Retries an Action step on failure or timeout. This is currently intended to replace the run
step for moody commands.
NOTE: Ownership of this project was transferred to my personal account nick-fields
from my work account nick-invision
. Details here
Required Minutes to wait before attempt times out. Must only specify either minutes or seconds
Required Seconds to wait before attempt times out. Must only specify either minutes or seconds
Required Number of attempts to make before failing the step
Required The command to run
Optional Number of seconds to wait before attempting the next retry. Defaults to 10
Optional Shell to use to execute command
. Defaults to powershell
on Windows, bash
otherwise. Supports bash, python, pwsh, sh, cmd, and powershell per docs
Optional Number of seconds to wait while polling for command result. Defaults to 1
Optional Event to retry on. Currently supports [any (default), timeout, error].
Optional Whether to output a warning on retry, or just output to info. Defaults to true
.
Optional Command to run before a retry (such as a cleanup script). Any error thrown from retry command is caught and surfaced as a warning.
Optional Command to run if the first attempt fails. This command will be called on all subsequent attempts.
Optional Exit successfully even if an error occurs. Same as native continue-on-error behavior, but for use in composite actions. Defaults to false
Optional Specific exit code to retry on. This will only retry for the given error code and fail immediately other error codes.
The final number of attempts made
The final exit code returned by the command
The final error returned by the command
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
shell: pwsh
command: dir
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
command: npm run some-typically-slow-script
uses: nick-fields/retry@v3
with:
timeout_seconds: 15
max_attempts: 3
command: npm run some-typically-fast-script
uses: nick-fields/retry@v3
with:
timeout_seconds: 15
max_attempts: 3
retry_on: timeout
command: npm run some-typically-fast-script
uses: nick-fields/retry@v3
with:
timeout_seconds: 15
max_attempts: 3
retry_on: error
command: npm run some-typically-fast-script
Retry using continue_on_error input (in composite action) but allow failure and do something with output
- uses: nick-fields/retry@v3
id: retry
with:
timeout_seconds: 15
max_attempts: 3
continue_on_error: true
command: node -e 'process.exit(99);'
- name: Assert that step succeeded (despite failing command)
uses: nick-fields/assert-action@v1
with:
expected: success
actual: ${{ steps.retry.outcome }}
- name: Assert that action exited with expected exit code
uses: nick-fields/assert-action@v1
with:
expected: 99
actual: ${{ steps.retry.outputs.exit_code }}
Retry using continue-on-error built-in command (in workflow action) but allow failure and do something with output
- uses: nick-fields/retry@v3
id: retry
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idcontinue-on-error
continue-on-error: true
with:
timeout_seconds: 15
max_attempts: 3
retry_on: error
command: node -e 'process.exit(99);'
- name: Assert that action failed
uses: nick-fields/assert-action@v1
with:
expected: failure
actual: ${{ steps.retry.outcome }}
- name: Assert that action exited with expected exit code
uses: nick-fields/assert-action@v1
with:
expected: 99
actual: ${{ steps.retry.outputs.exit_code }}
- name: Assert that action made expected number of attempts
uses: nick-fields/assert-action@v1
with:
expected: 3
actual: ${{ steps.retry.outputs.total_attempts }}
uses: nick-fields/retry@v3
with:
timeout_seconds: 15
max_attempts: 3
command: npm run some-flaky-script-that-outputs-something
on_retry_command: npm run cleanup-flaky-script-output
uses: nick-fields/retry@v3
with:
timeout_seconds: 15
max_attempts: 3
command: npx jest
new_command_on_retry: npx jest --onlyFailures
name: Multi-line multi-command Test
uses: nick-fields/retry@v3
with:
timeout_minutes: 1
max_attempts: 2
command: |
Get-ComputerInfo
Get-Date
name: Multi-line single-command Test
uses: nick-fields/retry@v3
with:
timeout_minutes: 1
max_attempts: 2
shell: cmd
command: >-
echo "this is
a test"
NodeJS is required for this action to run. This runs without issue on all GitHub hosted runners but if you are running into issues with this on self hosted runners ensure NodeJS is installed.
As of 2022/02/15 ownership of this project has been transferred to my personal account nick-fields
from my work account nick-invision
due to me leaving InVision. I am the author and have been the primary maintainer since day one and will continue to maintain this as needed.
Existing workflow references to nick-invision/retry@<whatever>
no longer work and must be updated to nick-fields/retry@<whatever>
.