Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: retry only on specific exit code #57

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: CI/CD
on:
push:
branches:
- '**'

jobs:
# runs on branch pushes only
ci:
Expand Down Expand Up @@ -79,6 +78,26 @@ jobs:
command: node -e "process.exit(1)"
on_retry_command: node -e "console.log('this is a retry command')"

- name: retry_on_exit_code (with expected error code)
id: retry_on_exit_code
uses: ./
continue-on-error: true
with:
timeout_minutes: 1
retry_on_exit_code: 2
max_attempts: 3
command: node -e "process.exit(2)"

- name: retry_on_exit_code (with unexpected error code)
id: retry_on_exit_code
uses: ./
continue-on-error: true
with:
timeout_minutes: 1
retry_on_exit_code: 2
max_attempts: 3
command: node -e "process.exit(1)"

- name: on-retry-cmd (on-retry fails)
id: on-retry-cmd-fails
uses: ./
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ inputs:
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.
required: false
outputs:
total_attempts:
description: The final number of attempts made
Expand Down
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ var WARNING_ON_RETRY = core_1.getInput('warning_on_retry').toLowerCase() === 'tr
var ON_RETRY_COMMAND = core_1.getInput('on_retry_command');
var CONTINUE_ON_ERROR = getInputBoolean('continue_on_error');
var NEW_COMMAND_ON_RETRY = core_1.getInput('new_command_on_retry');
var RETRY_ON_EXIT_CODE = getInputNumber('retry_on_exit_code', false);
var OS = process.platform;
var OUTPUT_TOTAL_ATTEMPTS_KEY = 'total_attempts';
var OUTPUT_EXIT_CODE_KEY = 'exit_code';
Expand Down Expand Up @@ -499,7 +500,8 @@ function runAction() {
// error: timeout
throw error_2;
case 7:
if (!(exit > 0 && RETRY_ON === 'timeout')) return [3 /*break*/, 8];
if (!(((RETRY_ON_EXIT_CODE && RETRY_ON_EXIT_CODE !== exit) || exit > 0) &&
RETRY_ON === 'timeout')) return [3 /*break*/, 8];
// error: error
throw error_2;
case 8: return [4 /*yield*/, runRetryCmd()];
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const WARNING_ON_RETRY = getInput('warning_on_retry').toLowerCase() === 'true';
const ON_RETRY_COMMAND = getInput('on_retry_command');
const CONTINUE_ON_ERROR = getInputBoolean('continue_on_error');
const NEW_COMMAND_ON_RETRY = getInput('new_command_on_retry');
const RETRY_ON_EXIT_CODE = getInputNumber('retry_on_exit_code', false);

const OS = process.platform;
const OUTPUT_TOTAL_ATTEMPTS_KEY = 'total_attempts';
Expand Down Expand Up @@ -187,7 +188,10 @@ async function runAction() {
} else if (!done && RETRY_ON === 'error') {
// error: timeout
throw error;
} else if (exit > 0 && RETRY_ON === 'timeout') {
} else if (
((RETRY_ON_EXIT_CODE && RETRY_ON_EXIT_CODE !== exit) || exit > 0) &&
RETRY_ON === 'timeout'
) {
// error: error
throw error;
} else {
Expand Down