Skip to content

Commit b2c1c1c

Browse files
committed
[CI] Add help command to rerun workflow bot
- Enhance rerun workflow bot to support `/rerun help` command. - Provide detailed documentation for rerun commands in response to `/rerun help`. - Ensure all rerun workflow steps are skipped when the help command is invoked.
1 parent 9b61155 commit b2c1c1c

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

.github/workflows/rerun-workflow.yml

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,36 @@ jobs:
1818
contents: read
1919

2020
steps:
21+
- name: Check for help command
22+
id: help
23+
uses: actions/github-script@v7
24+
with:
25+
script: |
26+
const comment = context.payload.comment.body;
27+
if (comment.match(/\/rerun\s+help/i)) {
28+
await github.rest.issues.createComment({
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
issue_number: context.issue.number,
32+
body: `## 🔄 Rerun Workflow Commands
33+
34+
| Command | Description |
35+
|---------|-------------|
36+
| \`/rerun\` | Rerun only **failed/cancelled/timed-out** workflows |
37+
| \`/rerun all\` | Rerun **all** workflows for this PR |
38+
| \`/rerun failed\` | Same as \`/rerun\` |
39+
| \`/rerun <name>\` | Rerun workflows matching \`<name>\` (e.g. \`/rerun ci\`, \`/rerun build\`) |
40+
| \`/rerun help\` | Show this help message |
41+
42+
**Note:** Only completed workflows can be rerun. In-progress workflows are skipped.`
43+
});
44+
core.setOutput('is_help', 'true');
45+
} else {
46+
core.setOutput('is_help', 'false');
47+
}
48+
2149
- name: Get PR SHA
50+
if: steps.help.outputs.is_help != 'true'
2251
id: pr
2352
uses: actions/github-script@v7
2453
with:
@@ -34,6 +63,7 @@ jobs:
3463
console.log(`PR head ref: ${pr.head.ref}`);
3564
3665
- name: Add reaction to comment
66+
if: steps.help.outputs.is_help != 'true'
3767
uses: actions/github-script@v7
3868
with:
3969
script: |
@@ -45,6 +75,7 @@ jobs:
4575
});
4676
4777
- name: Post start comment
78+
if: steps.help.outputs.is_help != 'true'
4879
uses: actions/github-script@v7
4980
with:
5081
script: |
@@ -60,6 +91,7 @@ jobs:
6091
});
6192
6293
- name: Rerun failed workflows
94+
if: steps.help.outputs.is_help != 'true'
6395
uses: actions/github-script@v7
6496
with:
6597
script: |
@@ -96,21 +128,21 @@ jobs:
96128
rerunArg === 'all' ||
97129
(rerunArg === 'failed' && ['failure', 'cancelled', 'timed_out'].includes(run.conclusion)) ||
98130
run.name.toLowerCase().includes(rerunArg);
99-
131+
100132
if (!shouldRerun) {
101133
console.log(`Skipping ${run.name} (status: ${run.status}, conclusion: ${run.conclusion})`);
102134
continue;
103135
}
104-
136+
105137
// Only rerun completed workflows
106138
if (run.status !== 'completed') {
107139
console.log(`Skipping ${run.name} - still ${run.status}`);
108140
continue;
109141
}
110-
142+
111143
try {
112144
console.log(`Rerunning workflow: ${run.name} (ID: ${run.id})`);
113-
145+
114146
// Use rerun-failed-jobs if available and workflow failed, otherwise full rerun
115147
if (['failure', 'cancelled', 'timed_out'].includes(run.conclusion)) {
116148
await github.rest.actions.reRunWorkflowFailedJobs({
@@ -134,7 +166,7 @@ jobs:
134166
console.log(`Reran ${rerunCount} workflow(s)`);
135167
136168
- name: Post completion comment
137-
if: always()
169+
if: always() && steps.help.outputs.is_help != 'true'
138170
uses: actions/github-script@v7
139171
with:
140172
script: |
@@ -146,4 +178,4 @@ jobs:
146178
repo: context.repo.repo,
147179
issue_number: context.issue.number,
148180
body: `${emoji} **Workflow rerun ${status}**\n\n[View Actions](https://github.com/${context.repo.owner}/${context.repo.repo}/actions)`
149-
});
181+
});

0 commit comments

Comments
 (0)