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
17 changed files with 619 additions and 2840 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

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

View File

@@ -313,6 +313,114 @@ jobs:
expected: failure expected: failure
actual: ${{ steps.wrong_shell.outcome }} 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')

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.exec)(NEW_COMMAND_ON_RETRY, { shell: executable }) ? child_process_1.exec(NEW_COMMAND_ON_RETRY, { 'shell': executable })
: (0, child_process_1.exec)(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) {

3041
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,12 +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 -- ."
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -22,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,27 +28,18 @@
"@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/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",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"semantic-release": "19.0.3", "semantic-release": "19.0.3",
"ts-node": "9.0.0", "ts-node": "9.0.0",
"typescript": "^4.7.4" "typescript": "4.0.5"
}, },
"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 --"
]
} }
} }

View File

@@ -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 })
? exec(NEW_COMMAND_ON_RETRY, { shell: executable }) : exec(COMMAND, { 'shell': executable });
: exec(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