Merge Queue Failure Handler #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Merge Queue Failure Handler | |
| on: | |
| workflow_run: | |
| workflows: ["NVIDIA GPU"] | |
| types: [completed] | |
| branches: [main] | |
| permissions: | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| handle-failure: | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event.workflow_run.conclusion == 'failure' && | |
| github.event.workflow_run.event == 'merge_group' | |
| steps: | |
| - name: Extract PR number from merge group | |
| id: extract-pr | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const headRef = '${{ github.event.workflow_run.head_branch }}'; | |
| // Merge group branch format: gh-readonly-queue/main/pr-{number}-{sha} | |
| const match = headRef.match(/pr-(\d+)-/); | |
| if (match) { | |
| return match[1]; | |
| } | |
| return null; | |
| result-encoding: string | |
| - name: Comment on PR | |
| if: steps.extract-pr.outputs.result != 'null' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prNumber = parseInt('${{ steps.extract-pr.outputs.result }}'); | |
| const workflowName = '${{ github.event.workflow_run.name }}'; | |
| const runUrl = '${{ github.event.workflow_run.html_url }}'; | |
| // Check if PR exists and is open | |
| try { | |
| const { data: pr } = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber | |
| }); | |
| // Add comment about merge queue failure | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: `## ⚠️ Merge Queue Failed\n\nThe merge queue validation failed for this PR.\n\n**Failed Workflow:** ${workflowName}\n**Run Details:** ${runUrl}\n\nThe PR has been automatically removed from the merge queue. Please review the test failures and push fixes to re-attempt merging.` | |
| }); | |
| // If PR was somehow closed, reopen it | |
| if (pr.state === 'closed') { | |
| await github.rest.pulls.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber, | |
| state: 'open' | |
| }); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: '🔄 This PR has been automatically reopened after merge queue failure.' | |
| }); | |
| } | |
| } catch (error) { | |
| console.log(`Could not process PR #${prNumber}: ${error.message}`); | |
| } |