|
| 1 | +name: CI Failure Issue |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + # These names must match the `name:` field in each workflow file exactly |
| 6 | + workflows: |
| 7 | + - 'Build and Test' |
| 8 | + - 'Quality and Safety Checks' |
| 9 | + - 'E2E Tests (Full Suite)' |
| 10 | + - 'CodeQL' |
| 11 | + types: [completed] |
| 12 | + |
| 13 | +jobs: |
| 14 | + create-issue: |
| 15 | + concurrency: ci-failure-issue-${{ github.event.workflow_run.name }} |
| 16 | + runs-on: ubuntu-latest |
| 17 | + timeout-minutes: 5 |
| 18 | + if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.head_branch == 'main' }} |
| 19 | + permissions: |
| 20 | + issues: write |
| 21 | + steps: |
| 22 | + - uses: actions/github-script@v9 |
| 23 | + with: |
| 24 | + script: | |
| 25 | + try { |
| 26 | + const workflowName = context.payload.workflow_run.name; |
| 27 | +
|
| 28 | + if (!/^[A-Za-z0-9 _()\-]+$/.test(workflowName)) { |
| 29 | + core.setFailed(`Unexpected characters in workflow name: ${workflowName}`); |
| 30 | + return; |
| 31 | + } |
| 32 | +
|
| 33 | + const sha = context.payload.workflow_run.head_sha; |
| 34 | + const runUrl = context.payload.workflow_run.html_url; |
| 35 | + const branch = context.payload.workflow_run.head_branch; |
| 36 | + const title = `CI Failure: ${workflowName}`; |
| 37 | +
|
| 38 | + const { data: issues } = await github.rest.issues.listForRepo({ |
| 39 | + owner: context.repo.owner, |
| 40 | + repo: context.repo.repo, |
| 41 | + labels: 'high-severity,ci', |
| 42 | + state: 'open', |
| 43 | + per_page: 100 |
| 44 | + }); |
| 45 | +
|
| 46 | + if (issues.some(i => i.title === title)) { |
| 47 | + core.info(`Issue already exists for "${title}"`); |
| 48 | + return; |
| 49 | + } |
| 50 | +
|
| 51 | + await github.rest.issues.create({ |
| 52 | + owner: context.repo.owner, |
| 53 | + repo: context.repo.repo, |
| 54 | + title, |
| 55 | + labels: ['high-severity', 'ci'], |
| 56 | + body: `## CI Failure\n\n- **Workflow:** ${workflowName}\n- **Branch:** ${branch}\n- **Commit:** ${sha}\n- **Run:** ${runUrl}\n\nPlease investigate this failure.` |
| 57 | + }); |
| 58 | + } catch (error) { |
| 59 | + core.setFailed(`Failed to create CI failure issue: ${error.message || error}`); |
| 60 | + } |
0 commit comments