Compare commits

..

8 Commits

Author SHA1 Message Date
Nick Fields
8e4fe2b191 patch: remove original multiline tests from ci workflow 2022-06-20 09:26:36 -04:00
Nick Fields
676683ec60 patch: move multiline tests to separate job 2022-06-20 09:25:15 -04:00
Anton Chaporgin
772a768088 tests checked with act 2022-06-20 14:04:06 +03:00
Anton Chaporgin
6e8635d64a tests checked with act 2022-06-20 12:01:02 +03:00
Anton Chaporgin
2d8f74008e self review 2022-06-20 11:28:31 +03:00
Anton Chaporgin
4d604b1776 tests 2022-06-20 11:25:59 +03:00
Nick Fields
29e1861bc1 Merge branch 'master' into patch-1 2022-06-19 22:06:19 -04:00
Anton Chaporgin
db59b2620d add -e to bash to support multiline commands
#43 #53
2022-06-09 10:33:36 +03:00
23 changed files with 660 additions and 10670 deletions

View File

@@ -1 +0,0 @@
.eslintrc.js

View File

@@ -1,7 +0,0 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
ignorePatterns: ['**/*.js', 'dist/'],
};

View File

@@ -1,2 +0,0 @@
dist/
node_modules/

View File

@@ -1,5 +0,0 @@
trailingComma: 'es5'
tabWidth: 2
semi: true
singleQuote: true
printWidth: 100

View File

@@ -1,13 +0,0 @@
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}'],
};

View File

@@ -4,6 +4,7 @@ about: Create a report to help us improve
title: '' title: ''
labels: '' labels: ''
assignees: nick-invision assignees: nick-invision
--- ---
**Describe the bug** **Describe the bug**

12
.github/codecov.yml vendored
View File

@@ -1,12 +0,0 @@
# 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

View File

@@ -4,181 +4,10 @@ on:
jobs: jobs:
# runs on branch pushes only # runs on branch pushes only
ci_unit: ci:
name: Run Unit Tests name: Run Tests
if: startsWith(github.ref, 'refs/heads') if: startsWith(github.ref, 'refs/heads')
runs-on: ubuntu-latest 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: 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: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
@@ -249,6 +78,42 @@ jobs:
command: node -e "process.exit(1)" command: node -e "process.exit(1)"
on_retry_command: node -e "console.log('this is a retry command')" 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) - name: on-retry-cmd (on-retry fails)
id: on-retry-cmd-fails id: on-retry-cmd-fails
uses: ./ uses: ./
@@ -276,6 +141,41 @@ jobs:
expected: failure expected: failure
actual: ${{ steps.sad_path_error.outcome }} 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 - name: retry_on (timeout) fails early if error encountered
id: retry_on_timeout_fail id: retry_on_timeout_fail
uses: ./ uses: ./
@@ -320,39 +220,7 @@ jobs:
expected: 2 expected: 2
actual: ${{ steps.retry_on_error.outputs.exit_code }} actual: ${{ steps.retry_on_error.outputs.exit_code }}
- name: sad-path (wrong shell for OS) # timeout tests (takes longer to run so run last)
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) - name: sad-path (timeout)
id: sad_path_timeout id: sad_path_timeout
uses: ./ uses: ./
@@ -427,6 +295,132 @@ jobs:
expected: failure expected: failure
actual: ${{ steps.sad_path_timeout.outcome }} 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: ci_windows:
name: Run Windows Tests name: Run Windows Tests
if: startsWith(github.ref, 'refs/heads') if: startsWith(github.ref, 'refs/heads')
@@ -482,9 +476,9 @@ jobs:
# runs on push to master only # runs on push to master only
cd: cd:
name: Publish Action name: Publish Action
needs: [ci_integration, ci_integration_timeout, ci_windows] needs: ci
if: github.ref == 'refs/heads/master' if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest runs-on: ubuntu-18.04
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2

View File

@@ -1,5 +0,0 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# lint commit message
npx --no -- commitlint --config ./.config/.commitlintrc.js --edit $1

View File

@@ -1,8 +0,0 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# run lint/styling on staged changes
npx lint-staged
# regenerate dist
npm run prepare && git add .

