Skip to content

Commit 714b178

Browse files
authored
ci: add workflow to create issues on CI failure (#1174)
* ci: add workflow to create issues on CI failure * style: fix prettier formatting
1 parent 2c34489 commit 714b178

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

Comments
 (0)