-
-
Notifications
You must be signed in to change notification settings - Fork 56
39 lines (36 loc) · 1.7 KB
/
pr-commands.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
name: PR commands
on:
issue_comment:
types: [created]
jobs:
rerun-workflows:
runs-on: ubuntu-latest
steps:
- name: Pull Request Comment Trigger
uses: shanegenschaw/[email protected]
id: check
with:
trigger: "/rerun"
reaction: rocket
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_WORKFLOW_RERUN }}
- name: Rerun workflows
if: steps.check.outputs.triggered == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_WORKFLOW_RERUN }}
run: |
# Note to self: it could be possible to use the `pull_requests` field on the runs API to filter the runs instead of doing it by branch
# get the branch name for the pull request
echo "Getting the branch name for ${{ github.repository }}#${{ github.event.issue.number }}"
branch=$(gh api "repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}" | jq -r '.head.ref')
echo "Branch name is $branch"
# Get the workflow runs
runs_failed=$(gh api --method GET "repos/${{ github.repository }}/actions/runs" -f per_page=100 | jq -r --arg branch "$branch" '.workflow_runs[] | select(.conclusion == "failure" and .head_branch == $branch) | .id')
# Convert the runs to an array
readarray -t workflow_runs_failed <<< "$runs_failed"
echo "Workflow runs failed: $workflow_runs_failed"
# Rerun the workflows
for workflow_run_id in $workflow_runs_failed; do
echo "Rerunning failed workflow runs $workflow_run_id"
gh api --method POST "repos/${{ github.repository }}/actions/runs/$workflow_run_id/rerun-failed-jobs"
done