Skip to content

Commit b89433d

Browse files
(CAT-1820) Move workflow-restarter to cat_github_actions
1 parent b98f1f1 commit b89433d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
name: Workflow Restarter
3+
on:
4+
workflow_call:
5+
inputs:
6+
repo:
7+
description: "GitHub repository name."
8+
required: true
9+
type: string
10+
run_id:
11+
description: "The ID of the workflow run to rerun."
12+
required: true
13+
type: string
14+
retries:
15+
description: "The number of times to retry the workflow run."
16+
required: false
17+
type: number
18+
default: 3
19+
secrets:
20+
SOURCE_GITHUB_TOKEN:
21+
required: true
22+
23+
jobs:
24+
rerun:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
30+
- name: Check retry count
31+
id: check-retry
32+
run: |
33+
# IF `--attempts` returns a non-zero exit code, then keep retrying
34+
status_code=$(gh run view ${{ inputs.run_id }} --repo ${{ inputs.repo }} --attempt ${{ inputs.retries }} --json status) || {
35+
echo "Retry count is within limit"
36+
echo "::set-output name=should_retry::true"
37+
exit 0
38+
}
39+
40+
# ELSE `--attempts` returns a zero exit code, so stop retrying
41+
echo "Retry count has reached the limit"
42+
echo "::set-output name=should_retry::false"
43+
env:
44+
SOURCE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Re-run failed jobs
47+
if: ${{ steps.check-retry.outputs.should_retry == 'true' }}
48+
run: gh run rerun --failed ${{ inputs.run_id }} --repo ${{ inputs.repo }}
49+
continue-on-error: true
50+
env:
51+
SOURCE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)