|
| 1 | +name: CI Failure Issues |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: # zizmor: ignore[dangerous-triggers] |
| 5 | + workflows: |
| 6 | + - Fuzz |
| 7 | + types: |
| 8 | + - completed |
| 9 | + branches: |
| 10 | + - master |
| 11 | + |
| 12 | +permissions: |
| 13 | + issues: write |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: ci-failure-issues-${{ github.event.workflow_run.name }} |
| 17 | + cancel-in-progress: false |
| 18 | + |
| 19 | +jobs: |
| 20 | + sync-issue: |
| 21 | + if: ${{ contains(fromJson('["failure","success"]'), github.event.workflow_run.conclusion) }} |
| 22 | + runs-on: ubuntu-24.04 |
| 23 | + |
| 24 | + steps: |
| 25 | + - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 |
| 26 | + with: |
| 27 | + script: | |
| 28 | + const run = context.payload.workflow_run; |
| 29 | + const workflow = run.name; |
| 30 | + const marker = `<!-- ci-failure-key:${workflow} -->`; |
| 31 | + const workflowFiles = { |
| 32 | + "Fuzz": "cron-daily-fuzz.yml", |
| 33 | + }; |
| 34 | +
|
| 35 | + const formatTs = iso => { |
| 36 | + const d = new Date(iso); |
| 37 | + const pad = n => String(n).padStart(2, "0"); |
| 38 | + return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())} at ${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}:${pad(d.getUTCSeconds())} UTC`; |
| 39 | + }; |
| 40 | + const shortSha = sha => (sha || "unknown").slice(0, 7); |
| 41 | + const commitUrl = sha => `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/commit/${sha}`; |
| 42 | + const workflowUrl = workflowFiles[workflow] |
| 43 | + ? `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/workflows/${workflowFiles[workflow]}` |
| 44 | + : `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions?query=${encodeURIComponent(`workflow:"${workflow}"`)}`; |
| 45 | +
|
| 46 | + function titleFor() { |
| 47 | + return `The ${workflow} workflow is failing`; |
| 48 | + } |
| 49 | +
|
| 50 | + function bodyForFailure() { |
| 51 | + return [ |
| 52 | + marker, |
| 53 | + "", |
| 54 | + `The [${workflow} workflow](${workflowUrl}) started failing on ${formatTs(run.created_at)}: [${workflow} #${run.run_number}](${run.html_url}) - [\`${shortSha(run.head_sha)}\`](${commitUrl(run.head_sha)})`, |
| 55 | + ].join("\n"); |
| 56 | + } |
| 57 | +
|
| 58 | + const issues = await github.paginate(github.rest.issues.listForRepo, { |
| 59 | + owner: context.repo.owner, |
| 60 | + repo: context.repo.repo, |
| 61 | + state: "open", |
| 62 | + per_page: 100, |
| 63 | + }); |
| 64 | +
|
| 65 | + const existing = issues.find(issue => |
| 66 | + !issue.pull_request && issue.body && issue.body.includes(marker) |
| 67 | + ); |
| 68 | +
|
| 69 | + if (run.conclusion === "failure" && !existing) { |
| 70 | + await github.rest.issues.create({ |
| 71 | + owner: context.repo.owner, |
| 72 | + repo: context.repo.repo, |
| 73 | + title: titleFor(), |
| 74 | + body: bodyForFailure(), |
| 75 | + }); |
| 76 | + } |
| 77 | +
|
| 78 | + if (run.conclusion === "success" && existing) { |
| 79 | + await github.rest.issues.createComment({ |
| 80 | + owner: context.repo.owner, |
| 81 | + repo: context.repo.repo, |
| 82 | + issue_number: existing.number, |
| 83 | + body: `The [${workflow} workflow](${workflowUrl}) successfully ran again on ${formatTs(run.created_at)}: [${workflow} #${run.run_number}](${run.html_url}).`, |
| 84 | + }); |
| 85 | +
|
| 86 | + await github.rest.issues.update({ |
| 87 | + owner: context.repo.owner, |
| 88 | + repo: context.repo.repo, |
| 89 | + issue_number: existing.number, |
| 90 | + state: "closed", |
| 91 | + }); |
| 92 | + } |
0 commit comments