Skip to content

Commit c8f5eff

Browse files
authored
ci: allow people to rerun failed jobs by commenting /rerun (#1486)
1 parent 50fe3a1 commit c8f5eff

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

.github/workflows/rerun-jobs.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: pull request comment
2+
on:
3+
issue_comment:
4+
types: [created]
5+
6+
jobs:
7+
rerun-workflows:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Pull Request Comment Trigger
11+
uses: Khan/[email protected]
12+
id: check
13+
with:
14+
trigger: "/rerun"
15+
reaction: rocket
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_WORKFLOW_RERUN }}
18+
- name: Rerun workflows
19+
if: steps.check.outputs.triggered == 'true'
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_WORKFLOW_RERUN }}
22+
run: |
23+
# get the branch name for the pull request
24+
branch=$(gh api "repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}" | jq -r '.head.ref')
25+
26+
# Get the workflow runs
27+
workflow_runs=$(gh api "repos/${{ github.repository }}/actions/runs")
28+
workflow_runs_failed=$(echo $workflow_runs | jq -r --arg branch "$branch" '.workflow_runs[] | select(.conclusion == "failure" and .head_branch == $branch) | .id')
29+
# Rerun the workflows
30+
for workflow_run_id in $workflow_runs_failed; do
31+
gh api "repos/${{ github.repository }}/actions/runs/${workflow_run_id}/rerun-failed-jobs"
32+
done

0 commit comments

Comments
 (0)