From 2b58840cc84dda5f76b4ad8ce5006cf59417f752 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Tue, 16 Dec 2025 12:02:02 +0100 Subject: [PATCH 1/7] Check if merge queue can be skipped if pull request is up-to-date --- .github/actions/check-merge-queue/action.yml | 92 ++++++++++++++++++++ .github/workflows/main.yml | 38 +++++++- 2 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 .github/actions/check-merge-queue/action.yml diff --git a/.github/actions/check-merge-queue/action.yml b/.github/actions/check-merge-queue/action.yml new file mode 100644 index 00000000000..3ecadb308dc --- /dev/null +++ b/.github/actions/check-merge-queue/action.yml @@ -0,0 +1,92 @@ +name: Check merge queue +description: Check whether a pull request can skip the merge queue when it's + up-to-date with the base branch. + +inputs: + head-ref: + description: The name of the head ref (the pull request branch). + required: true + default: ${{ github.event.merge_group.head_ref }} + + base-ref: + description: The name of the base ref (e.g., main, master). + required: true + default: main + + github-token: + description: The GitHub token to use for authentication. + required: true + default: ${{ github.token }} + +outputs: + up-to-date: + value: ${{ steps.up-to-date.outputs.up-to-date }} + description: Whether the pull request is up-to-date with the base branch + and is first in the merge queue, allowing it to skip the merge queue. + +runs: + using: composite + steps: + - name: Checkout repository + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Get pull request details + id: pr-details + uses: actions/github-script@v8 + env: + HEAD_REF: ${{ inputs.head-ref }} + with: + github-token: ${{ inputs.github-token }} + script: | + const { HEAD_REF } = process.env; + const match = HEAD_REF.match(/\/pr-([0-9]+)-/u); + if (!match) { + return core.setFailed(`Could not extract pull request number from head ref: "${HEAD_REF}".`); + } + + const number = parseInt(match[1], 10); + const result = await github.graphql(` + query($owner: String!, $name: String!, $number: Int!) { + repository(owner: $owner, name: $name) { + pullRequest(number: $number) { + headRefName + mergeQueueEntry { position } + } + } + } + `, { + owner: context.repo.owner, + name: context.repo.repo, + number, + }); + + if (!result.repository.pullRequest) { + return core.setFailed(`Pull request #${number} not found in repository "${context.repo.owner}/${context.repo.repo}".`); + } + + const position = result.repository.pullRequest.mergeQueueEntry?.position; + if (!position) { + return core.setFailed(`Pull request #${number} is not in the merge queue.`); + } + + core.setOutput('pr-number', number); + core.setOutput('pr-branch', result.repository.pullRequest.headRefName); + core.setOutput('merge-queue-position', position); + + - name: Check if pull request is up-to-date with base branch + id: up-to-date + shell: bash + env: + BASE_REF: ${{ inputs.base-ref }} + PR_BRANCH: ${{ steps.pr-details.outputs.pr-branch }} + MERGE_QUEUE_POSITION: ${{ steps.pr-details.outputs.merge-queue-position }} + run: | + set -euo pipefail + if git merge-base --is-ancestor "origin/${BASE_REF}" "origin/${PR_BRANCH}" && [ "${MERGE_QUEUE_POSITION}" -eq 1 ]; then + echo "up-to-date=true" >> "$GITHUB_OUTPUT" + else + echo "up-to-date=false" >> "$GITHUB_OUTPUT" + fi + diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ce44020ec80..01dc4c09b78 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,8 +11,25 @@ concurrency: cancel-in-progress: ${{ !contains(github.ref, 'refs/heads/main') }} jobs: + check-skip-merge-queue: + name: Check if pull request can skip merge queue + if: github.event_name == 'merge_group' + runs-on: ubuntu-latest + outputs: + skip-merge-queue: ${{ steps.check-skip-merge-queue.outputs.up-to-date }} + steps: + - id: check-skip-merge-queue + uses: ./.github/actions/check-merge-queue + with: + head-ref: ${{ github.event.merge_group.head_ref }} + base-ref: main + github-token: ${{ secrets.GITHUB_TOKEN }} + check-workflows: name: Check workflows + needs: + - check-skip-merge-queue + if: github.event_name != 'merge_group' || needs.check-skip-merge-queue.outputs.skip-merge-queue != 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 @@ -26,7 +43,10 @@ jobs: analyse-code: name: Analyse code - needs: check-workflows + needs: + - check-workflows + - check-skip-merge-queue + if: github.event_name != 'merge_group' || needs.check-skip-merge-queue.outputs.skip-merge-queue != 'true' uses: MetaMask/action-security-code-scanner/.github/workflows/security-scan.yml@v2 with: scanner-ref: v2 @@ -60,12 +80,18 @@ jobs: lint-build-test: name: Lint, build, and test - needs: check-workflows + needs: + - check-workflows + - check-skip-merge-queue + if: github.event_name != 'merge_group' || needs.check-skip-merge-queue.outputs.skip-merge-queue != 'true' uses: ./.github/workflows/lint-build-test.yml check-release: name: Check release - needs: check-workflows + needs: + - check-workflows + - check-skip-merge-queue + if: github.event_name != 'merge_group' || needs.check-skip-merge-queue.outputs.skip-merge-queue != 'true' runs-on: ubuntu-latest permissions: contents: read @@ -127,7 +153,11 @@ jobs: name: All jobs pass if: ${{ always() }} runs-on: ubuntu-latest - needs: all-jobs-complete + needs: + - all-jobs-complete + - check-skip-merge-queue + env: + PASSED: ${{ needs.all-jobs-complete.outputs.passed == 'true' || needs.check-skip-merge-queue.outputs.skip-merge-queue == 'true' }} steps: - name: Check that all jobs have passed run: | From d28fb1acfb84265180ca67632b6036f7c90b4952 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Tue, 16 Dec 2025 13:40:57 +0100 Subject: [PATCH 2/7] Add checkout, and fix `all-jobs-pass` check --- .github/actions/check-merge-queue/action.yml | 1 - .github/workflows/main.yml | 14 ++++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/actions/check-merge-queue/action.yml b/.github/actions/check-merge-queue/action.yml index 3ecadb308dc..a88578ca9c9 100644 --- a/.github/actions/check-merge-queue/action.yml +++ b/.github/actions/check-merge-queue/action.yml @@ -89,4 +89,3 @@ runs: else echo "up-to-date=false" >> "$GITHUB_OUTPUT" fi - diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01dc4c09b78..9bcea11630a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,17 +13,24 @@ concurrency: jobs: check-skip-merge-queue: name: Check if pull request can skip merge queue - if: github.event_name == 'merge_group' runs-on: ubuntu-latest outputs: skip-merge-queue: ${{ steps.check-skip-merge-queue.outputs.up-to-date }} steps: - - id: check-skip-merge-queue + - name: Checkout repository + uses: actions/checkout@v6 + if: github.event_name == 'merge_group' + - name: Check pull request merge queue status + id: check-skip-merge-queue + if: github.event_name == 'merge_group' uses: ./.github/actions/check-merge-queue with: head-ref: ${{ github.event.merge_group.head_ref }} base-ref: main github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Set skip-merge-queue output to false + if: github.event_name != 'merge_group' + run: echo "skip-merge-queue=false" >> "$GITHUB_OUTPUT" check-workflows: name: Check workflows @@ -161,7 +168,6 @@ jobs: steps: - name: Check that all jobs have passed run: | - passed="${{ needs.all-jobs-complete.outputs.passed }}" - if [[ $passed != "true" ]]; then + if [[ "$PASSED" != "true" ]]; then exit 1 fi From db0df85bd4cc523dd852afac4aee19ee747f54c9 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Tue, 16 Dec 2025 14:16:44 +0100 Subject: [PATCH 3/7] Remove unnecessary step --- .github/workflows/main.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9bcea11630a..5716d9b51bc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,9 +28,6 @@ jobs: head-ref: ${{ github.event.merge_group.head_ref }} base-ref: main github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Set skip-merge-queue output to false - if: github.event_name != 'merge_group' - run: echo "skip-merge-queue=false" >> "$GITHUB_OUTPUT" check-workflows: name: Check workflows From 3b2eb1daa66823d1ec2d2e9c39e02bd6c25e6f97 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Tue, 16 Dec 2025 20:55:20 +0100 Subject: [PATCH 4/7] Simplify logic for skipping workflows --- .github/workflows/main.yml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5716d9b51bc..98ee97a7bdb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,7 +33,7 @@ jobs: name: Check workflows needs: - check-skip-merge-queue - if: github.event_name != 'merge_group' || needs.check-skip-merge-queue.outputs.skip-merge-queue != 'true' + if: always() && github.event_name != 'merge_group' || needs.check-skip-merge-queue.outputs.skip-merge-queue != 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 @@ -47,10 +47,7 @@ jobs: analyse-code: name: Analyse code - needs: - - check-workflows - - check-skip-merge-queue - if: github.event_name != 'merge_group' || needs.check-skip-merge-queue.outputs.skip-merge-queue != 'true' + needs: check-workflows uses: MetaMask/action-security-code-scanner/.github/workflows/security-scan.yml@v2 with: scanner-ref: v2 @@ -84,18 +81,12 @@ jobs: lint-build-test: name: Lint, build, and test - needs: - - check-workflows - - check-skip-merge-queue - if: github.event_name != 'merge_group' || needs.check-skip-merge-queue.outputs.skip-merge-queue != 'true' + needs: check-workflows uses: ./.github/workflows/lint-build-test.yml check-release: name: Check release - needs: - - check-workflows - - check-skip-merge-queue - if: github.event_name != 'merge_group' || needs.check-skip-merge-queue.outputs.skip-merge-queue != 'true' + needs: check-workflows runs-on: ubuntu-latest permissions: contents: read From 285ce9bf9890119c162b9de0e4ff087907c40d94 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Tue, 16 Dec 2025 21:46:18 +0100 Subject: [PATCH 5/7] Simplify logic further --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 98ee97a7bdb..a8c9998bc37 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,16 +13,15 @@ concurrency: jobs: check-skip-merge-queue: name: Check if pull request can skip merge queue + if: github.event_name == 'merge_group runs-on: ubuntu-latest outputs: skip-merge-queue: ${{ steps.check-skip-merge-queue.outputs.up-to-date }} steps: - name: Checkout repository uses: actions/checkout@v6 - if: github.event_name == 'merge_group' - name: Check pull request merge queue status id: check-skip-merge-queue - if: github.event_name == 'merge_group' uses: ./.github/actions/check-merge-queue with: head-ref: ${{ github.event.merge_group.head_ref }} From 14951f5e9295b092e3559d026c1d5ce064e21c83 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Tue, 16 Dec 2025 21:51:38 +0100 Subject: [PATCH 6/7] Fix missing quote --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a8c9998bc37..6079f6d2437 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ concurrency: jobs: check-skip-merge-queue: name: Check if pull request can skip merge queue - if: github.event_name == 'merge_group + if: github.event_name == 'merge_group' runs-on: ubuntu-latest outputs: skip-merge-queue: ${{ steps.check-skip-merge-queue.outputs.up-to-date }} From c43686c2779255225e330167515dab82a5eade25 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Tue, 16 Dec 2025 18:05:30 -0330 Subject: [PATCH 7/7] WIP --- .github/workflows/main.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6079f6d2437..ecdc86954a0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,6 +44,14 @@ jobs: run: ${{ steps.download-actionlint.outputs.executable }} -color shell: bash + print-job-status: + needs: check-workflows + runs-on: ubuntu-latest + if: ${{ success() }} + steps: + - run: echo "${{ job.status }}" + shell: bash + analyse-code: name: Analyse code needs: check-workflows