2
.nvmrc
View File

@@ -1 +1 @@
v16.16.0 v16.14.2

7
.prettierrc.js Normal file
View File

@@ -0,0 +1,7 @@
module.exports = {
tabWidth: 2,
printWidth: 100,
semi: true,
singleQuote: true,
trailingComma: 'es5',
};

View File

@@ -1,3 +0,0 @@
{
"recommendations": ["esbenp.prettier-vscode"]
}

View File

@@ -1,7 +1,6 @@
{ {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true, "editor.formatOnSave": true,
"prettier.configPath": "./.config/.prettierrc.yml", "prettier.requireConfig": true,
"prettier.ignorePath": "./.config/.prettierignore", "typescript.tsdk": "node_modules/typescript/lib",
"typescript.tsdk": "node_modules/typescript/lib" "editor.tabSize": 2
} }

168
dist/index.js vendored
View File

@@ -635,15 +635,15 @@ var util_1 = __webpack_require__(322);
var TIMEOUT_MINUTES = getInputNumber('timeout_minutes', false); var TIMEOUT_MINUTES = getInputNumber('timeout_minutes', false);
var TIMEOUT_SECONDS = getInputNumber('timeout_seconds', false); var TIMEOUT_SECONDS = getInputNumber('timeout_seconds', false);
var MAX_ATTEMPTS = getInputNumber('max_attempts', true) || 3; var MAX_ATTEMPTS = getInputNumber('max_attempts', true) || 3;
var COMMAND = (0, core_1.getInput)('command', { required: true }); var COMMAND = core_1.getInput('command', { required: true });
var RETRY_WAIT_SECONDS = getInputNumber('retry_wait_seconds', false) || 10; var RETRY_WAIT_SECONDS = getInputNumber('retry_wait_seconds', false) || 10;
var SHELL = (0, core_1.getInput)('shell'); var SHELL = core_1.getInput('shell');
var POLLING_INTERVAL_SECONDS = getInputNumber('polling_interval_seconds', false) || 1; var POLLING_INTERVAL_SECONDS = getInputNumber('polling_interval_seconds', false) || 1;
var RETRY_ON = (0, core_1.getInput)('retry_on') || 'any'; var RETRY_ON = core_1.getInput('retry_on') || 'any';
var WARNING_ON_RETRY = (0, core_1.getInput)('warning_on_retry').toLowerCase() === 'true'; var WARNING_ON_RETRY = core_1.getInput('warning_on_retry').toLowerCase() === 'true';
var ON_RETRY_COMMAND = (0, core_1.getInput)('on_retry_command'); var ON_RETRY_COMMAND = core_1.getInput('on_retry_command');
var CONTINUE_ON_ERROR = getInputBoolean('continue_on_error'); var CONTINUE_ON_ERROR = getInputBoolean('continue_on_error');
var NEW_COMMAND_ON_RETRY = (0, core_1.getInput)('new_command_on_retry'); var NEW_COMMAND_ON_RETRY = core_1.getInput('new_command_on_retry');
var RETRY_ON_EXIT_CODE = getInputNumber('retry_on_exit_code', false); var RETRY_ON_EXIT_CODE = getInputNumber('retry_on_exit_code', false);
var OS = process.platform; var OS = process.platform;
var OUTPUT_TOTAL_ATTEMPTS_KEY = 'total_attempts'; var OUTPUT_TOTAL_ATTEMPTS_KEY = 'total_attempts';
@@ -652,21 +652,21 @@ var OUTPUT_EXIT_ERROR_KEY = 'exit_error';
var exit; var exit;
var done; var done;
function getInputNumber(id, required) { function getInputNumber(id, required) {
var input = (0, core_1.getInput)(id, { required: required }); var input = core_1.getInput(id, { required: required });
var num = Number.parseInt(input); var num = Number.parseInt(input);
// empty is ok // empty is ok
if (!input && !required) { if (!input && !required) {
return; return;
} }
if (!Number.isInteger(num)) { if (!Number.isInteger(num)) {
throw "Input ".concat(id, " only accepts numbers. Received ").concat(input); throw "Input " + id + " only accepts numbers. Received " + input;
} }
return num; return num;
} }
function getInputBoolean(id) { function getInputBoolean(id) {
var input = (0, core_1.getInput)(id); var input = core_1.getInput(id);
if (!['true', 'false'].includes(input.toLowerCase())) { if (!['true', 'false'].includes(input.toLowerCase())) {
throw "Input ".concat(id, " only accepts boolean values. Received ").concat(input); throw "Input " + id + " only accepts boolean values. Received " + input;
} }
return input.toLowerCase() === 'true'; return input.toLowerCase() === 'true';
} }
@@ -677,11 +677,11 @@ function retryWait() {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
waitStart = Date.now(); waitStart = Date.now();
return [4 /*yield*/, (0, util_1.wait)(milliseconds_1.default.seconds(RETRY_WAIT_SECONDS))]; return [4 /*yield*/, util_1.wait(milliseconds_1.default.seconds(RETRY_WAIT_SECONDS))];
case 1: case 1:
_a.sent(); _a.sent();
(0, core_1.debug)("Waited ".concat(Date.now() - waitStart, "ms")); core_1.debug("Waited " + (Date.now() - waitStart) + "ms");
(0, core_1.debug)("Configured wait: ".concat(milliseconds_1.default.seconds(RETRY_WAIT_SECONDS), "ms")); core_1.debug("Configured wait: " + milliseconds_1.default.seconds(RETRY_WAIT_SECONDS) + "ms");
return [2 /*return*/]; return [2 /*return*/];
} }
}); });
@@ -708,33 +708,37 @@ function getTimeout() {
} }
function getExecutable() { function getExecutable() {
if (!SHELL) { if (!SHELL) {
return OS === 'win32' ? 'powershell' : 'bash'; return OS === 'win32' ? 'powershell' : 'bash -e';
} }
var executable; var executable;
switch (SHELL) { switch (SHELL) {
case 'bash': case "bash": {
case 'python': // -e to not ignore errors, but exit with non-zero code.
case 'pwsh': { executable = "bash -e";
break;
}
case "python":
case "pwsh": {
executable = SHELL; executable = SHELL;
break; break;
} }
case 'sh': { case "sh": {
if (OS === 'win32') { if (OS === 'win32') {
throw new Error("Shell ".concat(SHELL, " not allowed on OS ").concat(OS)); throw new Error("Shell " + SHELL + " not allowed on OS " + OS);
} }
executable = SHELL; executable = SHELL;
break; break;
} }
case 'cmd': case "cmd":
case 'powershell': { case "powershell": {
if (OS !== 'win32') { if (OS !== 'win32') {
throw new Error("Shell ".concat(SHELL, " not allowed on OS ").concat(OS)); throw new Error("Shell " + SHELL + " not allowed on OS " + OS);
} }
executable = SHELL + '.exe'; executable = SHELL + ".exe";
break; break;
} }
default: { default: {
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")); 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;
@@ -752,13 +756,13 @@ function runRetryCmd() {
_a.label = 1; _a.label = 1;
case 1: case 1:
_a.trys.push([1, 3, , 4]); _a.trys.push([1, 3, , 4]);
return [4 /*yield*/, (0, child_process_1.execSync)(ON_RETRY_COMMAND, { stdio: 'inherit' })]; return [4 /*yield*/, child_process_1.execSync(ON_RETRY_COMMAND, { stdio: 'inherit' })];
case 2: case 2:
_a.sent(); _a.sent();
return [3 /*break*/, 4]; return [3 /*break*/, 4];
case 3: case 3:
error_1 = _a.sent(); error_1 = _a.sent();
(0, core_1.info)("WARNING: Retry command threw the error ".concat(error_1.message)); core_1.info("WARNING: Retry command threw the error " + error_1.message);
return [3 /*break*/, 4]; return [3 /*break*/, 4];
case 4: return [2 /*return*/]; case 4: return [2 /*return*/];
} }
@@ -776,10 +780,10 @@ function runCmd(attempt) {
executable = getExecutable(); executable = getExecutable();
exit = 0; exit = 0;
done = false; done = false;
(0, core_1.debug)("Running command ".concat(COMMAND, " on ").concat(OS, " using shell ").concat(executable)); core_1.debug("Running command " + COMMAND + " on " + OS + " using shell \"" + executable + "\"");
child = attempt > 1 && NEW_COMMAND_ON_RETRY child = attempt > 1 && NEW_COMMAND_ON_RETRY
? (0, child_process_1.spawn)(NEW_COMMAND_ON_RETRY, { shell: executable }) ? child_process_1.exec(NEW_COMMAND_ON_RETRY, { 'shell': executable })
: (0, child_process_1.spawn)(COMMAND, { shell: executable }); : child_process_1.exec(COMMAND, { 'shell': executable });
(_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', function (data) { (_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', function (data) {
process.stdout.write(data); process.stdout.write(data);
}); });
@@ -787,8 +791,8 @@ function runCmd(attempt) {
process.stdout.write(data); process.stdout.write(data);
}); });
child.on('exit', function (code, signal) { child.on('exit', function (code, signal) {
(0, core_1.debug)("Code: ".concat(code)); core_1.debug("Code: " + code);
(0, core_1.debug)("Signal: ".concat(signal)); core_1.debug("Signal: " + signal);
if (code && code > 0) { if (code && code > 0) {
exit = code; exit = code;
} }
@@ -799,7 +803,7 @@ function runCmd(attempt) {
done = true; done = true;
}); });
_c.label = 1; _c.label = 1;
case 1: return [4 /*yield*/, (0, util_1.wait)(milliseconds_1.default.seconds(POLLING_INTERVAL_SECONDS))]; case 1: return [4 /*yield*/, util_1.wait(milliseconds_1.default.seconds(POLLING_INTERVAL_SECONDS))];
case 2: case 2:
_c.sent(); _c.sent();
_c.label = 3; _c.label = 3;
@@ -807,18 +811,18 @@ function runCmd(attempt) {
if (Date.now() < end_time && !done) return [3 /*break*/, 1]; if (Date.now() < end_time && !done) return [3 /*break*/, 1];
_c.label = 4; _c.label = 4;
case 4: case 4:
if (!(!done && child.pid)) return [3 /*break*/, 6]; if (!!done) return [3 /*break*/, 6];
(0, tree_kill_1.default)(child.pid); tree_kill_1.default(child.pid);
return [4 /*yield*/, retryWait()]; return [4 /*yield*/, retryWait()];
case 5: case 5:
_c.sent(); _c.sent();
throw new Error("Timeout of ".concat(getTimeout(), "ms hit")); throw new Error("Timeout of " + getTimeout() + "ms hit");
case 6: case 6:
if (!(exit > 0)) return [3 /*break*/, 8]; if (!(exit > 0)) return [3 /*break*/, 8];
return [4 /*yield*/, retryWait()]; return [4 /*yield*/, retryWait()];
case 7: case 7:
_c.sent(); _c.sent();
throw new Error("Child_process exited with error code ".concat(exit)); throw new Error("Child_process exited with error code " + exit);
case 8: return [2 /*return*/]; case 8: return [2 /*return*/];
} }
}); });
@@ -840,16 +844,16 @@ function runAction() {
case 3: case 3:
_a.trys.push([3, 5, , 12]); _a.trys.push([3, 5, , 12]);
// just keep overwriting attempts output // just keep overwriting attempts output
(0, core_1.setOutput)(OUTPUT_TOTAL_ATTEMPTS_KEY, attempt); core_1.setOutput(OUTPUT_TOTAL_ATTEMPTS_KEY, attempt);
return [4 /*yield*/, runCmd(attempt)]; return [4 /*yield*/, runCmd(attempt)];
case 4: case 4:
_a.sent(); _a.sent();
(0, core_1.info)("Command completed after ".concat(attempt, " attempt(s).")); core_1.info("Command completed after " + attempt + " attempt(s).");
return [3 /*break*/, 13]; return [3 /*break*/, 13];
case 5: case 5:
error_2 = _a.sent(); error_2 = _a.sent();
if (!(attempt === MAX_ATTEMPTS)) return [3 /*break*/, 6]; if (!(attempt === MAX_ATTEMPTS)) return [3 /*break*/, 6];
throw new Error("Final attempt failed. ".concat(error_2.message)); throw new Error("Final attempt failed. " + error_2.message);
case 6: case 6:
if (!(!done && RETRY_ON === 'error')) return [3 /*break*/, 7]; if (!(!done && RETRY_ON === 'error')) return [3 /*break*/, 7];
// error: timeout // error: timeout
@@ -865,10 +869,10 @@ function runAction() {
case 10: case 10:
_a.sent(); _a.sent();
if (WARNING_ON_RETRY) { if (WARNING_ON_RETRY) {
(0, core_1.warning)("Attempt ".concat(attempt, " failed. Reason: ").concat(error_2.message)); core_1.warning("Attempt " + attempt + " failed. Reason: " + error_2.message);
} }
else { else {
(0, core_1.info)("Attempt ".concat(attempt, " failed. Reason: ").concat(error_2.message)); core_1.info("Attempt " + attempt + " failed. Reason: " + error_2.message);
} }
_a.label = 11; _a.label = 11;
case 11: return [3 /*break*/, 12]; case 11: return [3 /*break*/, 12];
@@ -882,21 +886,21 @@ function runAction() {
} }
runAction() runAction()
.then(function () { .then(function () {
(0, core_1.setOutput)(OUTPUT_EXIT_CODE_KEY, 0); core_1.setOutput(OUTPUT_EXIT_CODE_KEY, 0);
process.exit(0); // success process.exit(0); // success
}) })
.catch(function (err) { .catch(function (err) {
// exact error code if available, otherwise just 1 // exact error code if available, otherwise just 1
var exitCode = exit > 0 ? exit : 1; var exitCode = exit > 0 ? exit : 1;
if (CONTINUE_ON_ERROR) { if (CONTINUE_ON_ERROR) {
(0, core_1.warning)(err.message); core_1.warning(err.message);
} }
else { else {
(0, core_1.error)(err.message); core_1.error(err.message);
} }
// these can be helpful to know if continue-on-error is true // these can be helpful to know if continue-on-error is true
(0, core_1.setOutput)(OUTPUT_EXIT_ERROR_KEY, err.message); core_1.setOutput(OUTPUT_EXIT_ERROR_KEY, err.message);
(0, core_1.setOutput)(OUTPUT_EXIT_CODE_KEY, exitCode); core_1.setOutput(OUTPUT_EXIT_CODE_KEY, exitCode);
// if continue_on_error, exit with exact error code else exit gracefully // if continue_on_error, exit with exact error code else exit gracefully
// mimics native continue-on-error that is not supported in composite actions // mimics native continue-on-error that is not supported in composite actions
process.exit(CONTINUE_ON_ERROR ? 0 : exitCode); process.exit(CONTINUE_ON_ERROR ? 0 : exitCode);
@@ -1956,13 +1960,6 @@ Object.defineProperty(exports, "summary", { enumerable: true, get: function () {
*/ */
var summary_2 = __webpack_require__(665); var summary_2 = __webpack_require__(665);
Object.defineProperty(exports, "markdownSummary", { enumerable: true, get: function () { return summary_2.markdownSummary; } }); 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 //# sourceMappingURL=core.js.map
/***/ }), /***/ }),
@@ -2055,71 +2052,6 @@ 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: /***/ 605:
/***/ (function(module) { /***/ (function(module) {

10522
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,13 +3,8 @@
"version": "0.0.0-managed-by-semantic-release", "version": "0.0.0-managed-by-semantic-release",
"description": "Retries a GitHub Action step on failure or timeout.", "description": "Retries a GitHub Action step on failure or timeout.",
"scripts": { "scripts": {
"lint:base": "eslint --config ./.config/.eslintrc.js ",
"lint": "npm run lint:base -- .",
"local": "npm run prepare && node -r dotenv/config ./dist/index.js", "local": "npm run prepare && node -r dotenv/config ./dist/index.js",
"prepare": "ncc build src/index.ts && husky install", "prepare": "ncc build src/index.ts"
"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": { "repository": {
"type": "git", "type": "git",
@@ -23,7 +18,7 @@
}, },
"homepage": "https://github.com/nick-invision/retry#readme", "homepage": "https://github.com/nick-invision/retry#readme",
"dependencies": { "dependencies": {
"@actions/core": "^1.9.0", "@actions/core": "^1.8.2",
"milliseconds": "^1.0.3", "milliseconds": "^1.0.3",
"tree-kill": "^1.2.2" "tree-kill": "^1.2.2"
}, },
@@ -32,35 +27,19 @@
"@commitlint/config-conventional": "^16.2.1", "@commitlint/config-conventional": "^16.2.1",
"@semantic-release/changelog": "^6.0.1", "@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1", "@semantic-release/git": "^10.0.1",
"@types/jest": "^28.1.6",
"@types/milliseconds": "0.0.30", "@types/milliseconds": "0.0.30",
"@types/node": "^16.11.7", "@types/node": "14.14.7",
"@typescript-eslint/eslint-plugin": "^5.32.0",
"@typescript-eslint/parser": "^5.32.0",
"@zeit/ncc": "^0.20.5", "@zeit/ncc": "^0.20.5",
"dotenv": "8.2.0", "dotenv": "8.2.0",
"eslint": "^8.21.0", "husky": "^4.3.8",
"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", "semantic-release": "19.0.3",
"ts-jest": "^28.0.7",
"ts-node": "9.0.0", "ts-node": "9.0.0",
"typescript": "^4.7.4", "typescript": "4.0.5"
"yaml-lint": "^1.7.0"
}, },
"lint-staged": { "husky": {
"**/*.ts": [ "hooks": {
"npm run style:base --", "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"npm run lint:base --" "pre-commit": "npm run prepare && git add ."
], }
"**/*.{md,yaml,yml}": [
"npm run style:base --"
],
"**/*.{yaml,yml}": [
"npx yamllint "
]
} }
} }

View File

@@ -1,11 +1,7 @@
# these are the bare minimum envvars required
INPUT_TIMEOUT_MINUTES=1 INPUT_TIMEOUT_MINUTES=1
INPUT_MAX_ATTEMPTS=3 INPUT_MAX_ATTEMPTS=3
INPUT_COMMAND="node -e 'process.exit(99)'" INPUT_COMMAND="node -e 'process.exit(99)'"
INPUT_CONTINUE_ON_ERROR=false INPUT_RETRY_WAIT_SECONDS=10
SHELL=pwsh
# these are optional INPUT_POLLING_INTERVAL_SECONDS=1
#INPUT_RETRY_WAIT_SECONDS=10 INPUT_RETRY_ON=any
#SHELL=pwsh
#INPUT_POLLING_INTERVAL_SECONDS=1
#INPUT_RETRY_ON=any

View File

@@ -1,5 +1,5 @@
import { getInput, error, warning, info, debug, setOutput } from '@actions/core'; import { getInput, error, warning, info, debug, setOutput } from '@actions/core';
import { execSync, spawn } from 'child_process'; import { exec, execSync } from 'child_process';
import ms from 'milliseconds'; import ms from 'milliseconds';
import kill from 'tree-kill'; 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_CODE_KEY = 'exit_code';
const OUTPUT_EXIT_ERROR_KEY = 'exit_error'; const OUTPUT_EXIT_ERROR_KEY = 'exit_error';
let exit: number; var exit: number;
let done: boolean; var done: boolean;
function getInputNumber(id: string, required: boolean): number | undefined { function getInputNumber(id: string, required: boolean): number | undefined {
const input = getInput(id, { required }); const input = getInput(id, { required });
@@ -44,13 +44,13 @@ function getInputNumber(id: string, required: boolean): number | undefined {
return num; return num;
} }
function getInputBoolean(id: string): boolean { function getInputBoolean(id: string): Boolean {
const input = getInput(id); 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}`; throw `Input ${id} only accepts boolean values. Received ${input}`;
} }
return input.toLowerCase() === 'true'; return input.toLowerCase() === 'true'
} }
async function retryWait() { async function retryWait() {
@@ -78,39 +78,41 @@ function getTimeout(): number {
function getExecutable(): string { function getExecutable(): string {
if (!SHELL) { if (!SHELL) {
return OS === 'win32' ? 'powershell' : 'bash'; return OS === 'win32' ? 'powershell' : 'bash -e';
} }
let executable: string; let executable: string;
switch (SHELL) { switch (SHELL) {
case 'bash': case "bash": {
case 'python': // -e to not ignore errors, but exit with non-zero code.
case 'pwsh': { executable = "bash -e";
break;
}
case "python":
case "pwsh": {
executable = SHELL; executable = SHELL;
break; break;
} }
case 'sh': { case "sh": {
if (OS === 'win32') { if (OS === 'win32') {
throw new Error(`Shell ${SHELL} not allowed on OS ${OS}`); throw new Error(`Shell ${SHELL} not allowed on OS ${OS}`);
} }
executable = SHELL; executable = SHELL;
break; break;
} }
case 'cmd': case "cmd":
case 'powershell': { case "powershell": {
if (OS !== 'win32') { if (OS !== 'win32') {
throw new Error(`Shell ${SHELL} not allowed on OS ${OS}`); throw new Error(`Shell ${SHELL} not allowed on OS ${OS}`);
} }
executable = SHELL + '.exe'; executable = SHELL + ".exe";
break; break;
} }
default: { default: {
throw new Error( 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`);
`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> { async function runRetryCmd(): Promise<void> {
@@ -121,9 +123,8 @@ async function runRetryCmd(): Promise<void> {
try { try {
await execSync(ON_RETRY_COMMAND, { stdio: 'inherit' }); await execSync(ON_RETRY_COMMAND, { stdio: 'inherit' });
// eslint-disable-next-line } catch (error) {
} catch (error: any) { info(`WARNING: Retry command threw the error ${error.message}`)
info(`WARNING: Retry command threw the error ${error.message}`);
} }
} }
@@ -134,11 +135,10 @@ async function runCmd(attempt: number) {
exit = 0; exit = 0;
done = false; done = false;
debug(`Running command ${COMMAND} on ${OS} using shell ${executable}`); debug(`Running command ${COMMAND} on ${OS} using shell "${executable}"`)
const child = var child = attempt > 1 && NEW_COMMAND_ON_RETRY
attempt > 1 && NEW_COMMAND_ON_RETRY ? exec(NEW_COMMAND_ON_RETRY, { 'shell': executable })
? spawn(NEW_COMMAND_ON_RETRY, { shell: executable }) : exec(COMMAND, { 'shell': executable });
: spawn(COMMAND, { shell: executable });
child.stdout?.on('data', (data) => { child.stdout?.on('data', (data) => {
process.stdout.write(data); process.stdout.write(data);
@@ -164,7 +164,7 @@ async function runCmd(attempt: number) {
await wait(ms.seconds(POLLING_INTERVAL_SECONDS)); await wait(ms.seconds(POLLING_INTERVAL_SECONDS));
} while (Date.now() < end_time && !done); } while (Date.now() < end_time && !done);
if (!done && child.pid) { if (!done) {
kill(child.pid); kill(child.pid);
await retryWait(); await retryWait();
throw new Error(`Timeout of ${getTimeout()}ms hit`); throw new Error(`Timeout of ${getTimeout()}ms hit`);
@@ -186,14 +186,13 @@ async function runAction() {
await runCmd(attempt); await runCmd(attempt);
info(`Command completed after ${attempt} attempt(s).`); info(`Command completed after ${attempt} attempt(s).`);
break; break;
// eslint-disable-next-line } catch (error) {
} catch (error: any) {
if (attempt === MAX_ATTEMPTS) { if (attempt === MAX_ATTEMPTS) {
throw new Error(`Final attempt failed. ${error.message}`); throw new Error(`Final attempt failed. ${error.message}`);
} else if (!done && RETRY_ON === 'error') { } else if (!done && RETRY_ON === 'error') {
// error: timeout // error: timeout
throw error; 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; throw error;
} else if (exit > 0 && RETRY_ON === 'timeout') { } else if (exit > 0 && RETRY_ON === 'timeout') {
// error: error // error: error

View File

@@ -1,17 +0,0 @@
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);
});
});

View File

@@ -1,13 +0,0 @@
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-%

View File

@@ -1,13 +0,0 @@
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