A GitHub Action that reruns failed jobs, optionally only when specific patterns are found in logs.
This action uses gh run rerun <run_id> --failed to rerun all failed jobs in a workflow run. The job and pattern inputs control whether to trigger a rerun, not which jobs get rerun.
jobandpatternare conditions for deciding whether to rerun- When a rerun is triggered, all failed jobs in the run (and their dependents) are rerun
- The rerun creates a new attempt of the same workflow run
This action must be used with the workflow_run event. Since gh run rerun requires the target run to be completed, you cannot rerun a run from within itself. The workflow_run event fires after the target workflow finishes, making it the right trigger for this action.
name: Retry on transient failure
on:
workflow_run:
workflows: ["CI"]
types:
- completed
jobs:
retry:
runs-on: ubuntu-slim
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
permissions:
contents: read
actions: write
steps:
- uses: k1LoW/rerun-action@80c58dc1309b82e2746743ea0dc3f726313412a1 # v1.2.0
with:
run_id: ${{ github.event.workflow_run.id }}
pattern: 'Network partition'
job: 'build-and-test'
max_attempts: 2 - uses: k1LoW/rerun-action@80c58dc1309b82e2746743ea0dc3f726313412a1 # v1.2.0
with:
run_id: ${{ github.event.workflow_run.id }}
pattern: |
Network partition
Connection reset
Timeout exceeded
job: 'build-and-test'
max_attempts: 3When multiple jobs are specified, a rerun is triggered if any of them failed. Logs from all failed jobs are searched when pattern is also specified.
- uses: k1LoW/rerun-action@80c58dc1309b82e2746743ea0dc3f726313412a1 # v1.2.0
with:
run_id: ${{ github.event.workflow_run.id }}
pattern: 'Network partition'
job: |
build-and-test
integration-test - uses: k1LoW/rerun-action@80c58dc1309b82e2746743ea0dc3f726313412a1 # v1.2.0
with:
run_id: ${{ github.event.workflow_run.id }}
pattern: 'Network partition' - uses: k1LoW/rerun-action@80c58dc1309b82e2746743ea0dc3f726313412a1 # v1.2.0
with:
run_id: ${{ github.event.workflow_run.id }}
job: 'build-and-test' - uses: k1LoW/rerun-action@80c58dc1309b82e2746743ea0dc3f726313412a1 # v1.2.0
with:
run_id: ${{ github.event.workflow_run.id }}
max_attempts: 3 - id: rerun
uses: k1LoW/rerun-action@80c58dc1309b82e2746743ea0dc3f726313412a1 # v1.2.0
with:
run_id: ${{ github.event.workflow_run.id }}
- run: echo "reran=${{ steps.rerun.outputs.reran }}"This example uses a pseudo notification action to show how to branch on steps.rerun.outputs.reran.
- id: rerun
uses: k1LoW/rerun-action@80c58dc1309b82e2746743ea0dc3f726313412a1 # v1.2.0
with:
run_id: ${{ github.event.workflow_run.id }}
pattern: 'Network partition'
job: 'build-and-test'
- uses: example/notify-action@v1
if: ${{ steps.rerun.outputs.reran == 'true' }}
with:
message: "Rerun triggered for workflow run ${{ github.event.workflow_run.id }}"| Name | Required | Default | Description |
|---|---|---|---|
run_id |
Yes | The workflow run ID to rerun | |
pattern |
No | Pattern to search for in logs (newline-separated for multiple). If omitted, rerun unconditionally | |
job |
No | Job name(s) to check (newline-separated for multiple). Narrows log search scope when used with pattern. When used alone, reruns only if any specified job failed |
|
github_token |
No | ${{ github.token }} |
GitHub Token with actions:write permission |
max_attempts |
No | 3 |
Maximum run attempts to allow retry |
| Name | Description |
|---|---|
reran |
true if this action triggered gh run rerun, otherwise false |