mirror of
https://github.com/nick-fields/retry.git
synced 2026-02-10 15:15:30 +00:00
Compare commits
5 Commits
anthonyc/m
...
v2.8.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
616fa81820 | ||
|
|
a25f198007 | ||
|
|
0f986c438b | ||
|
|
3dad7de805 | ||
|
|
14b6b46d04 |
1
.config/.eslintignore
Normal file
1
.config/.eslintignore
Normal file
@@ -0,0 +1 @@
|
||||
.eslintrc.js
|
||||
7
.config/.eslintrc.js
Normal file
7
.config/.eslintrc.js
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
|
||||
ignorePatterns: ['**/*.js', 'dist/'],
|
||||
};
|
||||
2
.config/.prettierignore
Normal file
2
.config/.prettierignore
Normal file
@@ -0,0 +1,2 @@
|
||||
dist/
|
||||
node_modules/
|
||||
5
.config/.prettierrc.yml
Normal file
5
.config/.prettierrc.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
trailingComma: 'es5'
|
||||
tabWidth: 2
|
||||
semi: true
|
||||
singleQuote: true
|
||||
printWidth: 100
|
||||
13
.config/jest.config.js
Normal file
13
.config/jest.config.js
Normal file
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
rootDir: '..',
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['<rootDir>/src/**/*.test.ts'],
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest',
|
||||
},
|
||||
verbose: true,
|
||||
collectCoverage: true,
|
||||
collectCoverageFrom: ['src/**/*.{js,ts,jsx,tsx}'],
|
||||
};
|
||||
1
.github/ISSUE_TEMPLATE/bug-report.md
vendored
1
.github/ISSUE_TEMPLATE/bug-report.md
vendored
@@ -4,7 +4,6 @@ about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: nick-invision
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
|
||||
12
.github/codecov.yml
vendored
Normal file
12
.github/codecov.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# see https://docs.codecov.com/docs/codecovyml-reference
|
||||
codecov:
|
||||
require_ci_to_pass: false
|
||||
comment:
|
||||
layout: 'diff, flags'
|
||||
behavior: default
|
||||
require_changes: true
|
||||
coverage:
|
||||
# don't pass/fail PRs for coverage yet
|
||||
status:
|
||||
project: off
|
||||
patch: off
|
||||
412
.github/workflows/ci_cd.yml
vendored
412
.github/workflows/ci_cd.yml
vendored
@@ -4,10 +4,181 @@ on:
|
||||
|
||||
jobs:
|
||||
# runs on branch pushes only
|
||||
ci:
|
||||
name: Run Tests
|
||||
ci_unit:
|
||||
name: Run Unit Tests
|
||||
if: startsWith(github.ref, 'refs/heads')
|
||||
runs-on: ubuntu-18.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Run Unit Tests
|
||||
run: npm test
|
||||
- uses: codecov/codecov-action@v3
|
||||
with:
|
||||
directory: ./coverage/
|
||||
verbose: true
|
||||
|
||||
ci_integration_envvar:
|
||||
name: Run Integration Env Var Tests
|
||||
if: startsWith(github.ref, 'refs/heads')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: env-vars-passed-through
|
||||
uses: ./
|
||||
env:
|
||||
NODE_OPTIONS: '--max_old_space_size=3072'
|
||||
with:
|
||||
timeout_minutes: 1
|
||||
max_attempts: 2
|
||||
command: node -e 'console.log(process.env.NODE_OPTIONS)'
|
||||
|
||||
ci_integration_large_output:
|
||||
name: Run Integration Large Output Tests
|
||||
if: startsWith(github.ref, 'refs/heads')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Test 100MiB of output can be processed
|
||||
id: large-output
|
||||
continue-on-error: true
|
||||
uses: ./
|
||||
with:
|
||||
max_attempts: 1
|
||||
timeout_minutes: 5
|
||||
command: 'make -C ./test-data/large-output bytes-102400'
|
||||
- name: Assert test had expected result
|
||||
uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: failure
|
||||
actual: ${{ steps.large-output.outcome }}
|
||||
- name: Assert exit code is expected
|
||||
uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 2
|
||||
actual: ${{ steps.large-output.outputs.exit_code }}
|
||||
|
||||
ci_integration_retry_on_exit_code:
|
||||
name: Run Integration retry_on_exit_code Tests
|
||||
if: startsWith(github.ref, 'refs/heads')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: retry_on_exit_code (with expected error code)
|
||||
id: retry_on_exit_code_expected
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
timeout_minutes: 1
|
||||
retry_on_exit_code: 2
|
||||
max_attempts: 3
|
||||
command: node -e "process.exit(2)"
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: failure
|
||||
actual: ${{ steps.retry_on_exit_code_expected.outcome }}
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 3
|
||||
actual: ${{ steps.retry_on_exit_code_expected.outputs.total_attempts }}
|
||||
|
||||
- name: retry_on_exit_code (with unexpected error code)
|
||||
id: retry_on_exit_code_unexpected
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
timeout_minutes: 1
|
||||
retry_on_exit_code: 2
|
||||
max_attempts: 3
|
||||
command: node -e "process.exit(1)"
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: failure
|
||||
actual: ${{ steps.retry_on_exit_code_unexpected.outcome }}
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 1
|
||||
actual: ${{ steps.retry_on_exit_code_unexpected.outputs.total_attempts }}
|
||||
|
||||
ci_integration_continue_on_error:
|
||||
name: Run Integration continue_on_error Tests
|
||||
if: startsWith(github.ref, 'refs/heads')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: happy-path (continue_on_error)
|
||||
id: happy_path_continue_on_error
|
||||
uses: ./
|
||||
with:
|
||||
command: node -e "process.exit(0)"
|
||||
timeout_minutes: 1
|
||||
continue_on_error: true
|
||||
- name: sad-path (continue_on_error)
|
||||
id: sad_path_continue_on_error
|
||||
uses: ./
|
||||
with:
|
||||
command: node -e "process.exit(33)"
|
||||
timeout_minutes: 1
|
||||
continue_on_error: true
|
||||
- name: Verify continue_on_error returns correct exit code on success
|
||||
uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 0
|
||||
actual: ${{ steps.happy_path_continue_on_error.outputs.exit_code }}
|
||||
- name: Verify continue_on_error exits with correct outcome on success
|
||||
uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: success
|
||||
actual: ${{ steps.happy_path_continue_on_error.outcome }}
|
||||
- name: Verify continue_on_error returns correct exit code on error
|
||||
uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 33
|
||||
actual: ${{ steps.sad_path_continue_on_error.outputs.exit_code }}
|
||||
- name: Verify continue_on_error exits with successful outcome when an error occurs
|
||||
uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: success
|
||||
actual: ${{ steps.sad_path_continue_on_error.outcome }}
|
||||
|
||||
ci_integration:
|
||||
name: Run Integration Tests
|
||||
if: startsWith(github.ref, 'refs/heads')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
@@ -78,42 +249,6 @@ 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_expected
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
timeout_minutes: 1
|
||||
retry_on_exit_code: 2
|
||||
max_attempts: 3
|
||||
command: node -e "process.exit(2)"
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: failure
|
||||
actual: ${{ steps.retry_on_exit_code_expected.outcome }}
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 3
|
||||
actual: ${{ steps.retry_on_exit_code_expected.outputs.total_attempts }}
|
||||
|
||||
- name: retry_on_exit_code (with unexpected error code)
|
||||
id: retry_on_exit_code_unexpected
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
timeout_minutes: 1
|
||||
retry_on_exit_code: 2
|
||||
max_attempts: 3
|
||||
command: node -e "process.exit(1)"
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: failure
|
||||
actual: ${{ steps.retry_on_exit_code_unexpected.outcome }}
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 1
|
||||
actual: ${{ steps.retry_on_exit_code_unexpected.outputs.total_attempts }}
|
||||
|
||||
- name: on-retry-cmd (on-retry fails)
|
||||
id: on-retry-cmd-fails
|
||||
uses: ./
|
||||
@@ -141,41 +276,6 @@ jobs:
|
||||
expected: failure
|
||||
actual: ${{ steps.sad_path_error.outcome }}
|
||||
|
||||
- name: happy-path (continue_on_error)
|
||||
id: happy_path_continue_on_error
|
||||
uses: ./
|
||||
with:
|
||||
command: node -e "process.exit(0)"
|
||||
timeout_minutes: 1
|
||||
continue_on_error: true
|
||||
- name: sad-path (continue_on_error)
|
||||
id: sad_path_continue_on_error
|
||||
uses: ./
|
||||
with:
|
||||
command: node -e "process.exit(33)"
|
||||
timeout_minutes: 1
|
||||
continue_on_error: true
|
||||
- name: Verify continue_on_error returns correct exit code on success
|
||||
uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 0
|
||||
actual: ${{ steps.happy_path_continue_on_error.outputs.exit_code }}
|
||||
- name: Verify continue_on_error exits with correct outcome on success
|
||||
uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: success
|
||||
actual: ${{ steps.happy_path_continue_on_error.outcome }}
|
||||
- name: Verify continue_on_error returns correct exit code on error
|
||||
uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 33
|
||||
actual: ${{ steps.sad_path_continue_on_error.outputs.exit_code }}
|
||||
- name: Verify continue_on_error exits with successful outcome when an error occurs
|
||||
uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: success
|
||||
actual: ${{ steps.sad_path_continue_on_error.outcome }}
|
||||
|
||||
- name: retry_on (timeout) fails early if error encountered
|
||||
id: retry_on_timeout_fail
|
||||
uses: ./
|
||||
@@ -220,7 +320,39 @@ jobs:
|
||||
expected: 2
|
||||
actual: ${{ steps.retry_on_error.outputs.exit_code }}
|
||||
|
||||
# timeout tests (takes longer to run so run last)
|
||||
- name: sad-path (wrong shell for OS)
|
||||
id: wrong_shell
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
timeout_minutes: 1
|
||||
max_attempts: 2
|
||||
shell: cmd
|
||||
command: 'dir'
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 2
|
||||
actual: ${{ steps.wrong_shell.outputs.total_attempts }}
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: failure
|
||||
actual: ${{ steps.wrong_shell.outcome }}
|
||||
|
||||
# timeout tests take longer to run so run in parallel
|
||||
ci_integration_timeout:
|
||||
name: Run Integration Timeout Tests
|
||||
if: startsWith(github.ref, 'refs/heads')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: sad-path (timeout)
|
||||
id: sad_path_timeout
|
||||
uses: ./
|
||||
@@ -295,132 +427,6 @@ jobs:
|
||||
expected: failure
|
||||
actual: ${{ steps.sad_path_timeout.outcome }}
|
||||
|
||||
- name: sad-path (wrong shell for OS)
|
||||
id: wrong_shell
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
timeout_minutes: 1
|
||||
max_attempts: 2
|
||||
shell: cmd
|
||||
command: 'dir'
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 2
|
||||
actual: ${{ steps.wrong_shell.outputs.total_attempts }}
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: failure
|
||||
actual: ${{ steps.wrong_shell.outcome }}
|
||||
|
||||
ci_multiline_tests:
|
||||
name: Run Tests (Multiline)
|
||||
if: startsWith(github.ref, 'refs/heads')
|
||||
runs-on: ubuntu-18.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Multi-line 2 commands non existent first command
|
||||
id: multi_line_2_commands_non_existent_first_command
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
shell: bash
|
||||
timeout_seconds: 1
|
||||
max_attempts: 2
|
||||
command: |
|
||||
i-do-not-exist && \
|
||||
echo "i-exist"
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 2
|
||||
actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.total_attempts }}
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 'Final attempt failed'
|
||||
actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_error }}
|
||||
comparison: contains
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
# The 127 error code indicates “command not found”.
|
||||
expected: '127'
|
||||
actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_code }}
|
||||
comparison: contains
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 'i-exist'
|
||||
actual: ${{ steps.multi_line_2_commands_non_existent_first_command.outputs.exit_error }}
|
||||
comparison: notContains
|
||||
|
||||
- name: Multi-line 2 commands happy path test
|
||||
id: multi_line_2_commands_happy_path
|
||||
uses: ./
|
||||
with:
|
||||
shell: bash
|
||||
timeout_seconds: 1
|
||||
max_attempts: 2
|
||||
command: |
|
||||
echo "foo" && \
|
||||
echo "bar"
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 1
|
||||
actual: ${{ steps.multi_line_2_commands_happy_path.outputs.total_attempts }}
|
||||
|
||||
- name: Conventional multi-line non existent first command
|
||||
id: conventional_multi_line_non_existent_first_command
|
||||
uses: ./
|
||||
continue-on-error: true
|
||||
with:
|
||||
shell: bash
|
||||
timeout_seconds: 1
|
||||
max_attempts: 2
|
||||
command: |
|
||||
i-do-not-exist
|
||||
echo "i-exist"
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 2
|
||||
actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.total_attempts }}
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 'Final attempt failed'
|
||||
actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_error }}
|
||||
comparison: contains
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
# The 127 error code indicates “command not found”.
|
||||
expected: '127'
|
||||
actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_code }}
|
||||
comparison: contains
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 'i-exist'
|
||||
actual: ${{ steps.conventional_multi_line_non_existent_first_command.outputs.exit_error }}
|
||||
comparison: notContains
|
||||
|
||||
- name: Conventional multi-line happy path test
|
||||
id: conventional_multi_line_happy_path
|
||||
uses: ./
|
||||
with:
|
||||
shell: bash
|
||||
timeout_seconds: 1
|
||||
max_attempts: 2
|
||||
command: |
|
||||
echo "foo"
|
||||
echo "bar"
|
||||
- uses: nick-invision/assert-action@v1
|
||||
with:
|
||||
expected: 1
|
||||
actual: ${{ steps.conventional_multi_line_happy_path.outputs.total_attempts }}
|
||||
|
||||
ci_windows:
|
||||
name: Run Windows Tests
|
||||
if: startsWith(github.ref, 'refs/heads')
|
||||
@@ -476,9 +482,9 @@ jobs:
|
||||
# runs on push to master only
|
||||
cd:
|
||||
name: Publish Action
|
||||
needs: ci
|
||||
needs: [ci_integration, ci_integration_timeout, ci_windows]
|
||||
if: github.ref == 'refs/heads/master'
|
||||
runs-on: ubuntu-18.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
5
.husky/commit-msg
Executable file
5
.husky/commit-msg
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
# lint commit message
|
||||
npx --no -- commitlint --config ./.config/.commitlintrc.js --edit $1
|
||||
8
.husky/pre-commit
Executable file
8
.husky/pre-commit
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
# run lint/styling on staged changes
|
||||
npx lint-staged
|
||||
|
||||
# regenerate dist
|
||||
npm run prepare && git add .
|
||||
@@ -1,7 +0,0 @@
|
||||
module.exports = {
|
||||
tabWidth: 2,
|
||||
printWidth: 100,
|
||||
semi: true,
|
||||
singleQuote: true,
|
||||
trailingComma: 'es5',
|
||||
};
|
||||
3
.vscode/extensions.json
vendored
Normal file
3
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["esbenp.prettier-vscode"]
|
||||
}
|
||||
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true,
|
||||
"prettier.requireConfig": true,
|
||||
"typescript.tsdk": "node_modules/typescript/lib",
|
||||
"editor.tabSize": 2
|
||||
"prettier.configPath": "./.config/.prettierrc.yml",
|
||||
"prettier.ignorePath": "./.config/.prettierignore",
|
||||
"typescript.tsdk": "node_modules/typescript/lib"
|
||||
}
|
||||
|
||||
168
dist/index.js
vendored
168
dist/index.js
vendored
@@ -635,15 +635,15 @@ var util_1 = __webpack_require__(322);
|
||||
var TIMEOUT_MINUTES = getInputNumber('timeout_minutes', false);
|
||||
var TIMEOUT_SECONDS = getInputNumber('timeout_seconds', false);
|
||||
var MAX_ATTEMPTS = getInputNumber('max_attempts', true) || 3;
|
||||
var COMMAND = core_1.getInput('command', { required: true });
|
||||
var COMMAND = (0, core_1.getInput)('command', { required: true });
|
||||
var RETRY_WAIT_SECONDS = getInputNumber('retry_wait_seconds', false) || 10;
|
||||
var SHELL = core_1.getInput('shell');
|
||||
var SHELL = (0, core_1.getInput)('shell');
|
||||
var POLLING_INTERVAL_SECONDS = getInputNumber('polling_interval_seconds', false) || 1;
|
||||
var RETRY_ON = core_1.getInput('retry_on') || 'any';
|
||||
var WARNING_ON_RETRY = core_1.getInput('warning_on_retry').toLowerCase() === 'true';
|
||||
var ON_RETRY_COMMAND = core_1.getInput('on_retry_command');
|
||||
var RETRY_ON = (0, core_1.getInput)('retry_on') || 'any';
|
||||
var WARNING_ON_RETRY = (0, core_1.getInput)('warning_on_retry').toLowerCase() === 'true';
|
||||
var ON_RETRY_COMMAND = (0, 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 NEW_COMMAND_ON_RETRY = (0, 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';
|
||||
@@ -652,21 +652,21 @@ var OUTPUT_EXIT_ERROR_KEY = 'exit_error';
|
||||
var exit;
|
||||
var done;
|
||||
function getInputNumber(id, required) {
|
||||
var input = core_1.getInput(id, { required: required });
|
||||
var input = (0, core_1.getInput)(id, { required: required });
|
||||
var num = Number.parseInt(input);
|
||||
// empty is ok
|
||||
if (!input && !required) {
|
||||
return;
|
||||
}
|
||||
if (!Number.isInteger(num)) {
|
||||
throw "Input " + id + " only accepts numbers. Received " + input;
|
||||
throw "Input ".concat(id, " only accepts numbers. Received ").concat(input);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
function getInputBoolean(id) {
|
||||
var input = core_1.getInput(id);
|
||||
var input = (0, core_1.getInput)(id);
|
||||
if (!['true', 'false'].includes(input.toLowerCase())) {
|
||||
throw "Input " + id + " only accepts boolean values. Received " + input;
|
||||
throw "Input ".concat(id, " only accepts boolean values. Received ").concat(input);
|
||||
}
|
||||
return input.toLowerCase() === 'true';
|
||||
}
|
||||
@@ -677,11 +677,11 @@ function retryWait() {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
waitStart = Date.now();
|
||||
return [4 /*yield*/, util_1.wait(milliseconds_1.default.seconds(RETRY_WAIT_SECONDS))];
|
||||
return [4 /*yield*/, (0, util_1.wait)(milliseconds_1.default.seconds(RETRY_WAIT_SECONDS))];
|
||||
case 1:
|
||||
_a.sent();
|
||||
core_1.debug("Waited " + (Date.now() - waitStart) + "ms");
|
||||
core_1.debug("Configured wait: " + milliseconds_1.default.seconds(RETRY_WAIT_SECONDS) + "ms");
|
||||
(0, core_1.debug)("Waited ".concat(Date.now() - waitStart, "ms"));
|
||||
(0, core_1.debug)("Configured wait: ".concat(milliseconds_1.default.seconds(RETRY_WAIT_SECONDS), "ms"));
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
@@ -708,37 +708,33 @@ function getTimeout() {
|
||||
}
|
||||
function getExecutable() {
|
||||
if (!SHELL) {
|
||||
return OS === 'win32' ? 'powershell' : 'bash -e';
|
||||
return OS === 'win32' ? 'powershell' : 'bash';
|
||||
}
|
||||
var executable;
|
||||
switch (SHELL) {
|
||||
case "bash": {
|
||||
// -e to not ignore errors, but exit with non-zero code.
|
||||
executable = "bash -e";
|
||||
break;
|
||||
}
|
||||
case "python":
|
||||
case "pwsh": {
|
||||
case 'bash':
|
||||
case 'python':
|
||||
case 'pwsh': {
|
||||
executable = SHELL;
|
||||
break;
|
||||
}
|
||||
case "sh": {
|
||||
case 'sh': {
|
||||
if (OS === 'win32') {
|
||||
throw new Error("Shell " + SHELL + " not allowed on OS " + OS);
|
||||
throw new Error("Shell ".concat(SHELL, " not allowed on OS ").concat(OS));
|
||||
}
|
||||
executable = SHELL;
|
||||
break;
|
||||
}
|
||||
case "cmd":
|
||||
case "powershell": {
|
||||
case 'cmd':
|
||||
case 'powershell': {
|
||||
if (OS !== 'win32') {
|
||||
throw new Error("Shell " + SHELL + " not allowed on OS " + OS);
|
||||
throw new Error("Shell ".concat(SHELL, " not allowed on OS ").concat(OS));
|
||||
}
|
||||
executable = SHELL + ".exe";
|
||||
executable = SHELL + '.exe';
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error("Shell " + SHELL + " not supported. See https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell for supported shells");
|
||||
throw new Error("Shell ".concat(SHELL, " not supported. See https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell for supported shells"));
|
||||
}
|
||||
}
|
||||
return executable;
|
||||
@@ -756,13 +752,13 @@ function runRetryCmd() {
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
_a.trys.push([1, 3, , 4]);
|
||||
return [4 /*yield*/, child_process_1.execSync(ON_RETRY_COMMAND, { stdio: 'inherit' })];
|
||||
return [4 /*yield*/, (0, child_process_1.execSync)(ON_RETRY_COMMAND, { stdio: 'inherit' })];
|
||||
case 2:
|
||||
_a.sent();
|
||||
return [3 /*break*/, 4];
|
||||
case 3:
|
||||
error_1 = _a.sent();
|
||||
core_1.info("WARNING: Retry command threw the error " + error_1.message);
|
||||
(0, core_1.info)("WARNING: Retry command threw the error ".concat(error_1.message));
|
||||
return [3 /*break*/, 4];
|
||||
case 4: return [2 /*return*/];
|
||||
}
|
||||
@@ -780,10 +776,10 @@ function runCmd(attempt) {
|
||||
executable = getExecutable();
|
||||
exit = 0;
|
||||
done = false;
|
||||
core_1.debug("Running command " + COMMAND + " on " + OS + " using shell \"" + executable + "\"");
|
||||
(0, core_1.debug)("Running command ".concat(COMMAND, " on ").concat(OS, " using shell ").concat(executable));
|
||||
child = attempt > 1 && NEW_COMMAND_ON_RETRY
|
||||
? child_process_1.exec(NEW_COMMAND_ON_RETRY, { 'shell': executable })
|
||||
: child_process_1.exec(COMMAND, { 'shell': executable });
|
||||
? (0, child_process_1.spawn)(NEW_COMMAND_ON_RETRY, { shell: executable })
|
||||
: (0, child_process_1.spawn)(COMMAND, { shell: executable });
|
||||
(_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', function (data) {
|
||||
process.stdout.write(data);
|
||||
});
|
||||
@@ -791,8 +787,8 @@ function runCmd(attempt) {
|
||||
process.stdout.write(data);
|
||||
});
|
||||
child.on('exit', function (code, signal) {
|
||||
core_1.debug("Code: " + code);
|
||||
core_1.debug("Signal: " + signal);
|
||||
(0, core_1.debug)("Code: ".concat(code));
|
||||
(0, core_1.debug)("Signal: ".concat(signal));
|
||||
if (code && code > 0) {
|
||||
exit = code;
|
||||
}
|
||||
@@ -803,7 +799,7 @@ function runCmd(attempt) {
|
||||
done = true;
|
||||
});
|
||||
_c.label = 1;
|
||||
case 1: return [4 /*yield*/, util_1.wait(milliseconds_1.default.seconds(POLLING_INTERVAL_SECONDS))];
|
||||
case 1: return [4 /*yield*/, (0, util_1.wait)(milliseconds_1.default.seconds(POLLING_INTERVAL_SECONDS))];
|
||||
case 2:
|
||||
_c.sent();
|
||||
_c.label = 3;
|
||||
@@ -811,18 +807,18 @@ function runCmd(attempt) {
|
||||
if (Date.now() < end_time && !done) return [3 /*break*/, 1];
|
||||
_c.label = 4;
|
||||
case 4:
|
||||
if (!!done) return [3 /*break*/, 6];
|
||||
tree_kill_1.default(child.pid);
|
||||
if (!(!done && child.pid)) return [3 /*break*/, 6];
|
||||
(0, tree_kill_1.default)(child.pid);
|
||||
return [4 /*yield*/, retryWait()];
|
||||
case 5:
|
||||
_c.sent();
|
||||
throw new Error("Timeout of " + getTimeout() + "ms hit");
|
||||
throw new Error("Timeout of ".concat(getTimeout(), "ms hit"));
|
||||
case 6:
|
||||
if (!(exit > 0)) return [3 /*break*/, 8];
|
||||
return [4 /*yield*/, retryWait()];
|
||||
case 7:
|
||||
_c.sent();
|
||||
throw new Error("Child_process exited with error code " + exit);
|
||||
throw new Error("Child_process exited with error code ".concat(exit));
|
||||
case 8: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
@@ -844,16 +840,16 @@ function runAction() {
|
||||
case 3:
|
||||
_a.trys.push([3, 5, , 12]);
|
||||
// just keep overwriting attempts output
|
||||
core_1.setOutput(OUTPUT_TOTAL_ATTEMPTS_KEY, attempt);
|
||||
(0, core_1.setOutput)(OUTPUT_TOTAL_ATTEMPTS_KEY, attempt);
|
||||
return [4 /*yield*/, runCmd(attempt)];
|
||||
case 4:
|
||||
_a.sent();
|
||||
core_1.info("Command completed after " + attempt + " attempt(s).");
|
||||
(0, core_1.info)("Command completed after ".concat(attempt, " attempt(s)."));
|
||||
return [3 /*break*/, 13];
|
||||
case 5:
|
||||
error_2 = _a.sent();
|
||||
if (!(attempt === MAX_ATTEMPTS)) return [3 /*break*/, 6];
|
||||
throw new Error("Final attempt failed. " + error_2.message);
|
||||
throw new Error("Final attempt failed. ".concat(error_2.message));
|
||||
case 6:
|
||||
if (!(!done && RETRY_ON === 'error')) return [3 /*break*/, 7];
|
||||
// error: timeout
|
||||
@@ -869,10 +865,10 @@ function runAction() {
|
||||
case 10:
|
||||
_a.sent();
|
||||
if (WARNING_ON_RETRY) {
|
||||
core_1.warning("Attempt " + attempt + " failed. Reason: " + error_2.message);
|
||||
(0, core_1.warning)("Attempt ".concat(attempt, " failed. Reason: ").concat(error_2.message));
|
||||
}
|
||||
else {
|
||||
core_1.info("Attempt " + attempt + " failed. Reason: " + error_2.message);
|
||||
(0, core_1.info)("Attempt ".concat(attempt, " failed. Reason: ").concat(error_2.message));
|
||||
}
|
||||
_a.label = 11;
|
||||
case 11: return [3 /*break*/, 12];
|
||||
@@ -886,21 +882,21 @@ function runAction() {
|
||||
}
|
||||
runAction()
|
||||
.then(function () {
|
||||
core_1.setOutput(OUTPUT_EXIT_CODE_KEY, 0);
|
||||
(0, core_1.setOutput)(OUTPUT_EXIT_CODE_KEY, 0);
|
||||
process.exit(0); // success
|
||||
})
|
||||
.catch(function (err) {
|
||||
// exact error code if available, otherwise just 1
|
||||
var exitCode = exit > 0 ? exit : 1;
|
||||
if (CONTINUE_ON_ERROR) {
|
||||
core_1.warning(err.message);
|
||||
(0, core_1.warning)(err.message);
|
||||
}
|
||||
else {
|
||||
core_1.error(err.message);
|
||||
(0, core_1.error)(err.message);
|
||||
}
|
||||
// these can be helpful to know if continue-on-error is true
|
||||
core_1.setOutput(OUTPUT_EXIT_ERROR_KEY, err.message);
|
||||
core_1.setOutput(OUTPUT_EXIT_CODE_KEY, exitCode);
|
||||
(0, core_1.setOutput)(OUTPUT_EXIT_ERROR_KEY, err.message);
|
||||
(0, core_1.setOutput)(OUTPUT_EXIT_CODE_KEY, exitCode);
|
||||
// if continue_on_error, exit with exact error code else exit gracefully
|
||||
// mimics native continue-on-error that is not supported in composite actions
|
||||
process.exit(CONTINUE_ON_ERROR ? 0 : exitCode);
|
||||
@@ -1960,6 +1956,13 @@ Object.defineProperty(exports, "summary", { enumerable: true, get: function () {
|
||||
*/
|
||||
var summary_2 = __webpack_require__(665);
|
||||
Object.defineProperty(exports, "markdownSummary", { enumerable: true, get: function () { return summary_2.markdownSummary; } });
|
||||
/**
|
||||
* Path exports
|
||||
*/
|
||||
var path_utils_1 = __webpack_require__(573);
|
||||
Object.defineProperty(exports, "toPosixPath", { enumerable: true, get: function () { return path_utils_1.toPosixPath; } });
|
||||
Object.defineProperty(exports, "toWin32Path", { enumerable: true, get: function () { return path_utils_1.toWin32Path; } });
|
||||
Object.defineProperty(exports, "toPlatformPath", { enumerable: true, get: function () { return path_utils_1.toPlatformPath; } });
|
||||
//# sourceMappingURL=core.js.map
|
||||
|
||||
/***/ }),
|
||||
@@ -2052,6 +2055,71 @@ exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHand
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 573:
|
||||
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.toPlatformPath = exports.toWin32Path = exports.toPosixPath = void 0;
|
||||
const path = __importStar(__webpack_require__(622));
|
||||
/**
|
||||
* toPosixPath converts the given path to the posix form. On Windows, \\ will be
|
||||
* replaced with /.
|
||||
*
|
||||
* @param pth. Path to transform.
|
||||
* @return string Posix path.
|
||||
*/
|
||||
function toPosixPath(pth) {
|
||||
return pth.replace(/[\\]/g, '/');
|
||||
}
|
||||
exports.toPosixPath = toPosixPath;
|
||||
/**
|
||||
* toWin32Path converts the given path to the win32 form. On Linux, / will be
|
||||
* replaced with \\.
|
||||
*
|
||||
* @param pth. Path to transform.
|
||||
* @return string Win32 path.
|
||||
*/
|
||||
function toWin32Path(pth) {
|
||||
return pth.replace(/[/]/g, '\\');
|
||||
}
|
||||
exports.toWin32Path = toWin32Path;
|
||||
/**
|
||||
* toPlatformPath converts the given path to a platform-specific path. It does
|
||||
* this by replacing instances of / and \ with the platform-specific path
|
||||
* separator.
|
||||
*
|
||||
* @param pth The path to platformize.
|
||||
* @return string The platform-specific path.
|
||||
*/
|
||||
function toPlatformPath(pth) {
|
||||
return pth.replace(/[/\\]/g, path.sep);
|
||||
}
|
||||
exports.toPlatformPath = toPlatformPath;
|
||||
//# sourceMappingURL=path-utils.js.map
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 605:
|
||||
/***/ (function(module) {
|
||||
|
||||
|
||||
10526
package-lock.json
generated
10526
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
41
package.json
41
package.json
@@ -3,8 +3,13 @@
|
||||
"version": "0.0.0-managed-by-semantic-release",
|
||||
"description": "Retries a GitHub Action step on failure or timeout.",
|
||||
"scripts": {
|
||||
"lint:base": "eslint --config ./.config/.eslintrc.js ",
|
||||
"lint": "npm run lint:base -- .",
|
||||
"local": "npm run prepare && node -r dotenv/config ./dist/index.js",
|
||||
"prepare": "ncc build src/index.ts"
|
||||
"prepare": "ncc build src/index.ts && husky install",
|
||||
"style:base": "prettier --config ./.config/.prettierrc.yml --ignore-path ./.config/.prettierignore --write ",
|
||||
"style": "npm run style:base -- .",
|
||||
"test": "jest -c ./.config/jest.config.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -18,7 +23,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/nick-invision/retry#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.8.2",
|
||||
"@actions/core": "^1.9.0",
|
||||
"milliseconds": "^1.0.3",
|
||||
"tree-kill": "^1.2.2"
|
||||
},
|
||||
@@ -27,19 +32,35 @@
|
||||
"@commitlint/config-conventional": "^16.2.1",
|
||||
"@semantic-release/changelog": "^6.0.1",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"@types/jest": "^28.1.6",
|
||||
"@types/milliseconds": "0.0.30",
|
||||
"@types/node": "14.14.7",
|
||||
"@types/node": "^16.11.7",
|
||||
"@typescript-eslint/eslint-plugin": "^5.32.0",
|
||||
"@typescript-eslint/parser": "^5.32.0",
|
||||
"@zeit/ncc": "^0.20.5",
|
||||
"dotenv": "8.2.0",
|
||||
"husky": "^4.3.8",
|
||||
"eslint": "^8.21.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"husky": "^8.0.1",
|
||||
"jest": "^28.1.3",
|
||||
"lint-staged": "^13.0.3",
|
||||
"prettier": "^2.7.1",
|
||||
"semantic-release": "19.0.3",
|
||||
"ts-jest": "^28.0.7",
|
||||
"ts-node": "9.0.0",
|
||||
"typescript": "4.0.5"
|
||||
"typescript": "^4.7.4",
|
||||
"yaml-lint": "^1.7.0"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
||||
"pre-commit": "npm run prepare && git add ."
|
||||
}
|
||||
"lint-staged": {
|
||||
"**/*.ts": [
|
||||
"npm run style:base --",
|
||||
"npm run lint:base --"
|
||||
],
|
||||
"**/*.{md,yaml,yml}": [
|
||||
"npm run style:base --"
|
||||
],
|
||||
"**/*.{yaml,yml}": [
|
||||
"npx yamllint "
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
12
sample.env
12
sample.env
@@ -1,7 +1,11 @@
|
||||
# these are the bare minimum envvars required
|
||||
INPUT_TIMEOUT_MINUTES=1
|
||||
INPUT_MAX_ATTEMPTS=3
|
||||
INPUT_COMMAND="node -e 'process.exit(99)'"
|
||||
INPUT_RETRY_WAIT_SECONDS=10
|
||||
SHELL=pwsh
|
||||
INPUT_POLLING_INTERVAL_SECONDS=1
|
||||
INPUT_RETRY_ON=any
|
||||
INPUT_CONTINUE_ON_ERROR=false
|
||||
|
||||
# these are optional
|
||||
#INPUT_RETRY_WAIT_SECONDS=10
|
||||
#SHELL=pwsh
|
||||
#INPUT_POLLING_INTERVAL_SECONDS=1
|
||||
#INPUT_RETRY_ON=any
|
||||
|
||||
59
src/index.ts
59
src/index.ts
@@ -1,5 +1,5 @@
|
||||
import { getInput, error, warning, info, debug, setOutput } from '@actions/core';
|
||||
import { exec, execSync } from 'child_process';
|
||||
import { execSync, spawn } from 'child_process';
|
||||
import ms from 'milliseconds';
|
||||
import kill from 'tree-kill';
|
||||
|
||||
@@ -25,8 +25,8 @@ const OUTPUT_TOTAL_ATTEMPTS_KEY = 'total_attempts';
|
||||
const OUTPUT_EXIT_CODE_KEY = 'exit_code';
|
||||
const OUTPUT_EXIT_ERROR_KEY = 'exit_error';
|
||||
|
||||
var exit: number;
|
||||
var done: boolean;
|
||||
let exit: number;
|
||||
let done: boolean;
|
||||
|
||||
function getInputNumber(id: string, required: boolean): number | undefined {
|
||||
const input = getInput(id, { required });
|
||||
@@ -44,13 +44,13 @@ function getInputNumber(id: string, required: boolean): number | undefined {
|
||||
return num;
|
||||
}
|
||||
|
||||
function getInputBoolean(id: string): Boolean {
|
||||
function getInputBoolean(id: string): boolean {
|
||||
const input = getInput(id);
|
||||
|
||||
if (!['true','false'].includes(input.toLowerCase())) {
|
||||
if (!['true', 'false'].includes(input.toLowerCase())) {
|
||||
throw `Input ${id} only accepts boolean values. Received ${input}`;
|
||||
}
|
||||
return input.toLowerCase() === 'true'
|
||||
return input.toLowerCase() === 'true';
|
||||
}
|
||||
|
||||
async function retryWait() {
|
||||
@@ -78,41 +78,39 @@ function getTimeout(): number {
|
||||
|
||||
function getExecutable(): string {
|
||||
if (!SHELL) {
|
||||
return OS === 'win32' ? 'powershell' : 'bash -e';
|
||||
return OS === 'win32' ? 'powershell' : 'bash';
|
||||
}
|
||||
|
||||
let executable: string;
|
||||
switch (SHELL) {
|
||||
case "bash": {
|
||||
// -e to not ignore errors, but exit with non-zero code.
|
||||
executable = "bash -e";
|
||||
break;
|
||||
}
|
||||
case "python":
|
||||
case "pwsh": {
|
||||
case 'bash':
|
||||
case 'python':
|
||||
case 'pwsh': {
|
||||
executable = SHELL;
|
||||
break;
|
||||
}
|
||||
case "sh": {
|
||||
case 'sh': {
|
||||
if (OS === 'win32') {
|
||||
throw new Error(`Shell ${SHELL} not allowed on OS ${OS}`);
|
||||
}
|
||||
executable = SHELL;
|
||||
break;
|
||||
}
|
||||
case "cmd":
|
||||
case "powershell": {
|
||||
case 'cmd':
|
||||
case 'powershell': {
|
||||
if (OS !== 'win32') {
|
||||
throw new Error(`Shell ${SHELL} not allowed on OS ${OS}`);
|
||||
}
|
||||
executable = SHELL + ".exe";
|
||||
executable = SHELL + '.exe';
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Shell ${SHELL} not supported. See https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell for supported shells`);
|
||||
throw new Error(
|
||||
`Shell ${SHELL} not supported. See https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell for supported shells`
|
||||
);
|
||||
}
|
||||
}
|
||||
return executable
|
||||
return executable;
|
||||
}
|
||||
|
||||
async function runRetryCmd(): Promise<void> {
|
||||
@@ -123,8 +121,9 @@ async function runRetryCmd(): Promise<void> {
|
||||
|
||||
try {
|
||||
await execSync(ON_RETRY_COMMAND, { stdio: 'inherit' });
|
||||
} catch (error) {
|
||||
info(`WARNING: Retry command threw the error ${error.message}`)
|
||||
// eslint-disable-next-line
|
||||
} catch (error: any) {
|
||||
info(`WARNING: Retry command threw the error ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,10 +134,11 @@ async function runCmd(attempt: number) {
|
||||
exit = 0;
|
||||
done = false;
|
||||
|
||||
debug(`Running command ${COMMAND} on ${OS} using shell "${executable}"`)
|
||||
var child = attempt > 1 && NEW_COMMAND_ON_RETRY
|
||||
? exec(NEW_COMMAND_ON_RETRY, { 'shell': executable })
|
||||
: exec(COMMAND, { 'shell': executable });
|
||||
debug(`Running command ${COMMAND} on ${OS} using shell ${executable}`);
|
||||
const child =
|
||||
attempt > 1 && NEW_COMMAND_ON_RETRY
|
||||
? spawn(NEW_COMMAND_ON_RETRY, { shell: executable })
|
||||
: spawn(COMMAND, { shell: executable });
|
||||
|
||||
child.stdout?.on('data', (data) => {
|
||||
process.stdout.write(data);
|
||||
@@ -164,7 +164,7 @@ async function runCmd(attempt: number) {
|
||||
await wait(ms.seconds(POLLING_INTERVAL_SECONDS));
|
||||
} while (Date.now() < end_time && !done);
|
||||
|
||||
if (!done) {
|
||||
if (!done && child.pid) {
|
||||
kill(child.pid);
|
||||
await retryWait();
|
||||
throw new Error(`Timeout of ${getTimeout()}ms hit`);
|
||||
@@ -186,13 +186,14 @@ async function runAction() {
|
||||
await runCmd(attempt);
|
||||
info(`Command completed after ${attempt} attempt(s).`);
|
||||
break;
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line
|
||||
} catch (error: any) {
|
||||
if (attempt === MAX_ATTEMPTS) {
|
||||
throw new Error(`Final attempt failed. ${error.message}`);
|
||||
} else if (!done && RETRY_ON === 'error') {
|
||||
// error: timeout
|
||||
throw error;
|
||||
} else if (RETRY_ON_EXIT_CODE && RETRY_ON_EXIT_CODE !== exit){
|
||||
} else if (RETRY_ON_EXIT_CODE && RETRY_ON_EXIT_CODE !== exit) {
|
||||
throw error;
|
||||
} else if (exit > 0 && RETRY_ON === 'timeout') {
|
||||
// error: error
|
||||
|
||||
17
src/util.test.ts
Normal file
17
src/util.test.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'jest';
|
||||
import { getHeapStatistics } from 'v8';
|
||||
|
||||
import { wait } from './util';
|
||||
|
||||
// mocks the setTimeout function, see https://jestjs.io/docs/timer-mocks
|
||||
jest.useFakeTimers();
|
||||
jest.spyOn(global, 'setTimeout');
|
||||
|
||||
describe('util', () => {
|
||||
test('wait', async () => {
|
||||
const waitTime = 1000;
|
||||
wait(waitTime);
|
||||
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), waitTime);
|
||||
});
|
||||
});
|
||||
13
test-data/large-output/Makefile
Normal file
13
test-data/large-output/Makefile
Normal file
@@ -0,0 +1,13 @@
|
||||
SHELL = bash
|
||||
|
||||
# this tests fix for the following issues
|
||||
# https://github.com/nick-fields/retry/issues/76
|
||||
# https://github.com/nick-fields/retry/issues/84
|
||||
|
||||
bytes-%:
|
||||
for i in {1..$*}; do cat kibibyte.txt; done; exit 2
|
||||
.PHONY: bytes-%
|
||||
|
||||
lines-%:
|
||||
for i in {1..$*}; do echo a; done; exit 2
|
||||
.PHONY: lines-%
|
||||
13
test-data/large-output/kibibyte.txt
Normal file
13
test-data/large-output/kibibyte.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
1: 0000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
2: 0081 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
3: 0162 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
4: 243 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
5: 324 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
6: 405 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
7: 486 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
8: 567 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
9: 648 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
a: 729 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
b: 810 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
c: 891 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
d: 972 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
Reference in New Issue
Block a user