Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .pipelines/.templates/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ variables:
# Files listed in the .order file will be deployed before other files and in the
# order they are listed.
#
# Set AZOPS_SKIP_PR_COMPLETION to true to opt-out from pull request completion.
#
# - ARM_TENANT_ID
# - ARM_SUBSCRIPTION_ID
# - ARM_CLIENT_ID
# - ARM_CLIENT_SECRET
# - ARM_ENVIRONMENT
# - AZOPS_MODULE_VERSION
# - AZOPS_CUSTOM_SORT_ORDER
# - AZOPS_MODULE_VERSION
# - AZOPS_CUSTOM_SORT_ORDER
# - AZOPS_SKIP_PR_COMPLETION
#

- group: credentials
Expand All @@ -36,4 +39,4 @@ variables:
#

- name: modulesFolder
value: '$(System.DefaultWorkingDirectory)/Modules'
value: '$(System.DefaultWorkingDirectory)/Modules'
84 changes: 48 additions & 36 deletions .pipelines/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ variables:
#
# Folder Name
# By default we generate the hierachy within the
# 'azops' folder within the root of the repository.
# 'root' folder within the root of the repository.
# If this property is modified, the config value within
# the settings.json file - Core.State will also need
# to be changed.
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
# Set global options
#

- task: Bash@3
- task: PowerShell@2
displayName: "Configure"
inputs:
targetType: "inline"
Expand All @@ -142,7 +142,7 @@ jobs:
# Switch branches
#

- task: Bash@3
- task: PowerShell@2
displayName: "Checkout"
inputs:
targetType: "inline"
Expand All @@ -169,26 +169,26 @@ jobs:
# Check for data changes
#

- task: Bash@3
- task: PowerShell@2
displayName: "Status"
inputs:
targetType: "inline"
script: |
STATUS=$(git status --short $(folder))
echo $STATUS
if [ -z "$STATUS" ]
then
echo "##vso[task.setvariable variable=state]stop"
else
echo "##vso[task.setvariable variable=state]continue"
fi
$gitStatus = git status --short $(folder)
if ($null -ne $gitStatus) {
$gitStatus | Write-Host
Write-Host '##vso[task.setvariable variable=state]continue'
}
else {
Write-Host '##vso[task.setvariable variable=state]stop'
}

#
# Add
# Add file content to index
#

- task: Bash@3
- task: PowerShell@2
displayName: "Add"
condition: contains(variables['state'], 'continue')
inputs:
Expand All @@ -202,7 +202,7 @@ jobs:
# Record changes to the repository
#

- task: Bash@3
- task: PowerShell@2
displayName: "Commit"
condition: contains(variables['state'], 'continue')
inputs:
Expand All @@ -216,7 +216,7 @@ jobs:
# Update remote refs along with associated objects
#

- task: Bash@3
- task: PowerShell@2
displayName: "Push"
condition: contains(variables['state'], 'continue')
inputs:
Expand All @@ -230,31 +230,43 @@ jobs:
# Update remote refs along with associated objects
#

- task: Bash@3
- task: PowerShell@2
displayName: "Merge"
condition: contains(variables['state'], 'continue')
inputs:
targetType: "inline"
script: |
# Open new PR
PROut=$(
az repos pr create \
--title "$(pull_request)" \
--source-branch "$(branch)" \
--target-branch "main" \
--squash true \
--delete-source-branch true \
--auto-complete true \
);

# Get PR ID and check status
PRid=$(echo $PROut | jq -r '.pullRequestId');
PRStatus=$(az repos pr show --id $PRid | jq .status);

# If PR is not completed, then complete it bypassing policy
if [ $PRStatus == "\"active\"" ]; then
echo "Completing PR bypassing branch policy"
az repos pr update --status completed --id $PRid --bypass-policy true --bypass-policy-reason "Automated pull request" > /dev/null 2>&1
fi;
# Check if active PR already exists
$pr = az repos pr list `
--source-branch "$(branch)" `
--target-branch "main" `
--status "active" | ConvertFrom-Json -NoEnumerate

if ($pr) {
Write-Host 'Active PR found with Id:' $pr.pullRequestId
} else {
# Open new PR
$pr = az repos pr create `
--title "$(pull_request)" `
--source-branch "$(branch)" `
--target-branch "main" `
--squash true `
--delete-source-branch true `
--auto-complete true | ConvertFrom-Json -NoEnumerate

Write-Host 'PR created with Id:' $pr.pullRequestId
}

# Complete any active PR, new or existing
$completePullRequest = $env:AZOPS_SKIP_PR_COMPLETION -ne 'true'
if ($completePullRequest) {
$prId = $pr.pullRequestId
$pr = az repos pr show --id $prId | ConvertFrom-Json -NoEnumerate
# If PR is not completed, then complete it bypassing policy
if ($pr.status -eq 'active') {
Write-Host 'Completing PR bypassing branch policy'
az repos pr update --status completed --id $prId --bypass-policy true --bypass-policy-reason 'Automated pull request'
}
}
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)