From 5ee366655c257c0056a361e0219c1e60ee3228bf Mon Sep 17 00:00:00 2001 From: Nick Fields Date: Wed, 18 Nov 2020 10:25:11 -0500 Subject: [PATCH 1/3] feat: add warning_on_retry input --- README.md | 4 ++++ action.yml | 3 +++ dist/index.js | 8 +++++++- src/index.ts | 7 ++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 19dc1b9..8835c58 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ Retries an Action step on failure or timeout. This is currently intended to repl **Optional** Event to retry on. Currently supports [any (default), timeout, error]. +### `warning_on_retry` + +**Optional** Whether to output a warning on retry, or just output to info. Defaults to `true`. + ## Outputs ### `total_attempts` diff --git a/action.yml b/action.yml index 5b1b47f..f1f4a04 100644 --- a/action.yml +++ b/action.yml @@ -24,6 +24,9 @@ inputs: default: 1 retry_on: description: Event to retry on. Currently supported [any, timeout, error] + warning_on_retry: + description: Whether to output a warning on retry, or just output to info. Defaults to true + default: true outputs: total_attempts: description: The final number of attempts made diff --git a/dist/index.js b/dist/index.js index db1b4f6..f011518 100644 --- a/dist/index.js +++ b/dist/index.js @@ -251,6 +251,7 @@ var COMMAND = core_1.getInput('command', { required: true }); var RETRY_WAIT_SECONDS = getInputNumber('retry_wait_seconds', false) || 10; var POLLING_INTERVAL_SECONDS = getInputNumber('polling_interval_seconds', false) || 1; var RETRY_ON = core_1.getInput('retry_on') || 'any'; +var WARNING_ON_RETRY = core_1.getInput('warning_on_retry').toLowerCase() === 'true'; var OUTPUT_TOTAL_ATTEMPTS_KEY = 'total_attempts'; var OUTPUT_EXIT_CODE_KEY = 'exit_code'; var OUTPUT_EXIT_ERROR_KEY = 'exit_error'; @@ -398,7 +399,12 @@ function runAction() { throw error_1; } else { - core_1.warning("Attempt " + attempt + " failed. Reason: " + error_1.message); + if (WARNING_ON_RETRY) { + core_1.warning("Attempt " + attempt + " failed. Reason: " + error_1.message); + } + else { + core_1.info("Attempt " + attempt + " failed. Reason: " + error_1.message); + } } return [3 /*break*/, 6]; case 6: diff --git a/src/index.ts b/src/index.ts index 0513a09..5dc4067 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,7 @@ const COMMAND = getInput('command', { required: true }); const RETRY_WAIT_SECONDS = getInputNumber('retry_wait_seconds', false) || 10; const POLLING_INTERVAL_SECONDS = getInputNumber('polling_interval_seconds', false) || 1; const RETRY_ON = getInput('retry_on') || 'any'; +const WARNING_ON_RETRY = getInput('warning_on_retry').toLowerCase() === 'true'; const OUTPUT_TOTAL_ATTEMPTS_KEY = 'total_attempts'; const OUTPUT_EXIT_CODE_KEY = 'exit_code'; @@ -130,7 +131,11 @@ async function runAction() { // error: error throw error; } else { - warning(`Attempt ${attempt} failed. Reason: ${error.message}`); + if (WARNING_ON_RETRY) { + warning(`Attempt ${attempt} failed. Reason: ${error.message}`); + } else { + info(`Attempt ${attempt} failed. Reason: ${error.message}`); + } } } } From 292d515fa9b55edba21847ccd837474f8e27b61a Mon Sep 17 00:00:00 2001 From: Nick Fields Date: Wed, 18 Nov 2020 10:28:44 -0500 Subject: [PATCH 2/3] fix: allow timeout_seconds to be less than retry_wait_time --- dist/index.js | 3 --- src/index.ts | 6 ------ 2 files changed, 9 deletions(-) diff --git a/dist/index.js b/dist/index.js index f011518..5e2e99c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -292,9 +292,6 @@ function validateInputs() { if ((!TIMEOUT_MINUTES && !TIMEOUT_SECONDS) || (TIMEOUT_MINUTES && TIMEOUT_SECONDS)) { throw new Error('Must specify either timeout_minutes or timeout_seconds inputs'); } - if (TIMEOUT_SECONDS && TIMEOUT_SECONDS < RETRY_WAIT_SECONDS) { - throw new Error("timeout_seconds " + TIMEOUT_SECONDS + "s less than retry_wait_seconds " + RETRY_WAIT_SECONDS + "s"); - } return [2 /*return*/]; }); }); diff --git a/src/index.ts b/src/index.ts index 5dc4067..a9acda1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,12 +49,6 @@ async function validateInputs() { if ((!TIMEOUT_MINUTES && !TIMEOUT_SECONDS) || (TIMEOUT_MINUTES && TIMEOUT_SECONDS)) { throw new Error('Must specify either timeout_minutes or timeout_seconds inputs'); } - - if (TIMEOUT_SECONDS && TIMEOUT_SECONDS < RETRY_WAIT_SECONDS) { - throw new Error( - `timeout_seconds ${TIMEOUT_SECONDS}s less than retry_wait_seconds ${RETRY_WAIT_SECONDS}s` - ); - } } function getTimeout(): number { From 51e29ff1aeb1a2bf5e9f741b1f36993e453f301c Mon Sep 17 00:00:00 2001 From: Nick Fields Date: Wed, 18 Nov 2020 10:37:56 -0500 Subject: [PATCH 3/3] minor: document timeout_seconds input --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8835c58..b411c12 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,11 @@ Retries an Action step on failure or timeout. This is currently intended to repl ### `timeout_minutes` -**Required** Minutes to wait before attempt times out +**Required** Minutes to wait before attempt times out. Must only specify either minutes or seconds + +### `timeout_seconds` + +**Required** Seconds to wait before attempt times out. Must only specify either minutes or seconds ### `max_attempts`