This GitHub Action retries a command with configurable timeout handling, retry logic, and optional exponential backoff. It's designed to be lightweight, fast, and compatible across different environments! π
- β±οΈ Configurable timeout in minutes or seconds.
- π Exponential backoff support to gracefully handle rate limits or network issues.
- π Adjustable number of retry attempts.
- π Support for various shells (bash, sh, cmd, powershell).
- π§Ή Option to run cleanup commands between retries.
- β¨ Ability to swap the execution command on subsequent attempts.
- πͺΆ Lightweight implementation using Bash in a minimal Alpine Docker container.
| Input | Description | Required | Default |
|---|---|---|---|
timeout_minutes |
β±οΈ Minutes to wait before attempt times out | No | N/A |
timeout_seconds |
β±οΈ Seconds to wait before attempt times out | No | N/A |
max_attempts |
π’ Number of attempts to make | Yes | N/A |
command |
π» Command to execute | Yes | N/A |
retry_wait_seconds |
β³ Seconds between retries (Base wait if using backoff) | No | 10 |
exponential_backoff |
π Wait time doubles after each failed attempt (true/false) |
No | false |
shell |
π Shell to use | No | bash |
retry_on |
π― Retry on error / timeout / any |
No | any |
on_retry_command |
π§Ή Command to run before retry (e.g., reset state) | No | N/A |
new_command_on_retry |
β¨ Alternative command for subsequent attempts | No | N/A |
continue_on_error |
βοΈ Continue workflow on error (true/false) |
No | false |
| Output | Description |
|---|---|
total_attempts |
π’ Total attempts made |
exit_code |
πͺ Final exit code |
exit_error |
β Final error message |
- uses: harryvasanth/rerun@v1
with:
timeout_seconds: 30
max_attempts: 3
command: "apt-get update"- uses: harryvasanth/rerun@v1
with:
max_attempts: 4
command: "curl -f [https://api.flaky-service.com/data](https://api.flaky-service.com/data)"
retry_wait_seconds: 5
exponential_backoff: "true" # Waits 5s, then 10s, then 20s- uses: harryvasanth/rerun@v1
with:
max_attempts: 5
command: "dpkg -i package.deb"
on_retry_command: "dpkg --remove package"- uses: harryvasanth/rerun@v1
with:
max_attempts: 3
command: "apt-get install -y some-package"
new_command_on_retry: "apt-get install -y some-package --no-install-recommends"Retry a potentially flaky Debian package installation with a longer timeout and exponential backoff:
jobs:
install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: π¦ Update package lists
run: sudo apt-get update
- name: π Install package with smart retry
uses: harryvasanth/rerun@v1
with:
timeout_minutes: 5
max_attempts: 3
command: sudo apt-get install -y potentially-flaky-package
retry_wait_seconds: 15
exponential_backoff: "true"You don't have to be in GitHub Actions to use rerun.sh! You can download and run it directly in any terminal, script, or alternative CI/CD system.
Since the script relies on environment variables (prefixed with INPUT_), you can execute it like this:
# 1. Download the script and make it executable
curl -sO https://raw.githubusercontent.com/harryvasanth/rerun/main/rerun.sh
chmod +x rerun.sh
# 2. Run your flaky command with environment variables
INPUT_MAX_ATTEMPTS=3 \
INPUT_RETRY_WAIT_SECONDS=5 \
INPUT_EXPONENTIAL_BACKOFF=true \
INPUT_COMMAND="npm test" \
./rerun.sh
Alternatively, you can run it entirely in one line without saving the file:
export INPUT_MAX_ATTEMPTS=3
export INPUT_COMMAND="curl -sS https://httpbin.org/delay/1"
curl -s https://raw.githubusercontent.com/harryvasanth/rerun/main/rerun.sh | bash