From 10c3a4491a03997b8b12d8430916063b0d218a54 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Mon, 11 Aug 2025 13:28:56 +0100 Subject: [PATCH] Create/update issue when scheduled CI job fails Signed-off-by: Christopher Obbard --- .github/workflows/ci.yml | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9e8eba..2dc7db2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -107,3 +107,44 @@ jobs: uses: re-actors/alls-green@release/v1 with: jobs: ${{ toJSON(needs) }} + + # Notify on job failure + notify-on-failure: + runs-on: ubuntu-latest + needs: + - allgreen + if: ${{ needs.allgreen.result == 'failure' }} + steps: + - name: Create or update failure issue + uses: actions/github-script@v7 + with: + script: | + const { owner, repo } = context.repo; + + // Reuse a single issue to avoid spam + const search = await github.rest.search.issuesAndPullRequests({ + q: `repo:${owner}/${repo} is:issue is:open "Scheduled CI job failed"` + }); + const body = [ + `### Nightly CI job failed`, + `- Workflow: **${process.env.GITHUB_WORKFLOW}**`, + `- Run: ${context.runId}`, + `- Commit: ${process.env.GITHUB_SHA}`, + `- Branch/Ref: ${process.env.GITHUB_REF}`, + `- URL: https://github.com/${owner}/${repo}/actions/runs/${context.runId}`, + ``, + `Please investigate and close this issue once fixed.` + ].join("\n"); + + if (search.data.items.length > 0) { + const issue = search.data.items[0]; + await github.rest.issues.createComment({ + owner, repo, issue_number: issue.number, body + }); + } else { + await github.rest.issues.create({ + owner, repo, + title: "Scheduled CI job failed", + body, + }); + }