Compare commits

..

3 Commits

Author SHA1 Message Date
Snyk bot
0f986c438b [Snyk] Upgrade @actions/core from 1.8.2 to 1.9.0 (#81)
* fix: upgrade @actions/core from 1.8.2 to 1.9.0

Snyk has created this PR to upgrade @actions/core from 1.8.2 to 1.9.0.

See this package in npm:
https://www.npmjs.com/package/@actions/core

See this project in Snyk:
https://app.snyk.io/org/nick-invision/project/b960b937-66a3-4aae-9cb2-321f49c8750b?utm_source=github&utm_medium=referral&page=upgrade-pr

* patch: regenerate dist

Co-authored-by: Nick Fields <46869826+nick-fields@users.noreply.github.com>
2022-08-03 03:15:43 +00:00
Nick Fields
3dad7de805 Setup prettier and eslint and run pre-commit (#86)
* patch: setup prettier

* patch: move .commitlintrc.js to .config

* patch: config lint-staged and update husky

* patch: configure eslint as well
2022-08-03 02:47:32 +00:00
Nick Fields
14b6b46d04 patch: update typescript to latest (#85) 2022-08-03 01:55:30 +00:00
17 changed files with 2840 additions and 619 deletions

1
.config/.eslintignore Normal file
View File

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

7
.config/.eslintrc.js Normal file
View 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
View File

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

5
.config/.prettierrc.yml Normal file
View File

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

View File

@@ -4,7 +4,6 @@ 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,114 +313,6 @@ 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')

5
.husky/commit-msg Executable file
View 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
View 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 .

2
.nvmrc
View File

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

View File

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

3
.vscode/extensions.json vendored Normal file
View File

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

View File

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

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 = 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 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 POLLING_INTERVAL_SECONDS = getInputNumber('polling_interval_seconds', false) || 1;
var RETRY_ON = core_1.getInput('retry_on') || 'any'; var RETRY_ON = (0, core_1.getInput)('retry_on') || 'any';
var WARNING_ON_RETRY = core_1.getInput('warning_on_retry').toLowerCase() === 'true'; var WARNING_ON_RETRY = (0, core_1.getInput)('warning_on_retry').toLowerCase() === 'true';
var ON_RETRY_COMMAND = core_1.getInput('on_retry_command'); var ON_RETRY_COMMAND = (0, 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 = 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 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 = core_1.getInput(id, { required: required }); var input = (0, 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 " + id + " only accepts numbers. Received " + input; throw "Input ".concat(id, " only accepts numbers. Received ").concat(input);
} }
return num; return num;
} }
function getInputBoolean(id) { function getInputBoolean(id) {
var input = core_1.getInput(id); var input = (0, core_1.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 ".concat(id, " only accepts boolean values. Received ").concat(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*/, 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: case 1:
_a.sent(); _a.sent();
core_1.debug("Waited " + (Date.now() - waitStart) + "ms"); (0, core_1.debug)("Waited ".concat(Date.now() - waitStart, "ms"));
core_1.debug("Configured wait: " + milliseconds_1.default.seconds(RETRY_WAIT_SECONDS) + "ms"); (0, core_1.debug)("Configured wait: ".concat(milliseconds_1.default.seconds(RETRY_WAIT_SECONDS), "ms"));
return [2 /*return*/]; return [2 /*return*/];
} }
}); });
@@ -708,37 +708,33 @@ function getTimeout() {
} }
function getExecutable() { function getExecutable() {
if (!SHELL) { if (!SHELL) {
return OS === 'win32' ? 'powershell' : 'bash -e'; return OS === 'win32' ? 'powershell' : 'bash';
} }
var executable; var executable;
switch (SHELL) { switch (SHELL) {
case "bash": { case 'bash':
// -e to not ignore errors, but exit with non-zero code. case 'python':
executable = "bash -e"; case 'pwsh': {
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 ".concat(SHELL, " not allowed on OS ").concat(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 ".concat(SHELL, " not allowed on OS ").concat(OS));
} }
executable = SHELL + ".exe"; executable = SHELL + '.exe';
break; break;
} }
default: { 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; return executable;
@@ -756,13 +752,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*/, child_process_1.execSync(ON_RETRY_COMMAND, { stdio: 'inherit' })]; return [4 /*yield*/, (0, 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();
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]; return [3 /*break*/, 4];
case 4: return [2 /*return*/]; case 4: return [2 /*return*/];
} }
@@ -780,10 +776,10 @@ function runCmd(attempt) {
executable = getExecutable(); executable = getExecutable();
exit = 0; exit = 0;
done = false; 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 = attempt > 1 && NEW_COMMAND_ON_RETRY
? child_process_1.exec(NEW_COMMAND_ON_RETRY, { 'shell': executable }) ? (0, child_process_1.exec)(NEW_COMMAND_ON_RETRY, { shell: executable })
: child_process_1.exec(COMMAND, { 'shell': executable }); : (0, 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);
}); });
@@ -791,8 +787,8 @@ function runCmd(attempt) {
process.stdout.write(data); process.stdout.write(data);
}); });
child.on('exit', function (code, signal) { child.on('exit', function (code, signal) {
core_1.debug("Code: " + code); (0, core_1.debug)("Code: ".concat(code));
core_1.debug("Signal: " + signal); (0, core_1.debug)("Signal: ".concat(signal));
if (code && code > 0) { if (code && code > 0) {
exit = code; exit = code;
} }
@@ -803,7 +799,7 @@ function runCmd(attempt) {
done = true; done = true;
}); });
_c.label = 1; _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: case 2:
_c.sent(); _c.sent();
_c.label = 3; _c.label = 3;
@@ -811,18 +807,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) return [3 /*break*/, 6]; if (!(!done && child.pid)) return [3 /*break*/, 6];
tree_kill_1.default(child.pid); (0, 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 " + getTimeout() + "ms hit"); throw new Error("Timeout of ".concat(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 " + exit); throw new Error("Child_process exited with error code ".concat(exit));
case 8: return [2 /*return*/]; case 8: return [2 /*return*/];
} }
}); });
@@ -844,16 +840,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
core_1.setOutput(OUTPUT_TOTAL_ATTEMPTS_KEY, attempt); (0, 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();
core_1.info("Command completed after " + attempt + " attempt(s)."); (0, core_1.info)("Command completed after ".concat(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. " + error_2.message); throw new Error("Final attempt failed. ".concat(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
@@ -869,10 +865,10 @@ function runAction() {
case 10: case 10:
_a.sent(); _a.sent();
if (WARNING_ON_RETRY) { 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 { 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; _a.label = 11;
case 11: return [3 /*break*/, 12]; case 11: return [3 /*break*/, 12];
@@ -886,21 +882,21 @@ function runAction() {
} }
runAction() runAction()
.then(function () { .then(function () {
core_1.setOutput(OUTPUT_EXIT_CODE_KEY, 0); (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) {
core_1.warning(err.message); (0, core_1.warning)(err.message);
} }
else { else {
core_1.error(err.message); (0, 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
core_1.setOutput(OUTPUT_EXIT_ERROR_KEY, err.message); (0, core_1.setOutput)(OUTPUT_EXIT_ERROR_KEY, err.message);
core_1.setOutput(OUTPUT_EXIT_CODE_KEY, exitCode); (0, 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);
@@ -1960,6 +1956,13 @@ 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
/***/ }), /***/ }),
@@ -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: /***/ 605:
/***/ (function(module) { /***/ (function(module) {

3045
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,8 +3,12 @@
"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" "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 -- ."
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -18,7 +22,7 @@
}, },
"homepage": "https://github.com/nick-invision/retry#readme", "homepage": "https://github.com/nick-invision/retry#readme",
"dependencies": { "dependencies": {
"@actions/core": "^1.8.2", "@actions/core": "^1.9.0",
"milliseconds": "^1.0.3", "milliseconds": "^1.0.3",
"tree-kill": "^1.2.2" "tree-kill": "^1.2.2"
}, },
@@ -28,18 +32,27 @@
"@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": "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", "@zeit/ncc": "^0.20.5",
"dotenv": "8.2.0", "dotenv": "8.2.0",
"husky": "^4.3.8", "eslint": "^8.21.0",
"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.0.5" "typescript": "^4.7.4"
}, },
"husky": { "lint-staged": {
"hooks": { "**/*.ts": [
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS", "npm run style:base --",
"pre-commit": "npm run prepare && git add ." "npm run lint:base --"
} ],
"**/*.{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';
var exit: number; let exit: number;
var done: boolean; let 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,41 +78,39 @@ function getTimeout(): number {
function getExecutable(): string { function getExecutable(): string {
if (!SHELL) { if (!SHELL) {
return OS === 'win32' ? 'powershell' : 'bash -e'; return OS === 'win32' ? 'powershell' : 'bash';
} }
let executable: string; let executable: string;
switch (SHELL) { switch (SHELL) {
case "bash": { case 'bash':
// -e to not ignore errors, but exit with non-zero code. case 'python':
executable = "bash -e"; case 'pwsh': {
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(`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> { async function runRetryCmd(): Promise<void> {
@@ -123,8 +121,9 @@ async function runRetryCmd(): Promise<void> {
try { try {
await execSync(ON_RETRY_COMMAND, { stdio: 'inherit' }); await execSync(ON_RETRY_COMMAND, { stdio: 'inherit' });
} catch (error) { // eslint-disable-next-line
info(`WARNING: Retry command threw the error ${error.message}`) } catch (error: any) {
info(`WARNING: Retry command threw the error ${error.message}`);
} }
} }
@@ -135,10 +134,11 @@ 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}`);
var child = attempt > 1 && NEW_COMMAND_ON_RETRY const child =
? exec(NEW_COMMAND_ON_RETRY, { 'shell': executable }) attempt > 1 && NEW_COMMAND_ON_RETRY
: exec(COMMAND, { 'shell': executable }); ? exec(NEW_COMMAND_ON_RETRY, { 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) { if (!done && child.pid) {
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,13 +186,14 @@ 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;
} catch (error) { // eslint-disable-next-line
} 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