-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(CAT-1820) Move workflow-restarter to cat_github_actions
- Loading branch information
1 parent
b98f1f1
commit ff5450d
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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@v4 | ||
|
||
- 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 }} |