-
Notifications
You must be signed in to change notification settings - Fork 105
51 lines (47 loc) · 1.52 KB
/
workflow-restarter.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
40
41
42
43
44
45
46
47
48
49
50
51
---
name: Workflow Restarter
on:
workflow_dispatch:
inputs:
repo:
description: "GitHub repository name."
required: true
type: string
run_id:
description: "The ID of the workflow run to rerun."
required: true
type: string
retries:
description: "The number of times to retry the workflow run."
required: false
type: number
default: 3
secrets:
GITHUB_TOKEN:
required: true
jobs:
rerun:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check retry count
id: check-retry
run: |
# IF `--attempts` returns a non-zero exit code, then keep retrying
status_code=$(gh run view ${{ inputs.run_id }} --repo ${{ inputs.repo }} --attempt ${{ inputs.retries }} --json status) || {
echo "Retry count is within limit"
echo "::set-output name=should_retry::true"
exit 0
}
# ELSE `--attempts` returns a zero exit code, so stop retrying
echo "Retry count has reached the limit"
echo "::set-output name=should_retry::false"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Re-run failed jobs
if: ${{ steps.check-retry.outputs.should_retry == 'true' }}
run: gh run rerun --failed ${{ inputs.run_id }} --repo ${{ inputs.repo }}
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}