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:
Nick Fields
2022-08-02 22:47:32 -04:00
committed by GitHub
parent 14b6b46d04
commit 3dad7de805
15 changed files with 2702 additions and 418 deletions

1
.config/.eslintignore Normal file
View File

@@ -0,0 +1 @@
.eslintrc.js

7
.config/.eslintrc.js Normal file
View 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
View File

@@ -0,0 +1,2 @@
dist/
node_modules/

5
.config/.prettierrc.yml Normal file
View File

@@ -0,0 +1,5 @@
trailingComma: 'es5'
tabWidth: 2
semi: true
singleQuote: true
printWidth: 100

View File

@@ -4,7 +4,6 @@ about: Create a report to help us improve
title: ''
labels: ''
assignees: nick-invision
---
**Describe the bug**

5
.husky/commit-msg Executable file
View 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
View 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 .

View File

@@ -1,7 +0,0 @@
module.exports = {
tabWidth: 2,
printWidth: 100,
semi: true,
singleQuote: true,
trailingComma: 'es5',
};

3
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode"]
}

View File

@@ -1,6 +1,7 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"prettier.requireConfig": true,
"typescript.tsdk": "node_modules/typescript/lib",
"editor.tabSize": 2
"prettier.configPath": "./.config/.prettierrc.yml",
"prettier.ignorePath": "./.config/.prettierignore",
"typescript.tsdk": "node_modules/typescript/lib"
}

18
dist/index.js vendored
View File

@@ -712,25 +712,25 @@ function getExecutable() {
}
var executable;
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 ".concat(SHELL, " not allowed on OS ").concat(OS));
}
executable = SHELL;
break;
}
case "cmd":
case "powershell": {
case 'cmd':
case 'powershell': {
if (OS !== 'win32') {
throw new Error("Shell ".concat(SHELL, " not allowed on OS ").concat(OS));
}
executable = SHELL + ".exe";
executable = SHELL + '.exe';
break;
}
default: {
@@ -778,8 +778,8 @@ function runCmd(attempt) {
done = false;
(0, core_1.debug)("Running command ".concat(COMMAND, " on ").concat(OS, " using shell ").concat(executable));
child = attempt > 1 && NEW_COMMAND_ON_RETRY
? (0, child_process_1.exec)(NEW_COMMAND_ON_RETRY, { 'shell': executable })
: (0, child_process_1.exec)(COMMAND, { 'shell': executable });
? (0, child_process_1.exec)(NEW_COMMAND_ON_RETRY, { shell: executable })
: (0, child_process_1.exec)(COMMAND, { shell: executable });
(_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', function (data) {
process.stdout.write(data);
});

2984
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,8 +3,12 @@
"version": "0.0.0-managed-by-semantic-release",
"description": "Retries a GitHub Action step on failure or timeout.",
"scripts": {
"lint:base": "eslint --config ./.config/.eslintrc.js ",
"lint": "npm run lint:base -- .",
"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": {
"type": "git",
@@ -29,17 +33,26 @@
"@semantic-release/git": "^10.0.1",
"@types/milliseconds": "0.0.30",
"@types/node": "^16.11.7",
"@typescript-eslint/eslint-plugin": "^5.32.0",
"@typescript-eslint/parser": "^5.32.0",
"@zeit/ncc": "^0.20.5",
"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",
"ts-node": "9.0.0",
"typescript": "^4.7.4"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "npm run prepare && git add ."
}
"lint-staged": {
"**/*.ts": [
"npm run style:base --",
"npm run lint:base --"
],
"**/*.{md,yaml,yml}": [
"npm run style:base --"
]
}
}

View File

@@ -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