Compare commits

...

11 Commits

Author SHA1 Message Date
Nick Fields
850bd83fba More doc cleanup 2021-01-03 21:16:16 -05:00
Nick Fields
88ed4273a8 Merge pull request #31 from nick-invision/fix-docs
docs: cleanup docs around shell defaults and supported
2021-01-03 21:09:04 -05:00
Nick Fields
bee86ddb77 docs: cleanup docs around shell defaults and supported 2021-01-03 21:00:31 -05:00
Nick Fields
f865f2ade8 test: fix tests again 2021-01-02 15:34:51 -05:00
Nick Fields
8310ca5ae8 test: fix tests 2021-01-02 15:29:38 -05:00
Nick Fields
e48877fb9c Merge pull request #30 from isaacrlevin/master
feat: add SHELL input support
2021-01-02 15:25:40 -05:00
Isaac Levin
4af9664183 Merge pull request #1 from nick-invision/nrf/shell
Don't require OS input and use correct default shell per os
2021-01-02 08:55:04 -08:00
Nick Fields
d0aac3501c fix: dont require OS input and use correct shell per os 2021-01-02 10:20:16 -05:00
Isaac Levin
877a0ac37e feat: add SHELL input support 2021-01-01 22:57:53 +00:00
Nick Fields
0aeb89504c Merge pull request #27 from nick-invision/dependabot/npm_and_yarn/semantic-release-17.2.3
build(deps-dev): bump semantic-release from 17.2.2 to 17.2.3
2020-11-19 17:37:43 -05:00
dependabot[bot]
b2ee390b23 build(deps-dev): bump semantic-release from 17.2.2 to 17.2.3
Bumps [semantic-release](https://github.com/semantic-release/semantic-release) from 17.2.2 to 17.2.3.
- [Release notes](https://github.com/semantic-release/semantic-release/releases)
- [Commits](https://github.com/semantic-release/semantic-release/compare/v17.2.2...v17.2.3)

Signed-off-by: dependabot[bot] <support@github.com>
2020-11-18 22:35:27 +00:00
8 changed files with 855 additions and 1379 deletions

View File

@@ -197,6 +197,59 @@ jobs:
expected: failure expected: failure
actual: ${{ steps.sad_path_timeout.outcome }} actual: ${{ steps.sad_path_timeout.outcome }}
- name: sad-path (wrong shell for OS)
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 }}
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:
name: Publish Action name: Publish Action

View File

@@ -24,6 +24,10 @@ Retries an Action step on failure or timeout. This is currently intended to repl
**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 `powershell` on Windows, `bash` otherwise. Supports bash, python, pwsh, sh, cmd, and powershell per [docs](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell)
### `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 +56,17 @@ The final error returned by the command
## Examples ## Examples
### Shell
```yaml
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
shell: pwsh
command: dir
```
### Timeout in minutes ### Timeout in minutes
```yaml ```yaml

View File

@@ -18,6 +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
shell:
description: Alternate shell to use (defaults to powershell on windows, bash otherwise). Supports bash, python, pwsh, sh, cmd, and powershell
required: false
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 +39,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'

41
dist/index.js vendored
View File

@@ -249,9 +249,11 @@ 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 = 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 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';
@@ -305,17 +307,52 @@ 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 + " 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;
}
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();
executable = getExecutable();
exit = 0; exit = 0;
done = false; done = false;
child = child_process_1.exec(COMMAND); core_1.debug("Running command " + COMMAND + " on " + OS + " using 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);
}); });

2076
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -32,7 +32,7 @@
"@zeit/ncc": "^0.20.5", "@zeit/ncc": "^0.20.5",
"dotenv": "8.2.0", "dotenv": "8.2.0",
"husky": "4.3.0", "husky": "4.3.0",
"semantic-release": "17.2.2", "semantic-release": "17.2.3",
"ts-node": "9.0.0", "ts-node": "9.0.0",
"typescript": "4.0.5" "typescript": "4.0.5"
}, },

View File

@@ -2,5 +2,6 @@ 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
INPUT_POLLING_INTERVAL_SECONDS=1 INPUT_POLLING_INTERVAL_SECONDS=1
INPUT_RETRY_ON=any INPUT_RETRY_ON=any

View File

@@ -11,10 +11,12 @@ const TIMEOUT_SECONDS = getInputNumber('timeout_seconds', false);
const MAX_ATTEMPTS = getInputNumber('max_attempts', true) || 3; const MAX_ATTEMPTS = getInputNumber('max_attempts', true) || 3;
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');
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';
@@ -61,13 +63,50 @@ 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');
} }
function getExecutable(): string {
if (!SHELL) {
return OS === 'win32' ? 'powershell' : 'bash';
}
let executable: string;
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} 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
}
async function runCmd() { async function runCmd() {
const end_time = Date.now() + getTimeout(); const end_time = Date.now() + getTimeout();
const executable = getExecutable();
exit = 0; exit = 0;
done = false; done = false;
var child = exec(COMMAND); debug(`Running command ${COMMAND} on ${OS} using shell ${executable}`)
var child = exec(COMMAND, { 'shell': executable });
child.stdout?.on('data', (data) => { child.stdout?.on('data', (data) => {
process.stdout.write(data); process.stdout.write(data);