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 :
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 : |
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 : |
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