|
| 1 | +# Copyright(C) 2025-2026 Advanced Micro Devices, Inc. All rights reserved. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +# Notifies PR authors when their PR fails in the merge queue |
| 5 | +# Watches for workflow completions triggered by merge_group events |
| 6 | + |
| 7 | +name: Merge Queue Failure Notification |
| 8 | + |
| 9 | +on: |
| 10 | + workflow_run: |
| 11 | + workflows: |
| 12 | + - "GAIA CLI Tests (All Platforms)" |
| 13 | + - "Code Quality (Lint)" |
| 14 | + - "Unit Tests" |
| 15 | + types: |
| 16 | + - completed |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + pull-requests: write |
| 21 | + actions: read |
| 22 | + |
| 23 | +jobs: |
| 24 | + notify-on-failure: |
| 25 | + name: Notify on Merge Queue Failure |
| 26 | + runs-on: ubuntu-latest |
| 27 | + # Only run if the triggering workflow was from a merge_group and failed |
| 28 | + if: > |
| 29 | + github.event.workflow_run.event == 'merge_group' && |
| 30 | + github.event.workflow_run.conclusion == 'failure' |
| 31 | + steps: |
| 32 | + - name: Post failure comment to PR |
| 33 | + uses: actions/github-script@v7 |
| 34 | + with: |
| 35 | + script: | |
| 36 | + // Extract PR number from merge queue branch name (e.g., gh-readonly-queue/main/pr-254-...) |
| 37 | + const headBranch = context.payload.workflow_run.head_branch || ''; |
| 38 | + const prMatch = headBranch.match(/pr-(\d+)/); |
| 39 | +
|
| 40 | + if (!prMatch) { |
| 41 | + console.log('Could not extract PR number from branch:', headBranch); |
| 42 | + console.log('This may not be a merge queue run'); |
| 43 | + return; |
| 44 | + } |
| 45 | +
|
| 46 | + const prNumber = parseInt(prMatch[1], 10); |
| 47 | + const workflowRun = context.payload.workflow_run; |
| 48 | + const runUrl = workflowRun.html_url; |
| 49 | + const workflowName = workflowRun.name; |
| 50 | +
|
| 51 | + // Get the failed jobs for more detail |
| 52 | + const { data: jobs } = await github.rest.actions.listJobsForWorkflowRun({ |
| 53 | + owner: context.repo.owner, |
| 54 | + repo: context.repo.repo, |
| 55 | + run_id: workflowRun.id, |
| 56 | + }); |
| 57 | +
|
| 58 | + const failedJobs = jobs.jobs.filter(job => job.conclusion === 'failure'); |
| 59 | + const failedJobsList = failedJobs.length > 0 |
| 60 | + ? failedJobs.map(job => ` - [${job.name}](${job.html_url})`).join('\n') |
| 61 | + : ' - Check workflow run for details'; |
| 62 | +
|
| 63 | + const body = `## Merge Queue Failure |
| 64 | +
|
| 65 | +Your PR was removed from the merge queue due to test failures in **${workflowName}**. |
| 66 | + |
| 67 | +**Failed jobs:** |
| 68 | +${failedJobsList} |
| 69 | + |
| 70 | +**Full workflow run:** [View logs](${runUrl}) |
| 71 | + |
| 72 | +<sub>This comment was automatically generated.</sub>`; |
| 73 | + |
| 74 | + // Check if we already posted a comment for this run to avoid duplicates |
| 75 | + const { data: comments } = await github.rest.issues.listComments({ |
| 76 | + owner: context.repo.owner, |
| 77 | + repo: context.repo.repo, |
| 78 | + issue_number: prNumber, |
| 79 | + }); |
| 80 | + |
| 81 | + const existingComment = comments.find(c => |
| 82 | + c.body.includes('Merge Queue Failure') && |
| 83 | + c.body.includes(runUrl) |
| 84 | + ); |
| 85 | + |
| 86 | + if (existingComment) { |
| 87 | + console.log('Comment already exists for this run, skipping'); |
| 88 | + return; |
| 89 | + } |
| 90 | + |
| 91 | + await github.rest.issues.createComment({ |
| 92 | + owner: context.repo.owner, |
| 93 | + repo: context.repo.repo, |
| 94 | + issue_number: prNumber, |
| 95 | + body: body, |
| 96 | + }); |
| 97 | + |
| 98 | + console.log(`Posted failure notification to PR #${prNumber}`); |
0 commit comments