Compare commits

..

4 Commits

Author SHA1 Message Date
Raja Anbazhagan
c97818ca39 fix: group log lines for each attempt (#146) 2025-02-17 12:26:57 -05:00
Róbert Papp
dfb235ae84 Fix local action reference (#140) 2024-09-18 15:49:01 +00:00
Brandon Williams
3f757583fb docs: update README.md with new version (#130) 2024-02-03 13:24:21 +00:00
Preston Richey
7152eba30c Upgrade to Node 20 (#126)
* fix: upgrade to node 20, update relevant actions

* fix: install @vercel/ncc as dev dependency

* fix: allow writing to performance global

* fix: trivial change

* fix: regenerate package-lock.json and dist/index.js

* Revert "fix: trivial change"

This reverts commit 256b59f507.
2024-01-31 11:50:52 -05:00
9 changed files with 28799 additions and 16493 deletions

View File

@@ -14,11 +14,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
- name: Run Unit Tests
@@ -33,11 +33,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
@@ -143,11 +143,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
- name: env-vars-passed-through
@@ -164,11 +164,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
- name: Test 100MiB of output can be processed
@@ -195,11 +195,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
- name: retry_on_exit_code (with expected error code)
@@ -243,11 +243,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
- name: happy-path (continue_on_error)
@@ -290,11 +290,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
@@ -326,11 +326,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
@@ -369,11 +369,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
@@ -399,11 +399,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
@@ -430,11 +430,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
@@ -465,11 +465,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
@@ -495,11 +495,11 @@ jobs:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
- name: Powershell test
@@ -571,11 +571,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- name: Install dependencies
run: npm ci
- name: Release

2
.nvmrc
View File

@@ -1 +1 @@
v16.16.0
v20.11.0

View File

@@ -79,7 +79,7 @@ The final error returned by the command
### Shell
```yaml
uses: nick-fields/retry@v2
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
@@ -90,7 +90,7 @@ with:
### Timeout in minutes
```yaml
uses: nick-fields/retry@v2
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
@@ -100,7 +100,7 @@ with:
### Timeout in seconds
```yaml
uses: nick-fields/retry@v2
uses: nick-fields/retry@v3
with:
timeout_seconds: 15
max_attempts: 3
@@ -110,7 +110,7 @@ with:
### Only retry after timeout
```yaml
uses: nick-fields/retry@v2
uses: nick-fields/retry@v3
with:
timeout_seconds: 15
max_attempts: 3
@@ -121,7 +121,7 @@ with:
### Only retry after error
```yaml
uses: nick-fields/retry@v2
uses: nick-fields/retry@v3
with:
timeout_seconds: 15
max_attempts: 3
@@ -132,7 +132,7 @@ with:
### Retry using continue_on_error input (in composite action) but allow failure and do something with output
```yaml
- uses: nick-fields/retry@v2
- uses: nick-fields/retry@v3
id: retry
with:
timeout_seconds: 15
@@ -154,7 +154,7 @@ with:
### Retry using continue-on-error built-in command (in workflow action) but allow failure and do something with output
```yaml
- uses: nick-fields/retry@v2
- uses: nick-fields/retry@v3
id: retry
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idcontinue-on-error
continue-on-error: true
@@ -183,7 +183,7 @@ with:
### Run script after failure but before retry
```yaml
uses: nick-fields/retry@v2
uses: nick-fields/retry@v3
with:
timeout_seconds: 15
max_attempts: 3
@@ -194,7 +194,7 @@ with:
### Run different command after first failure
```yaml
uses: nick-fields/retry@v2
uses: nick-fields/retry@v3
with:
timeout_seconds: 15
max_attempts: 3
@@ -206,7 +206,7 @@ with:
```yaml
name: Multi-line multi-command Test
uses: ./
uses: nick-fields/retry@v3
with:
timeout_minutes: 1
max_attempts: 2
@@ -219,7 +219,7 @@ with:
```yaml
name: Multi-line single-command Test
uses: ./
uses: nick-fields/retry@v3
with:
timeout_minutes: 1
max_attempts: 2

View File

@@ -50,5 +50,5 @@ outputs:
exit_error:
description: The final error returned by the command
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'

28745
dist/index.js vendored

File diff suppressed because one or more lines are too long

16406
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -37,7 +37,7 @@
"@types/node": "^16.11.7",
"@typescript-eslint/eslint-plugin": "^5.32.0",
"@typescript-eslint/parser": "^5.32.0",
"@zeit/ncc": "^0.20.5",
"@vercel/ncc": "^0.38.1",
"dotenv": "8.2.0",
"eslint": "^8.21.0",
"eslint-config-prettier": "^8.5.0",

View File

@@ -11,16 +11,9 @@ 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';
@@ -78,7 +71,7 @@ async function runCmd(attempt: number, inputs: Inputs) {
const end_time = Date.now() + getTimeout(inputs);
const executable = getExecutable(inputs);
let exit = 0;
exit = 0;
done = false;
let timeout = false;
@@ -124,10 +117,10 @@ async function runCmd(attempt: number, inputs: Inputs) {
timeout = true;
kill(child.pid);
await retryWait(ms.seconds(inputs.retry_wait_seconds));
throw new ErrorWithCode(`Timeout of ${getTimeout(inputs)}ms hit`, exit);
throw new Error(`Timeout of ${getTimeout(inputs)}ms hit`);
} else if (exit > 0) {
await retryWait(ms.seconds(inputs.retry_wait_seconds));
throw new ErrorWithCode(`Child_process exited with error code ${exit}`, exit);
throw new Error(`Child_process exited with error code ${exit}`);
} else {
return;
}
@@ -137,6 +130,7 @@ async function runAction(inputs: Inputs) {
await validateInputs(inputs);
for (let attempt = 1; attempt <= inputs.max_attempts; attempt++) {
info(`::group::Attempt ${attempt}`);
try {
// just keep overwriting attempts output
setOutput(OUTPUT_TOTAL_ATTEMPTS_KEY, attempt);
@@ -145,9 +139,8 @@ 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 ErrorWithCode(`Final attempt failed. ${error.message}`, exit);
throw new Error(`Final attempt failed. ${error.message}`);
} else if (!done && inputs.retry_on === 'error') {
// error: timeout
throw error;
@@ -164,6 +157,8 @@ async function runAction(inputs: Inputs) {
info(`Attempt ${attempt} failed. Reason: ${error.message}`);
}
}
} finally {
info(`::endgroup::`);
}
}
}
@@ -176,7 +171,8 @@ runAction(inputs)
process.exit(0); // success
})
.catch((err) => {
const exitCode = err instanceof ErrorWithCode ? err.code : 1;
// exact error code if available, otherwise just 1
const exitCode = exit > 0 ? exit : 1;
if (inputs.continue_on_error) {
warning(err.message);

View File

@@ -3,6 +3,11 @@ import { getHeapStatistics } from 'v8';
import { wait } from './util';
// otherwise, TypeError: Cannot assign to read only property 'performance' of object '[object global]'
Object.defineProperty(global, 'performance', {
writable: true,
});
// mocks the setTimeout function, see https://jestjs.io/docs/timer-mocks
jest.useFakeTimers();
jest.spyOn(global, 'setTimeout');