mirror of
https://github.com/nick-fields/retry.git
synced 2026-02-10 07:05:29 +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:
1
.config/.eslintignore
Normal file
1
.config/.eslintignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.eslintrc.js
|
||||||
7
.config/.eslintrc.js
Normal file
7
.config/.eslintrc.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
plugins: ['@typescript-eslint'],
|
||||||
|
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
|
||||||
|
ignorePatterns: ['**/*.js', 'dist/'],
|
||||||
|
};
|
||||||
2
.config/.prettierignore
Normal file
2
.config/.prettierignore
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
dist/
|
||||||
|
node_modules/
|
||||||
5
.config/.prettierrc.yml
Normal file
5
.config/.prettierrc.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
trailingComma: 'es5'
|
||||||
|
tabWidth: 2
|
||||||
|
semi: true
|
||||||
|
singleQuote: true
|
||||||
|
printWidth: 100
|
||||||
1
.github/ISSUE_TEMPLATE/bug-report.md
vendored
1
.github/ISSUE_TEMPLATE/bug-report.md
vendored
@@ -4,7 +4,6 @@ about: Create a report to help us improve
|
|||||||
title: ''
|
title: ''
|
||||||
labels: ''
|
labels: ''
|
||||||
assignees: nick-invision
|
assignees: nick-invision
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Describe the bug**
|
**Describe the bug**
|
||||||
|
|||||||
5
.husky/commit-msg
Executable file
5
.husky/commit-msg
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
. "$(dirname -- "$0")/_/husky.sh"
|
||||||
|
|
||||||
|
# lint commit message
|
||||||
|
npx --no -- commitlint --config ./.config/.commitlintrc.js --edit $1
|
||||||
8
.husky/pre-commit
Executable file
8
.husky/pre-commit
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
. "$(dirname -- "$0")/_/husky.sh"
|
||||||
|
|
||||||
|
# run lint/styling on staged changes
|
||||||
|
npx lint-staged
|
||||||
|
|
||||||
|
# regenerate dist
|
||||||
|
npm run prepare && git add .
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
tabWidth: 2,
|
|
||||||
printWidth: 100,
|
|
||||||
semi: true,
|
|
||||||
singleQuote: true,
|
|
||||||
trailingComma: 'es5',
|
|
||||||
};
|
|
||||||
3
.vscode/extensions.json
vendored
Normal file
3
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"recommendations": ["esbenp.prettier-vscode"]
|
||||||
|
}
|
||||||
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"prettier.requireConfig": true,
|
"prettier.configPath": "./.config/.prettierrc.yml",
|
||||||
"typescript.tsdk": "node_modules/typescript/lib",
|
"prettier.ignorePath": "./.config/.prettierignore",
|
||||||
"editor.tabSize": 2
|
"typescript.tsdk": "node_modules/typescript/lib"
|
||||||
}
|
}
|
||||||
|
|||||||
18
dist/index.js
vendored
18
dist/index.js
vendored
@@ -712,25 +712,25 @@ function getExecutable() {
|
|||||||
}
|
}
|
||||||
var executable;
|
var executable;
|
||||||
switch (SHELL) {
|
switch (SHELL) {
|
||||||
case "bash":
|
case 'bash':
|
||||||
case "python":
|
case 'python':
|
||||||
case "pwsh": {
|
case 'pwsh': {
|
||||||
executable = SHELL;
|
executable = SHELL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "sh": {
|
case 'sh': {
|
||||||
if (OS === 'win32') {
|
if (OS === 'win32') {
|
||||||
throw new Error("Shell ".concat(SHELL, " not allowed on OS ").concat(OS));
|
throw new Error("Shell ".concat(SHELL, " not allowed on OS ").concat(OS));
|
||||||
}
|
}
|
||||||
executable = SHELL;
|
executable = SHELL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "cmd":
|
case 'cmd':
|
||||||
case "powershell": {
|
case 'powershell': {
|
||||||
if (OS !== 'win32') {
|
if (OS !== 'win32') {
|
||||||
throw new Error("Shell ".concat(SHELL, " not allowed on OS ").concat(OS));
|
throw new Error("Shell ".concat(SHELL, " not allowed on OS ").concat(OS));
|
||||||
}
|
}
|
||||||
executable = SHELL + ".exe";
|
executable = SHELL + '.exe';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@@ -778,8 +778,8 @@ function runCmd(attempt) {
|
|||||||
done = false;
|
done = false;
|
||||||
(0, core_1.debug)("Running command ".concat(COMMAND, " on ").concat(OS, " using shell ").concat(executable));
|
(0, core_1.debug)("Running command ".concat(COMMAND, " on ").concat(OS, " using shell ").concat(executable));
|
||||||
child = attempt > 1 && NEW_COMMAND_ON_RETRY
|
child = attempt > 1 && NEW_COMMAND_ON_RETRY
|
||||||
? (0, child_process_1.exec)(NEW_COMMAND_ON_RETRY, { 'shell': executable })
|
? (0, child_process_1.exec)(NEW_COMMAND_ON_RETRY, { shell: executable })
|
||||||
: (0, child_process_1.exec)(COMMAND, { 'shell': executable });
|
: (0, 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);
|
||||||
});
|
});
|
||||||
|
|||||||
2980
package-lock.json
generated
2980
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
27
package.json
27
package.json
@@ -3,8 +3,12 @@
|
|||||||
"version": "0.0.0-managed-by-semantic-release",
|
"version": "0.0.0-managed-by-semantic-release",
|
||||||
"description": "Retries a GitHub Action step on failure or timeout.",
|
"description": "Retries a GitHub Action step on failure or timeout.",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"lint:base": "eslint --config ./.config/.eslintrc.js ",
|
||||||
|
"lint": "npm run lint:base -- .",
|
||||||
"local": "npm run prepare && node -r dotenv/config ./dist/index.js",
|
"local": "npm run prepare && node -r dotenv/config ./dist/index.js",
|
||||||
"prepare": "ncc build src/index.ts"
|
"prepare": "ncc build src/index.ts && husky install",
|
||||||
|
"style:base": "prettier --config ./.config/.prettierrc.yml --ignore-path ./.config/.prettierignore --write ",
|
||||||
|
"style": "npm run style:base -- ."
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -29,17 +33,26 @@
|
|||||||
"@semantic-release/git": "^10.0.1",
|
"@semantic-release/git": "^10.0.1",
|
||||||
"@types/milliseconds": "0.0.30",
|
"@types/milliseconds": "0.0.30",
|
||||||
"@types/node": "^16.11.7",
|
"@types/node": "^16.11.7",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.32.0",
|
||||||
|
"@typescript-eslint/parser": "^5.32.0",
|
||||||
"@zeit/ncc": "^0.20.5",
|
"@zeit/ncc": "^0.20.5",
|
||||||
"dotenv": "8.2.0",
|
"dotenv": "8.2.0",
|
||||||
"husky": "^4.3.8",
|
"eslint": "^8.21.0",
|
||||||
|
"eslint-config-prettier": "^8.5.0",
|
||||||
|
"husky": "^8.0.1",
|
||||||
|
"lint-staged": "^13.0.3",
|
||||||
|
"prettier": "^2.7.1",
|
||||||
"semantic-release": "19.0.3",
|
"semantic-release": "19.0.3",
|
||||||
"ts-node": "9.0.0",
|
"ts-node": "9.0.0",
|
||||||
"typescript": "^4.7.4"
|
"typescript": "^4.7.4"
|
||||||
},
|
},
|
||||||
"husky": {
|
"lint-staged": {
|
||||||
"hooks": {
|
"**/*.ts": [
|
||||||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
"npm run style:base --",
|
||||||
"pre-commit": "npm run prepare && git add ."
|
"npm run lint:base --"
|
||||||
}
|
],
|
||||||
|
"**/*.{md,yaml,yml}": [
|
||||||
|
"npm run style:base --"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
41
src/index.ts
41
src/index.ts
@@ -25,8 +25,8 @@ 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';
|
||||||
|
|
||||||
var exit: number;
|
let exit: number;
|
||||||
var done: boolean;
|
let done: boolean;
|
||||||
|
|
||||||
function getInputNumber(id: string, required: boolean): number | undefined {
|
function getInputNumber(id: string, required: boolean): number | undefined {
|
||||||
const input = getInput(id, { required });
|
const input = getInput(id, { required });
|
||||||
@@ -44,13 +44,13 @@ function getInputNumber(id: string, required: boolean): number | undefined {
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInputBoolean(id: string): Boolean {
|
function getInputBoolean(id: string): boolean {
|
||||||
const input = getInput(id);
|
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}`;
|
throw `Input ${id} only accepts boolean values. Received ${input}`;
|
||||||
}
|
}
|
||||||
return input.toLowerCase() === 'true'
|
return input.toLowerCase() === 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function retryWait() {
|
async function retryWait() {
|
||||||
@@ -83,32 +83,34 @@ function getExecutable(): string {
|
|||||||
|
|
||||||
let executable: string;
|
let executable: string;
|
||||||
switch (SHELL) {
|
switch (SHELL) {
|
||||||
case "bash":
|
case 'bash':
|
||||||
case "python":
|
case 'python':
|
||||||
case "pwsh": {
|
case 'pwsh': {
|
||||||
executable = SHELL;
|
executable = SHELL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "sh": {
|
case 'sh': {
|
||||||
if (OS === 'win32') {
|
if (OS === 'win32') {
|
||||||
throw new Error(`Shell ${SHELL} not allowed on OS ${OS}`);
|
throw new Error(`Shell ${SHELL} not allowed on OS ${OS}`);
|
||||||
}
|
}
|
||||||
executable = SHELL;
|
executable = SHELL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "cmd":
|
case 'cmd':
|
||||||
case "powershell": {
|
case 'powershell': {
|
||||||
if (OS !== 'win32') {
|
if (OS !== 'win32') {
|
||||||
throw new Error(`Shell ${SHELL} not allowed on OS ${OS}`);
|
throw new Error(`Shell ${SHELL} not allowed on OS ${OS}`);
|
||||||
}
|
}
|
||||||
executable = SHELL + ".exe";
|
executable = SHELL + '.exe';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
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> {
|
async function runRetryCmd(): Promise<void> {
|
||||||
@@ -119,8 +121,9 @@ async function runRetryCmd(): Promise<void> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await execSync(ON_RETRY_COMMAND, { stdio: 'inherit' });
|
await execSync(ON_RETRY_COMMAND, { stdio: 'inherit' });
|
||||||
|
// eslint-disable-next-line
|
||||||
} catch (error: any) {
|
} 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;
|
exit = 0;
|
||||||
done = false;
|
done = false;
|
||||||
|
|
||||||
debug(`Running command ${COMMAND} on ${OS} using shell ${executable}`)
|
debug(`Running command ${COMMAND} on ${OS} using shell ${executable}`);
|
||||||
var child = attempt > 1 && NEW_COMMAND_ON_RETRY
|
const child =
|
||||||
? exec(NEW_COMMAND_ON_RETRY, { 'shell': executable })
|
attempt > 1 && NEW_COMMAND_ON_RETRY
|
||||||
: exec(COMMAND, { 'shell': executable });
|
? exec(NEW_COMMAND_ON_RETRY, { shell: executable })
|
||||||
|
: exec(COMMAND, { shell: executable });
|
||||||
|
|
||||||
child.stdout?.on('data', (data) => {
|
child.stdout?.on('data', (data) => {
|
||||||
process.stdout.write(data);
|
process.stdout.write(data);
|
||||||
@@ -182,6 +186,7 @@ async function runAction() {
|
|||||||
await runCmd(attempt);
|
await runCmd(attempt);
|
||||||
info(`Command completed after ${attempt} attempt(s).`);
|
info(`Command completed after ${attempt} attempt(s).`);
|
||||||
break;
|
break;
|
||||||
|
// eslint-disable-next-line
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (attempt === MAX_ATTEMPTS) {
|
if (attempt === MAX_ATTEMPTS) {
|
||||||
throw new Error(`Final attempt failed. ${error.message}`);
|
throw new Error(`Final attempt failed. ${error.message}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user