mirror of
https://github.com/nick-fields/retry.git
synced 2026-02-12 16:17:42 +00:00
Setup prettier and eslint and run pre-commit (#86)
* patch: setup prettier * patch: move .commitlintrc.js to .config * patch: config lint-staged and update husky * patch: configure eslint as well
This commit is contained in:
45
src/index.ts
45
src/index.ts
@@ -25,8 +25,8 @@ const OUTPUT_TOTAL_ATTEMPTS_KEY = 'total_attempts';
|
||||
const OUTPUT_EXIT_CODE_KEY = 'exit_code';
|
||||
const OUTPUT_EXIT_ERROR_KEY = 'exit_error';
|
||||
|
||||
var exit: number;
|
||||
var done: boolean;
|
||||
let exit: number;
|
||||
let done: boolean;
|
||||
|
||||
function getInputNumber(id: string, required: boolean): number | undefined {
|
||||
const input = getInput(id, { required });
|
||||
@@ -44,13 +44,13 @@ function getInputNumber(id: string, required: boolean): number | undefined {
|
||||
return num;
|
||||
}
|
||||
|
||||
function getInputBoolean(id: string): Boolean {
|
||||
function getInputBoolean(id: string): boolean {
|
||||
const input = getInput(id);
|
||||
|
||||
if (!['true','false'].includes(input.toLowerCase())) {
|
||||
if (!['true', 'false'].includes(input.toLowerCase())) {
|
||||
throw `Input ${id} only accepts boolean values. Received ${input}`;
|
||||
}
|
||||
return input.toLowerCase() === 'true'
|
||||
return input.toLowerCase() === 'true';
|
||||
}
|
||||
|
||||
async function retryWait() {
|
||||
@@ -83,32 +83,34 @@ function getExecutable(): string {
|
||||
|
||||
let executable: string;
|
||||
switch (SHELL) {
|
||||
case "bash":
|
||||
case "python":
|
||||
case "pwsh": {
|
||||
case 'bash':
|
||||
case 'python':
|
||||
case 'pwsh': {
|
||||
executable = SHELL;
|
||||
break;
|
||||
}
|
||||
case "sh": {
|
||||
case 'sh': {
|
||||
if (OS === 'win32') {
|
||||
throw new Error(`Shell ${SHELL} not allowed on OS ${OS}`);
|
||||
}
|
||||
executable = SHELL;
|
||||
break;
|
||||
}
|
||||
case "cmd":
|
||||
case "powershell": {
|
||||
case 'cmd':
|
||||
case 'powershell': {
|
||||
if (OS !== 'win32') {
|
||||
throw new Error(`Shell ${SHELL} not allowed on OS ${OS}`);
|
||||
}
|
||||
executable = SHELL + ".exe";
|
||||
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`);
|
||||
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
|
||||
return executable;
|
||||
}
|
||||
|
||||
async function runRetryCmd(): Promise<void> {
|
||||
@@ -119,8 +121,9 @@ async function runRetryCmd(): Promise<void> {
|
||||
|
||||
try {
|
||||
await execSync(ON_RETRY_COMMAND, { stdio: 'inherit' });
|
||||
// eslint-disable-next-line
|
||||
} catch (error: any) {
|
||||
info(`WARNING: Retry command threw the error ${error.message}`)
|
||||
info(`WARNING: Retry command threw the error ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,10 +134,11 @@ async function runCmd(attempt: number) {
|
||||
exit = 0;
|
||||
done = false;
|
||||
|
||||
debug(`Running command ${COMMAND} on ${OS} using shell ${executable}`)
|
||||
var child = attempt > 1 && NEW_COMMAND_ON_RETRY
|
||||
? exec(NEW_COMMAND_ON_RETRY, { 'shell': executable })
|
||||
: exec(COMMAND, { 'shell': executable });
|
||||
debug(`Running command ${COMMAND} on ${OS} using shell ${executable}`);
|
||||
const child =
|
||||
attempt > 1 && NEW_COMMAND_ON_RETRY
|
||||
? exec(NEW_COMMAND_ON_RETRY, { shell: executable })
|
||||
: exec(COMMAND, { shell: executable });
|
||||
|
||||
child.stdout?.on('data', (data) => {
|
||||
process.stdout.write(data);
|
||||
@@ -182,13 +186,14 @@ async function runAction() {
|
||||
await runCmd(attempt);
|
||||
info(`Command completed after ${attempt} attempt(s).`);
|
||||
break;
|
||||
// eslint-disable-next-line
|
||||
} catch (error: any) {
|
||||
if (attempt === MAX_ATTEMPTS) {
|
||||
throw new Error(`Final attempt failed. ${error.message}`);
|
||||
} else if (!done && RETRY_ON === 'error') {
|
||||
// error: timeout
|
||||
throw error;
|
||||
} else if (RETRY_ON_EXIT_CODE && RETRY_ON_EXIT_CODE !== exit){
|
||||
} else if (RETRY_ON_EXIT_CODE && RETRY_ON_EXIT_CODE !== exit) {
|
||||
throw error;
|
||||
} else if (exit > 0 && RETRY_ON === 'timeout') {
|
||||
// error: error
|
||||
|
||||
Reference in New Issue
Block a user