Skip to content

test

test #6

---
name: Workflow Restarter
on:
workflow_call:
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:

Check failure on line 20 in .github/workflows/workflow-restarter.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/workflow-restarter.yml

Invalid workflow file

secret name `GITHUB_TOKEN` within `workflow_call` can not be used since it would collide with system reserved name
required: true
jobs:
rerun:
runs-on: ubuntu-latest
steps:
# ABORT if not SOURCE_GITHUB_TOKEN environment variable set
# - name: Check for presence of SOURCE_GITHUB_TOKEN environment variable
# shell: bash
# run: |
# if [[ -z ]]; then
# echo "ERROR: \$SOURCE_GITHUB_TOKEN must be set by the calling workflow" 1>&2 && exit 1
# fi
- 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 }}