mirror of
https://github.com/nick-fields/retry.git
synced 2026-02-09 22:58:02 +00:00
fix: dont require OS input and use correct shell per os
This commit is contained in:
36
.github/workflows/ci_cd.yml
vendored
36
.github/workflows/ci_cd.yml
vendored
@@ -197,7 +197,7 @@ jobs:
|
|||||||
expected: failure
|
expected: failure
|
||||||
actual: ${{ steps.sad_path_timeout.outcome }}
|
actual: ${{ steps.sad_path_timeout.outcome }}
|
||||||
|
|
||||||
- name: sad-path (wrong shell)
|
- name: sad-path (wrong shell for OS)
|
||||||
id: wrong_shell
|
id: wrong_shell
|
||||||
uses: ./
|
uses: ./
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
@@ -215,6 +215,40 @@ jobs:
|
|||||||
expected: failure
|
expected: failure
|
||||||
actual: ${{ steps.wrong_shell.outcome }}
|
actual: ${{ steps.wrong_shell.outcome }}
|
||||||
|
|
||||||
|
ci_windows:
|
||||||
|
name: Run Windows Tests
|
||||||
|
if: startsWith(github.ref, 'refs/heads')
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 12
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Powershell test
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
timeout_minutes: 1
|
||||||
|
max_attempts: 2
|
||||||
|
shell: powershell
|
||||||
|
command: Get-ComputerInfo
|
||||||
|
- name: CMD.exe test
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
timeout_minutes: 1
|
||||||
|
max_attempts: 2
|
||||||
|
shell: cmd
|
||||||
|
command: echo %PATH%
|
||||||
|
- name: Python test
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
timeout_minutes: 1
|
||||||
|
max_attempts: 2
|
||||||
|
shell: python
|
||||||
|
command: print 1, 2, 3
|
||||||
|
|
||||||
# runs on push to master only
|
# runs on push to master only
|
||||||
cd:
|
cd:
|
||||||
|
|||||||
@@ -20,10 +20,6 @@ Retries an Action step on failure or timeout. This is currently intended to repl
|
|||||||
|
|
||||||
**Required** The command to run
|
**Required** The command to run
|
||||||
|
|
||||||
### `OS`
|
|
||||||
|
|
||||||
**Required** The OS passed from the runner (runner.OS)
|
|
||||||
|
|
||||||
### `retry_wait_seconds`
|
### `retry_wait_seconds`
|
||||||
|
|
||||||
**Optional** Number of seconds to wait before attempting the next retry. Defaults to `10`
|
**Optional** Number of seconds to wait before attempting the next retry. Defaults to `10`
|
||||||
@@ -69,7 +65,6 @@ uses: nick-invision/retry@v2
|
|||||||
with:
|
with:
|
||||||
timeout_minutes: 10
|
timeout_minutes: 10
|
||||||
max_attempts: 3
|
max_attempts: 3
|
||||||
os: ${{ runner.os }}
|
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
command: dir
|
command: dir
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -18,13 +18,9 @@ inputs:
|
|||||||
description: Number of seconds to wait before attempting the next retry
|
description: Number of seconds to wait before attempting the next retry
|
||||||
required: false
|
required: false
|
||||||
default: 10
|
default: 10
|
||||||
OS:
|
|
||||||
description: OS Passed from Runner (runner.OS)
|
|
||||||
required: true
|
|
||||||
shell:
|
shell:
|
||||||
description: Shell to Use to retry (Default is pwsh)
|
description: Shell to Use to retry (Default is pwsh)
|
||||||
required: false
|
required: false
|
||||||
default: pwsh
|
|
||||||
polling_interval_seconds:
|
polling_interval_seconds:
|
||||||
description: Number of seconds to wait for each check that command has completed running
|
description: Number of seconds to wait for each check that command has completed running
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
79
dist/index.js
vendored
79
dist/index.js
vendored
@@ -247,13 +247,13 @@ 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 OS = core_1.getInput('os', { required: true });
|
|
||||||
var COMMAND = 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 = core_1.getInput('shell') || 'pwsh';
|
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 = core_1.getInput('retry_on') || 'any';
|
var RETRY_ON = core_1.getInput('retry_on') || 'any';
|
||||||
var WARNING_ON_RETRY = core_1.getInput('warning_on_retry').toLowerCase() === 'true';
|
var WARNING_ON_RETRY = core_1.getInput('warning_on_retry').toLowerCase() === 'true';
|
||||||
|
var OS = process.platform;
|
||||||
var OUTPUT_TOTAL_ATTEMPTS_KEY = 'total_attempts';
|
var OUTPUT_TOTAL_ATTEMPTS_KEY = 'total_attempts';
|
||||||
var OUTPUT_EXIT_CODE_KEY = 'exit_code';
|
var OUTPUT_EXIT_CODE_KEY = 'exit_code';
|
||||||
var OUTPUT_EXIT_ERROR_KEY = 'exit_error';
|
var OUTPUT_EXIT_ERROR_KEY = 'exit_error';
|
||||||
@@ -307,6 +307,39 @@ function getTimeout() {
|
|||||||
}
|
}
|
||||||
throw new Error('Must specify either timeout_minutes or timeout_seconds inputs');
|
throw new Error('Must specify either timeout_minutes or timeout_seconds inputs');
|
||||||
}
|
}
|
||||||
|
function getExecutable() {
|
||||||
|
if (!SHELL) {
|
||||||
|
return OS === 'win32' ? 'powershell' : 'bash';
|
||||||
|
}
|
||||||
|
var executable;
|
||||||
|
switch (SHELL) {
|
||||||
|
case "bash":
|
||||||
|
case "python":
|
||||||
|
case "pwsh": {
|
||||||
|
executable = SHELL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "sh": {
|
||||||
|
if (OS === 'win32') {
|
||||||
|
throw new Error("Shell " + SHELL + " not allowed on OS " + OS);
|
||||||
|
}
|
||||||
|
executable = SHELL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "cmd":
|
||||||
|
case "powershell": {
|
||||||
|
if (OS !== 'win32') {
|
||||||
|
throw new Error("Shell " + SHELL + " not allowed on OS " + OS);
|
||||||
|
}
|
||||||
|
executable = SHELL + ".exe";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
throw new Error("Shell " + SHELL + " required");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return executable;
|
||||||
|
}
|
||||||
function runCmd() {
|
function runCmd() {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
@@ -315,48 +348,10 @@ function runCmd() {
|
|||||||
switch (_c.label) {
|
switch (_c.label) {
|
||||||
case 0:
|
case 0:
|
||||||
end_time = Date.now() + getTimeout();
|
end_time = Date.now() + getTimeout();
|
||||||
|
executable = getExecutable();
|
||||||
exit = 0;
|
exit = 0;
|
||||||
done = false;
|
done = false;
|
||||||
executable = SHELL + ".exe";
|
core_1.debug("Running command " + COMMAND + " on " + OS + " using shell " + executable);
|
||||||
switch (SHELL) {
|
|
||||||
case "pwsh": {
|
|
||||||
executable = SHELL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "bash": {
|
|
||||||
executable = SHELL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "python": {
|
|
||||||
executable = SHELL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "sh": {
|
|
||||||
if (OS === 'Windows') {
|
|
||||||
throw new Error("Shell " + SHELL + " not allowed on OS " + OS);
|
|
||||||
}
|
|
||||||
executable = SHELL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "cmd": {
|
|
||||||
if (OS !== 'Windows') {
|
|
||||||
throw new Error("Shell " + SHELL + " not allowed on OS " + OS);
|
|
||||||
}
|
|
||||||
executable = SHELL + ".exe";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "powershell": {
|
|
||||||
if (OS !== 'Windows') {
|
|
||||||
throw new Error("Shell " + SHELL + " not allowed on OS " + OS);
|
|
||||||
}
|
|
||||||
executable = SHELL + ".exe";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
throw new Error("Shell " + SHELL + " required");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
child = child_process_1.exec(COMMAND, { 'shell': executable });
|
child = 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);
|
||||||
|
|||||||
@@ -3,6 +3,5 @@ INPUT_MAX_ATTEMPTS=3
|
|||||||
INPUT_COMMAND="node -e 'process.exit(99)'"
|
INPUT_COMMAND="node -e 'process.exit(99)'"
|
||||||
INPUT_RETRY_WAIT_SECONDS=10
|
INPUT_RETRY_WAIT_SECONDS=10
|
||||||
SHELL=pwsh
|
SHELL=pwsh
|
||||||
OS=Linux
|
|
||||||
INPUT_POLLING_INTERVAL_SECONDS=1
|
INPUT_POLLING_INTERVAL_SECONDS=1
|
||||||
INPUT_RETRY_ON=any
|
INPUT_RETRY_ON=any
|
||||||
|
|||||||
47
src/index.ts
47
src/index.ts
@@ -9,14 +9,14 @@ import { wait } from './util';
|
|||||||
const TIMEOUT_MINUTES = getInputNumber('timeout_minutes', false);
|
const TIMEOUT_MINUTES = getInputNumber('timeout_minutes', false);
|
||||||
const TIMEOUT_SECONDS = getInputNumber('timeout_seconds', false);
|
const TIMEOUT_SECONDS = getInputNumber('timeout_seconds', false);
|
||||||
const MAX_ATTEMPTS = getInputNumber('max_attempts', true) || 3;
|
const MAX_ATTEMPTS = getInputNumber('max_attempts', true) || 3;
|
||||||
const OS = getInput('os', { required: true });
|
|
||||||
const COMMAND = getInput('command', { required: true });
|
const COMMAND = getInput('command', { required: true });
|
||||||
const RETRY_WAIT_SECONDS = getInputNumber('retry_wait_seconds', false) || 10;
|
const RETRY_WAIT_SECONDS = getInputNumber('retry_wait_seconds', false) || 10;
|
||||||
const SHELL = getInput('shell') || 'pwsh';
|
const SHELL = getInput('shell');
|
||||||
const POLLING_INTERVAL_SECONDS = getInputNumber('polling_interval_seconds', false) || 1;
|
const POLLING_INTERVAL_SECONDS = getInputNumber('polling_interval_seconds', false) || 1;
|
||||||
const RETRY_ON = getInput('retry_on') || 'any';
|
const RETRY_ON = getInput('retry_on') || 'any';
|
||||||
const WARNING_ON_RETRY = getInput('warning_on_retry').toLowerCase() === 'true';
|
const WARNING_ON_RETRY = getInput('warning_on_retry').toLowerCase() === 'true';
|
||||||
|
|
||||||
|
const OS = process.platform;
|
||||||
const OUTPUT_TOTAL_ATTEMPTS_KEY = 'total_attempts';
|
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';
|
||||||
@@ -63,42 +63,29 @@ function getTimeout(): number {
|
|||||||
throw new Error('Must specify either timeout_minutes or timeout_seconds inputs');
|
throw new Error('Must specify either timeout_minutes or timeout_seconds inputs');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runCmd() {
|
function getExecutable(): string {
|
||||||
const end_time = Date.now() + getTimeout();
|
if (!SHELL) {
|
||||||
|
return OS === 'win32' ? 'powershell' : 'bash';
|
||||||
|
}
|
||||||
|
|
||||||
exit = 0;
|
let executable: string;
|
||||||
done = false;
|
|
||||||
|
|
||||||
let executable: string = SHELL + ".exe";
|
|
||||||
switch (SHELL) {
|
switch (SHELL) {
|
||||||
|
case "bash":
|
||||||
|
case "python":
|
||||||
case "pwsh": {
|
case "pwsh": {
|
||||||
executable = SHELL;
|
executable = SHELL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "bash": {
|
|
||||||
executable = SHELL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "python": {
|
|
||||||
executable = SHELL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "sh": {
|
case "sh": {
|
||||||
if (OS === 'Windows') {
|
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":
|
||||||
if (OS !== 'Windows') {
|
|
||||||
throw new Error(`Shell ${SHELL} not allowed on OS ${OS}`);
|
|
||||||
}
|
|
||||||
executable = SHELL + ".exe";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "powershell": {
|
case "powershell": {
|
||||||
if (OS !== 'Windows') {
|
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";
|
||||||
@@ -106,11 +93,19 @@ async function runCmd() {
|
|||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
throw new Error(`Shell ${SHELL} required`);
|
throw new Error(`Shell ${SHELL} required`);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return executable
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runCmd() {
|
||||||
|
const end_time = Date.now() + getTimeout();
|
||||||
|
const executable = getExecutable();
|
||||||
|
|
||||||
|
exit = 0;
|
||||||
|
done = false;
|
||||||
|
|
||||||
|
debug(`Running command ${COMMAND} on ${OS} using shell ${executable}`)
|
||||||
var child = exec(COMMAND, { 'shell': executable });
|
var child = exec(COMMAND, { 'shell': executable });
|
||||||
|
|
||||||
child.stdout?.on('data', (data) => {
|
child.stdout?.on('data', (data) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user