From 776d779b62a945540453789161ca64dc887edec8 Mon Sep 17 00:00:00 2001 From: jpayne3506 Date: Fri, 22 Dec 2023 16:11:13 -0800 Subject: [PATCH 1/3] ci: Add check for merge queue ci --- .github/workflows/pipeline.yaml | 77 +++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 .github/workflows/pipeline.yaml diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml new file mode 100644 index 0000000000..6fdd4b3d5e --- /dev/null +++ b/.github/workflows/pipeline.yaml @@ -0,0 +1,77 @@ +name: Azure Pipeline Merge Queue Check +on: + workflow_dispatch: + pull_request: + branches: + - master + - release/* + merge_group: + types: + - checks_requested +jobs: + Azure-Merge-Queue-Check: + if: ${{ github.event_name == 'merge_group' }} + strategy: + matrix: + go-version: ['1.21'] + os: [ubuntu-latest] + name: Azure Pipeline Merge Queue Check + runs-on: ${{ matrix.os }} + permissions: + actions: read + contents: read + id-token: write + steps: + - name: Azure Login + uses: Azure/login@v1.5.1 + env: + AZURE_CORE_OUTPUT: none + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + - name: Check Azure Pipelines + uses: azure/CLI@v1 + env: + AZURE_CORE_OUTPUT: none + with: + azcliversion: latest + inlineScript: | + az account show + echo ${{ secrets.AZURE_DEVOPS_EXT_PAT }} | az devops login --org ${{ secrets.AZURE_PIPELINE_ORG }} + + echo "Sanity check recent Pipeline runs" + 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 + 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` + echo "Triggered CI Status - $status" + echo "Branch Ref - $GITHUB_REF" + + echo "Checking for AZP triggered CI for 60s" + end=$((SECONDS+60)) # Stop checking if not queued within a minute + while [ $SECONDS -lt $end ]; do + if [ $status = 'inProgress' ]; then + echo "AZP triggered pipeline successfully" + exit 0 + fi + echo "Waiting for 15 seconds for AZP to trigger run" + sleep 15s + 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` + echo "Current Status - $status" + done + echo "AZP did not trigger pipeline " + + az pipelines run --branch $GITHUB_REF --id ${{ secrets.AZURE_PIPELINE_ID }} --org ${{ secrets.AZURE_PIPELINE_ORG }} --project ${{ secrets.AZURE_PIPELINE_PROJECT }} + echo "Pipeline queued for $GITHUB_REF" + + echo "Checking for Workflow queued CI for 60s" + end=$((SECONDS+60)) # Stop checking if not queued within a minute + while [ $SECONDS -lt $end ]; do + echo "Waiting for 5 seconds for pipeline to show inProgress on AZP" + sleep 5s + 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` + echo "Current Status - $status" + if [ $status = 'inProgress' ]; then + exit 0 + fi + done + + echo "Pipeline not queued, break merge queue run" + exit 1 From f313fdb10ed9ba1f783d99dfacad48d1348ffb5f Mon Sep 17 00:00:00 2001 From: jpayne3506 Date: Fri, 22 Dec 2023 17:21:02 -0800 Subject: [PATCH 2/3] ci: restrict to master --- .github/workflows/pipeline.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index 6fdd4b3d5e..444994e8cf 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -4,7 +4,6 @@ on: pull_request: branches: - master - - release/* merge_group: types: - checks_requested From d60d6f58747d40fc208708a4ceca4f1d1aad82b0 Mon Sep 17 00:00:00 2001 From: jpayne3506 Date: Wed, 27 Dec 2023 23:16:41 -0800 Subject: [PATCH 3/3] chore: more verbose console messages --- .github/workflows/pipeline.yaml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index 444994e8cf..6561782739 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -37,7 +37,7 @@ jobs: az account show echo ${{ secrets.AZURE_DEVOPS_EXT_PAT }} | az devops login --org ${{ secrets.AZURE_PIPELINE_ORG }} - echo "Sanity check recent Pipeline runs" + echo "Sanity check recently triggered Merge Queue Pipeline runs" 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 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` echo "Triggered CI Status - $status" @@ -47,30 +47,33 @@ jobs: end=$((SECONDS+60)) # Stop checking if not queued within a minute while [ $SECONDS -lt $end ]; do if [ $status = 'inProgress' ]; then - echo "AZP triggered pipeline successfully" + echo "AZP triggered pipeline started successfully" exit 0 fi - echo "Waiting for 15 seconds for AZP to trigger run" + echo "Waiting for 15 seconds for AZP to trigger run and show inProgress" sleep 15s 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` - echo "Current Status - $status" + echo "Current CI Status - $status" done - echo "AZP did not trigger pipeline " + echo "AZP did not trigger CI" az pipelines run --branch $GITHUB_REF --id ${{ secrets.AZURE_PIPELINE_ID }} --org ${{ secrets.AZURE_PIPELINE_ORG }} --project ${{ secrets.AZURE_PIPELINE_PROJECT }} echo "Pipeline queued for $GITHUB_REF" + echo "Pipeline will be marked as Manually triggered for $GITHUB_REF" - echo "Checking for Workflow queued CI for 60s" + echo "Checking for Manually triggered CI for 60s" end=$((SECONDS+60)) # Stop checking if not queued within a minute while [ $SECONDS -lt $end ]; do echo "Waiting for 5 seconds for pipeline to show inProgress on AZP" sleep 5s 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` - echo "Current Status - $status" + echo "Current CI Status - $status" if [ $status = 'inProgress' ]; then + echo "Manually triggered pipeline started successfully" exit 0 fi done - echo "Pipeline not queued, break merge queue run" + echo "Pipeline not queued, break merge queue run. Please requeue the PR to the merge queue from the appropriate PR." + # NOTE: For this workflow to impact the Merge Queue and PR it must be made required in the appropriate branch protection rule exit 1