major: bump to v2 and added lots of examples

This commit is contained in:
Nick Fields
2020-09-29 14:56:52 -04:00
parent 915303cda5
commit 3f5463b526
5 changed files with 105 additions and 24 deletions

View File

@@ -71,7 +71,7 @@ jobs:
expected: failure
actual: ${{ steps.sad_path_error.outcome }}
- name: retry_on (timeout) fails early if nonzero encountered
- name: retry_on (timeout) fails early if error encountered
id: retry_on_timeout_fail
uses: ./
continue-on-error: true
@@ -93,27 +93,27 @@ jobs:
expected: 2
actual: ${{ steps.retry_on_timeout_fail.outputs.exit_code }}
- name: retry_on (nonzero)
id: retry_on_nonzero
- name: retry_on (error)
id: retry_on_error
uses: ./
continue-on-error: true
with:
timeout_minutes: 1
max_attempts: 2
retry_on: nonzero
retry_on: error
command: node -e "process.exit(2)"
- uses: nick-invision/assert-action@v1
with:
expected: 2
actual: ${{ steps.retry_on_nonzero.outputs.total_attempts }}
actual: ${{ steps.retry_on_error.outputs.total_attempts }}
- uses: nick-invision/assert-action@v1
with:
expected: failure
actual: ${{ steps.retry_on_nonzero.outcome }}
actual: ${{ steps.retry_on_error.outcome }}
- uses: nick-invision/assert-action@v1
with:
expected: 2
actual: ${{ steps.retry_on_nonzero.outputs.exit_code }}
actual: ${{ steps.retry_on_error.outputs.exit_code }}
# timeout tests (takes longer to run so run last)
@@ -152,27 +152,27 @@ jobs:
expected: failure
actual: ${{ steps.retry_on_timeout.outcome }}
- name: retry_on (nonzero) fails early if timeout encountered
id: retry_on_nonzero_fail
- name: retry_on (error) fails early if timeout encountered
id: retry_on_error_fail
uses: ./
continue-on-error: true
with:
timeout_seconds: 15
max_attempts: 2
retry_on: nonzero
retry_on: error
command: node -e "(async()=>await new Promise(r => setTimeout(r, 120000)))()"
- uses: nick-invision/assert-action@v1
with:
expected: 1
actual: ${{ steps.retry_on_nonzero_fail.outputs.total_attempts }}
actual: ${{ steps.retry_on_error_fail.outputs.total_attempts }}
- uses: nick-invision/assert-action@v1
with:
expected: failure
actual: ${{ steps.retry_on_nonzero_fail.outcome }}
actual: ${{ steps.retry_on_error_fail.outcome }}
- uses: nick-invision/assert-action@v1
with:
expected: 1
actual: ${{ steps.retry_on_nonzero_fail.outputs.exit_code }}
actual: ${{ steps.retry_on_error_fail.outputs.exit_code }}
- name: sad-path (timeout minutes)
id: sad_path_timeout_minutes

View File

@@ -24,16 +24,97 @@ Retries an Action step on failure or timeout. This is currently intended to repl
**Optional** Number of seconds to wait while polling for command result. Defaults to `1`
## Example usage
### `retry_on`
**Optional** Event to retry on. Currently supports [any (default), timeout, error].
## Outputs
### `total_attempts`
The final number of attempts made
### `exit_code`
The final exit code returned by the command
### `exit_error`
The final error returned by the command
## Examples
### Timeout in minutes
```yaml
uses: nick-invision/retry@v1
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: npm install
command: npm run some-typically-slow-script
```
### Timeout in seconds
```yaml
uses: nick-invision/retry@v2
with:
timeout_seconds: 15
max_attempts: 3
command: npm run some-typically-fast-script
```
### Only retry after timeout
```yaml
uses: nick-invision/retry@v2
with:
timeout_seconds: 15
max_attempts: 3
retry_on: timeout
command: npm run some-typically-fast-script
```
### Only retry after error
```yaml
uses: nick-invision/retry@v2
with:
timeout_seconds: 15
max_attempts: 3
retry_on: error
command: npm run some-typically-fast-script
```
### Retry but allow failure and do something with output
```yaml
- uses: nick-invision/retry@v2
id: retry
# see https://docs.github.com/en/free-pro-team@latest/actions/reference/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-invision/assert-action@v1
with:
expected: failure
actual: ${{ steps.retry.outcome }}
- name: Assert that action exited with expected exit code
uses: nick-invision/assert-action@v1
with:
expected: 99
actual: ${{ steps.retry.outputs.exit_code }}
- name: Assert that action made expected number of attempts
uses: nick-invision/assert-action@v1
with:
expected: 3
actual: ${{ steps.retry.outputs.total_attempts }}
```
## Requirements
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.
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.

View File

@@ -23,7 +23,7 @@ inputs:
required: false
default: 1
retry_on:
description: Event to retry on. Currently supported [any, timeout, nonzero]
description: Event to retry on. Currently supported [any, timeout, error]
outputs:
total_attempts:
description: The final number of attempts made

6
dist/index.js vendored
View File

@@ -533,11 +533,11 @@ async function runAction() {
} catch (error) {
if (attempt === MAX_ATTEMPTS) {
throw new Error(`Final attempt failed. ${error.message}`);
} else if (!done && RETRY_ON == 'nonzero') {
} else if (!done && RETRY_ON === 'error') {
// error: timeout
throw error;
} else if (exit > 0 && RETRY_ON == 'timeout') {
// error: nonzero
} else if (exit > 0 && RETRY_ON === 'timeout') {
// error: error
throw error;
} else {
warning(`Attempt ${attempt} failed. Reason: ${error.message}`);

View File

@@ -117,11 +117,11 @@ async function runAction() {
} catch (error) {
if (attempt === MAX_ATTEMPTS) {
throw new Error(`Final attempt failed. ${error.message}`);
} else if (!done && RETRY_ON == 'nonzero') {
} else if (!done && RETRY_ON === 'error') {
// error: timeout
throw error;
} else if (exit > 0 && RETRY_ON == 'timeout') {
// error: nonzero
} else if (exit > 0 && RETRY_ON === 'timeout') {
// error: error
throw error;
} else {
warning(`Attempt ${attempt} failed. Reason: ${error.message}`);