mirror of
https://github.com/nick-fields/retry.git
synced 2026-02-10 23:25:28 +00:00
feat: add SHELL input support
This commit is contained in:
19
.github/workflows/ci_cd.yml
vendored
19
.github/workflows/ci_cd.yml
vendored
@@ -197,6 +197,25 @@ jobs:
|
|||||||
expected: failure
|
expected: failure
|
||||||
actual: ${{ steps.sad_path_timeout.outcome }}
|
actual: ${{ steps.sad_path_timeout.outcome }}
|
||||||
|
|
||||||
|
- name: sad-path (wrong shell)
|
||||||
|
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 }}
|
||||||
|
|
||||||
|
|
||||||
# runs on push to master only
|
# runs on push to master only
|
||||||
cd:
|
cd:
|
||||||
name: Publish Action
|
name: Publish Action
|
||||||
|
|||||||
22
README.md
22
README.md
@@ -20,10 +20,20 @@ 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`
|
||||||
|
|
||||||
|
### `shell`
|
||||||
|
|
||||||
|
**Optional** Shell to use to execute `command`. Defaults to `pwsh`. See [here](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell) for shell options
|
||||||
|
required: false
|
||||||
|
default: pwsh
|
||||||
|
|
||||||
### `polling_interval_seconds`
|
### `polling_interval_seconds`
|
||||||
|
|
||||||
**Optional** Number of seconds to wait while polling for command result. Defaults to `1`
|
**Optional** Number of seconds to wait while polling for command result. Defaults to `1`
|
||||||
@@ -52,6 +62,18 @@ The final error returned by the command
|
|||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
### Shell
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
uses: nick-invision/retry@v2
|
||||||
|
with:
|
||||||
|
timeout_minutes: 10
|
||||||
|
max_attempts: 3
|
||||||
|
os: ${{ runner.os }}
|
||||||
|
shell: pwsh
|
||||||
|
command: dir
|
||||||
|
```
|
||||||
|
|
||||||
### Timeout in minutes
|
### Timeout in minutes
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
|||||||
@@ -18,6 +18,13 @@ 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:
|
||||||
|
description: Shell to Use to retry (Default is pwsh)
|
||||||
|
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
|
||||||
@@ -36,4 +43,4 @@ outputs:
|
|||||||
description: The final error returned by the command
|
description: The final error returned by the command
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
46
dist/index.js
vendored
46
dist/index.js
vendored
@@ -247,8 +247,10 @@ 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 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';
|
||||||
@@ -308,14 +310,54 @@ function getTimeout() {
|
|||||||
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 () {
|
||||||
var end_time, child;
|
var end_time, executable, child;
|
||||||
return __generator(this, function (_c) {
|
return __generator(this, function (_c) {
|
||||||
switch (_c.label) {
|
switch (_c.label) {
|
||||||
case 0:
|
case 0:
|
||||||
end_time = Date.now() + getTimeout();
|
end_time = Date.now() + getTimeout();
|
||||||
exit = 0;
|
exit = 0;
|
||||||
done = false;
|
done = false;
|
||||||
child = child_process_1.exec(COMMAND);
|
executable = SHELL + ".exe";
|
||||||
|
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 });
|
||||||
(_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);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,5 +2,7 @@ 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_RETRY_WAIT_SECONDS=10
|
INPUT_RETRY_WAIT_SECONDS=10
|
||||||
|
SHELL=pwsh
|
||||||
|
OS=Linux
|
||||||
INPUT_POLLING_INTERVAL_SECONDS=1
|
INPUT_POLLING_INTERVAL_SECONDS=1
|
||||||
INPUT_RETRY_ON=any
|
INPUT_RETRY_ON=any
|
||||||
|
|||||||
46
src/index.ts
46
src/index.ts
@@ -9,8 +9,10 @@ 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 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';
|
||||||
@@ -67,7 +69,49 @@ async function runCmd() {
|
|||||||
exit = 0;
|
exit = 0;
|
||||||
done = false;
|
done = false;
|
||||||
|
|
||||||
var child = exec(COMMAND);
|
let executable: string = SHELL + ".exe";
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var child = exec(COMMAND, { 'shell': executable });
|
||||||
|
|
||||||
child.stdout?.on('data', (data) => {
|
child.stdout?.on('data', (data) => {
|
||||||
process.stdout.write(data);
|
process.stdout.write(data);
|
||||||
|
|||||||
Reference in New Issue
Block a user