Compare commits

..

3 Commits

Author SHA1 Message Date
Nick Fields
634988cced Merge branch 'master' into nrf/add-tests 2023-09-26 10:17:11 -04:00
Nick Fields
cc15f2ffff minor: forgot to set ctor props 2023-09-24 20:41:06 -04:00
Nick Fields
db9d6ef914 minor: throw custom err w/ code attached instead of relying on shared var 2023-09-24 11:31:32 -04:00
4 changed files with 56 additions and 23 deletions

42
dist/index.js vendored
View File

@@ -891,6 +891,21 @@ exports.retryWait = retryWait;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
@@ -941,8 +956,19 @@ var OS = process.platform;
var OUTPUT_TOTAL_ATTEMPTS_KEY = 'total_attempts';
var OUTPUT_EXIT_CODE_KEY = 'exit_code';
var OUTPUT_EXIT_ERROR_KEY = 'exit_error';
var exit;
var done;
var ErrorWithCode = /** @class */ (function (_super) {
__extends(ErrorWithCode, _super);
function ErrorWithCode(message, code) {
var _this = _super.call(this) || this;
_this.message = message;
_this.code = code;
_this.code = code;
_this.message = message;
return _this;
}
return ErrorWithCode;
}(Error));
function getExecutable(inputs) {
if (!inputs.shell) {
return OS === 'win32' ? 'powershell' : 'bash';
@@ -1006,7 +1032,7 @@ function runRetryCmd(inputs) {
function runCmd(attempt, inputs) {
var _a, _b;
return __awaiter(this, void 0, void 0, function () {
var end_time, executable, timeout, child;
var end_time, executable, exit, timeout, child;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
@@ -1056,13 +1082,13 @@ function runCmd(attempt, inputs) {
return [4 /*yield*/, (0, util_1.retryWait)(milliseconds_1.default.seconds(inputs.retry_wait_seconds))];
case 5:
_c.sent();
throw new Error("Timeout of ".concat((0, inputs_1.getTimeout)(inputs), "ms hit"));
throw new ErrorWithCode("Timeout of ".concat((0, inputs_1.getTimeout)(inputs), "ms hit"), exit);
case 6:
if (!(exit > 0)) return [3 /*break*/, 8];
return [4 /*yield*/, (0, util_1.retryWait)(milliseconds_1.default.seconds(inputs.retry_wait_seconds))];
case 7:
_c.sent();
throw new Error("Child_process exited with error code ".concat(exit));
throw new ErrorWithCode("Child_process exited with error code ".concat(exit), exit);
case 8: return [2 /*return*/];
}
});
@@ -1070,7 +1096,7 @@ function runCmd(attempt, inputs) {
}
function runAction(inputs) {
return __awaiter(this, void 0, void 0, function () {
var attempt, error_2;
var attempt, error_2, exit;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, inputs_1.validateInputs)(inputs)];
@@ -1092,8 +1118,9 @@ function runAction(inputs) {
return [3 /*break*/, 13];
case 5:
error_2 = _a.sent();
exit = error_2 instanceof ErrorWithCode ? error_2.code : 1;
if (!(attempt === inputs.max_attempts)) return [3 /*break*/, 6];
throw new Error("Final attempt failed. ".concat(error_2.message));
throw new ErrorWithCode("Final attempt failed. ".concat(error_2.message), exit);
case 6:
if (!(!done && inputs.retry_on === 'error')) return [3 /*break*/, 7];
// error: timeout
@@ -1131,8 +1158,7 @@ runAction(inputs)
process.exit(0); // success
})
.catch(function (err) {
// exact error code if available, otherwise just 1
var exitCode = exit > 0 ? exit : 1;
var exitCode = err instanceof ErrorWithCode ? err.code : 1;
if (inputs.continue_on_error) {
(0, core_1.warning)(err.message);
}

14
package-lock.json generated
View File

@@ -9,7 +9,7 @@
"version": "0.0.0-managed-by-semantic-release",
"license": "ISC",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/core": "^1.10.0",
"milliseconds": "^1.0.3",
"tree-kill": "^1.2.2"
},
@@ -39,9 +39,9 @@
}
},
"node_modules/@actions/core": {
"version": "1.10.1",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.1.tgz",
"integrity": "sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==",
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
"dependencies": {
"@actions/http-client": "^2.0.1",
"uuid": "^8.3.2"
@@ -13090,9 +13090,9 @@
},
"dependencies": {
"@actions/core": {
"version": "1.10.1",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.1.tgz",
"integrity": "sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==",
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
"requires": {
"@actions/http-client": "^2.0.1",
"uuid": "^8.3.2"

View File

@@ -23,7 +23,7 @@
},
"homepage": "https://github.com/nick-invision/retry#readme",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/core": "^1.10.0",
"milliseconds": "^1.0.3",
"tree-kill": "^1.2.2"
},

View File

@@ -11,9 +11,16 @@ const OUTPUT_TOTAL_ATTEMPTS_KEY = 'total_attempts';
const OUTPUT_EXIT_CODE_KEY = 'exit_code';
const OUTPUT_EXIT_ERROR_KEY = 'exit_error';
let exit: number;
let done: boolean;
class ErrorWithCode extends Error {
constructor(readonly message: string, readonly code: number) {
super();
this.code = code;
this.message = message;
}
}
function getExecutable(inputs: Inputs): string {
if (!inputs.shell) {
return OS === 'win32' ? 'powershell' : 'bash';
@@ -71,7 +78,7 @@ async function runCmd(attempt: number, inputs: Inputs) {
const end_time = Date.now() + getTimeout(inputs);
const executable = getExecutable(inputs);
exit = 0;
let exit = 0;
done = false;
let timeout = false;
@@ -117,10 +124,10 @@ async function runCmd(attempt: number, inputs: Inputs) {
timeout = true;
kill(child.pid);
await retryWait(ms.seconds(inputs.retry_wait_seconds));
throw new Error(`Timeout of ${getTimeout(inputs)}ms hit`);
throw new ErrorWithCode(`Timeout of ${getTimeout(inputs)}ms hit`, exit);
} else if (exit > 0) {
await retryWait(ms.seconds(inputs.retry_wait_seconds));
throw new Error(`Child_process exited with error code ${exit}`);
throw new ErrorWithCode(`Child_process exited with error code ${exit}`, exit);
} else {
return;
}
@@ -138,8 +145,9 @@ async function runAction(inputs: Inputs) {
break;
// eslint-disable-next-line
} catch (error: any) {
const exit = error instanceof ErrorWithCode ? error.code : 1;
if (attempt === inputs.max_attempts) {
throw new Error(`Final attempt failed. ${error.message}`);
throw new ErrorWithCode(`Final attempt failed. ${error.message}`, exit);
} else if (!done && inputs.retry_on === 'error') {
// error: timeout
throw error;
@@ -168,8 +176,7 @@ runAction(inputs)
process.exit(0); // success
})
.catch((err) => {
// exact error code if available, otherwise just 1
const exitCode = exit > 0 ? exit : 1;
const exitCode = err instanceof ErrorWithCode ? err.code : 1;
if (inputs.continue_on_error) {
warning(err.message);