Skip to content

Commit

Permalink
feat: introduce flaky lines, remove unnecessary functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaevg committed Feb 4, 2024
1 parent 3f75758 commit 2938e3d
Show file tree
Hide file tree
Showing 14 changed files with 382 additions and 1,065 deletions.
2 changes: 1 addition & 1 deletion .config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
moduleFileExtensions: ['js', 'ts'],
rootDir: '..',
testEnvironment: 'node',
testMatch: ['<rootDir>/src/**/*.test.ts'],
testMatch: ['<rootDir>/src/**/*.spec.ts'],
transform: {
'^.+\\.ts$': 'ts-jest',
},
Expand Down
229 changes: 8 additions & 221 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
# retry

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](#Ownership)

---
Retries an Action step on failure or timeout. Determines if a failure is a flake based on the test output

## Inputs

### `timeout_minutes`

**Required** Minutes to wait before attempt times out. Must only specify either minutes or seconds

### `timeout_seconds`

**Required** Seconds to wait before attempt times out. Must only specify either minutes or seconds

### `max_attempts`

**Required** Number of attempts to make before failing the step
Expand All @@ -24,219 +12,18 @@ Retries an Action step on failure or timeout. This is currently intended to repl

**Required** The command to run

### `retry_wait_seconds`

**Optional** Number of seconds to wait before attempting the next retry. Defaults to `10`

### `shell`

**Optional** Shell to use to execute `command`. Defaults to `powershell` on Windows, `bash` otherwise. Supports bash, python, pwsh, sh, cmd, and powershell per [docs](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell)

### `polling_interval_seconds`

**Optional** Number of seconds to wait while polling for command result. Defaults to `1`

### `retry_on`

**Optional** Event to retry on. Currently supports [any (default), timeout, error].

### `warning_on_retry`

**Optional** Whether to output a warning on retry, or just output to info. Defaults to `true`.

### `on_retry_command`

**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.

### `new_command_on_retry`

**Optional** Command to run if the first attempt fails. This command will be called on all subsequent attempts.

### `continue_on_error`

**Optional** Exit successfully even if an error occurs. Same as native continue-on-error behavior, but for use in composite actions. Defaults to `false`

### `retry_on_exit_code`
### `flaky_test_output_lines`

**Optional** Specific exit code to retry on. This will only retry for the given error code and fail immediately other error codes.

## 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
**Optional** Specify which lines in output indicate that the failure is flaky. Note - if not specified, all failures are considered as real failures.

## Examples

### Shell

```yaml
uses: nick-fields/retry@v3
uses: oppia/retry@develop
with:
timeout_minutes: 10
max_attempts: 3
shell: pwsh
command: dir
```
### Timeout in minutes
```yaml
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
command: npm run some-typically-slow-script
```
### Timeout in seconds
```yaml
uses: nick-fields/retry@v3
with:
timeout_seconds: 15
max_attempts: 3
command: npm run some-typically-fast-script
```
### Only retry after timeout
```yaml
uses: nick-fields/retry@v3
with:
timeout_seconds: 15
max_attempts: 3
retry_on: timeout
command: npm run some-typically-fast-script
```
### Only retry after error
```yaml
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
```yaml
- 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
```yaml
- 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 }}
```
### Run script after failure but before retry
```yaml
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
```
### Run different command after first failure
```yaml
uses: nick-fields/retry@v3
with:
timeout_seconds: 15
max_attempts: 3
command: npx jest
new_command_on_retry: npx jest --onlyFailures
```
### Run multi-line, multi-command script
```yaml
name: Multi-line multi-command Test
uses: ./
with:
timeout_minutes: 1
max_attempts: 2
command: |
Get-ComputerInfo
Get-Date
flaky_test_output_lines: |
First flaky line
Second flaky line
command: ./run_tests.sh
```
### Run multi-line, single-command script
```yaml
name: Multi-line single-command Test
uses: ./
with:
timeout_minutes: 1
max_attempts: 2
shell: cmd
command: >-
echo "this is
a test"
```

## 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.

---

## **Ownership**

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>`.
44 changes: 3 additions & 41 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,16 @@
name: Retry Step
description: 'Retry a step on failure or timeout'
inputs:
timeout_minutes:
description: Minutes to wait before attempt times out. Must only specify either minutes or seconds
required: false
timeout_seconds:
description: Seconds to wait before attempt times out. Must only specify either minutes or seconds
required: false
max_attempts:
description: Number of attempts to make before failing the step
required: true
default: 3
default: 2
command:
description: The command to run
required: true
retry_wait_seconds:
description: Number of seconds to wait before attempting the next retry
required: false
default: 10
shell:
description: Alternate shell to use (defaults to powershell on windows, bash otherwise). Supports bash, python, pwsh, sh, cmd, and powershell
required: false
polling_interval_seconds:
description: Number of seconds to wait for each check that command has completed running
required: false
default: 1
retry_on:
description: Event to retry on. Currently supported [any, timeout, error]
warning_on_retry:
description: Whether to output a warning on retry, or just output to info. Defaults to true
default: true
on_retry_command:
description: Command to run before a retry (such as a cleanup script). Any error thrown from retry command is caught and surfaced as a warning.
required: false
continue_on_error:
description: Exits successfully even if an error occurs. Same as native continue-on-error behavior, but for use in composite actions. Default is false
default: false
new_command_on_retry:
description: Command to run if the first attempt fails. This command will be called on all subsequent attempts.
required: false
retry_on_exit_code:
description: Specific exit code to retry on. This will only retry for the given error code and fail immediately other error codes.
flaky_test_output_lines:
description: Specify which lines in output indicate that the failure is flaky. Note - if not specified, all failures are considered as real failures.
required: false
outputs:
total_attempts:
description: The final number of attempts made
exit_code:
description: The final exit code returned by the command
exit_error:
description: The final error returned by the command
runs:
using: 'node20'
main: 'dist/index.js'
Loading

0 comments on commit 2938e3d

Please sign in to comment.