Skip to content

Commit fba02b4

Browse files
jpayne3506matmerr
authored andcommitted
ci: Add workflow check for Merge Queue pipeline start on Azure Pipeline (#2460)
* ci: Add check for merge queue ci * ci: restrict to master * chore: more verbose console messages
1 parent 7374f21 commit fba02b4

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

.github/workflows/pipeline.yaml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Azure Pipeline Merge Queue Check
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
branches:
6+
- master
7+
merge_group:
8+
types:
9+
- checks_requested
10+
jobs:
11+
Azure-Merge-Queue-Check:
12+
if: ${{ github.event_name == 'merge_group' }}
13+
strategy:
14+
matrix:
15+
go-version: ['1.21']
16+
os: [ubuntu-latest]
17+
name: Azure Pipeline Merge Queue Check
18+
runs-on: ${{ matrix.os }}
19+
permissions:
20+
actions: read
21+
contents: read
22+
id-token: write
23+
steps:
24+
- name: Azure Login
25+
uses: Azure/[email protected]
26+
env:
27+
AZURE_CORE_OUTPUT: none
28+
with:
29+
creds: ${{ secrets.AZURE_CREDENTIALS }}
30+
- name: Check Azure Pipelines
31+
uses: azure/CLI@v1
32+
env:
33+
AZURE_CORE_OUTPUT: none
34+
with:
35+
azcliversion: latest
36+
inlineScript: |
37+
az account show
38+
echo ${{ secrets.AZURE_DEVOPS_EXT_PAT }} | az devops login --org ${{ secrets.AZURE_PIPELINE_ORG }}
39+
40+
echo "Sanity check recently triggered Merge Queue Pipeline runs"
41+
az pipelines runs list --pipeline-ids ${{ secrets.AZURE_PIPELINE_ID }} --org ${{ secrets.AZURE_PIPELINE_ORG }} --project ${{ secrets.AZURE_PIPELINE_PROJECT }} --reason individualCI --top 10 --output json | jq -r .[].sourceBranch
42+
status=`az pipelines runs list --pipeline-ids ${{ secrets.AZURE_PIPELINE_ID }} --org ${{ secrets.AZURE_PIPELINE_ORG }} --project ${{ secrets.AZURE_PIPELINE_PROJECT }} --top 1 --branch $GITHUB_REF --output json | jq -r .[].status`
43+
echo "Triggered CI Status - $status"
44+
echo "Branch Ref - $GITHUB_REF"
45+
46+
echo "Checking for AZP triggered CI for 60s"
47+
end=$((SECONDS+60)) # Stop checking if not queued within a minute
48+
while [ $SECONDS -lt $end ]; do
49+
if [ $status = 'inProgress' ]; then
50+
echo "AZP triggered pipeline started successfully"
51+
exit 0
52+
fi
53+
echo "Waiting for 15 seconds for AZP to trigger run and show inProgress"
54+
sleep 15s
55+
status=`az pipelines runs list --pipeline-ids ${{ secrets.AZURE_PIPELINE_ID }} --org ${{ secrets.AZURE_PIPELINE_ORG }} --project ${{ secrets.AZURE_PIPELINE_PROJECT }} --top 1 --branch $GITHUB_REF --output json | jq -r .[].status`
56+
echo "Current CI Status - $status"
57+
done
58+
echo "AZP did not trigger CI"
59+
60+
az pipelines run --branch $GITHUB_REF --id ${{ secrets.AZURE_PIPELINE_ID }} --org ${{ secrets.AZURE_PIPELINE_ORG }} --project ${{ secrets.AZURE_PIPELINE_PROJECT }}
61+
echo "Pipeline queued for $GITHUB_REF"
62+
echo "Pipeline will be marked as Manually triggered for $GITHUB_REF"
63+
64+
echo "Checking for Manually triggered CI for 60s"
65+
end=$((SECONDS+60)) # Stop checking if not queued within a minute
66+
while [ $SECONDS -lt $end ]; do
67+
echo "Waiting for 5 seconds for pipeline to show inProgress on AZP"
68+
sleep 5s
69+
status=`az pipelines runs list --pipeline-ids ${{ secrets.AZURE_PIPELINE_ID }} --org ${{ secrets.AZURE_PIPELINE_ORG }} --project ${{ secrets.AZURE_PIPELINE_PROJECT }} --top 1 --branch $GITHUB_REF --output json | jq -r .[].status`
70+
echo "Current CI Status - $status"
71+
if [ $status = 'inProgress' ]; then
72+
echo "Manually triggered pipeline started successfully"
73+
exit 0
74+
fi
75+
done
76+
77+
echo "Pipeline not queued, break merge queue run. Please requeue the PR to the merge queue from the appropriate PR."
78+
# NOTE: For this workflow to impact the Merge Queue and PR it must be made required in the appropriate branch protection rule
79+
exit 1

0 commit comments

Comments
 (0)