Skip to content

Commit

Permalink
feat: add husky pre-push hook (#3319)
Browse files Browse the repository at this point in the history
* feat: add husky pre-push hook

Prior to pushing to remote, check and fix any linting issues.

If an issue was found and fixed, we’ll prevent the user from pushing - he would have to commit the changed files.

If you want to run the test suite on pushing you can set the RUN_TESTS_ON_PUSH variable to true.

Co-authored-by: katspaugh <[email protected]>
  • Loading branch information
compojoom and katspaugh authored Feb 26, 2024
1 parent d7e7e75 commit b4138d2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Store the initial git status
initial_status=$(git status --porcelain)

# Run the lint command
yarn run lint --fix

# Store the status after running lint
post_lint_status=$(git status --porcelain)

# Compare the initial and post-lint statuses
if [ "$initial_status" != "$post_lint_status" ]; then
echo "===================================="
echo "Linters gonna lint!"
echo "Linting made changes. Please commit these changes before pushing or push with --no-verify flag to omit this check."
echo "===================================="
exit 1
fi

# Check if the user wants to run tests on push
if [ "$RUN_TESTS_ON_PUSH" == "true" ]; then
echo "Running tests..."
if ! yarn test; then
echo "===================================="
echo "Tests failed. Guess they need more 'exercise'!"
echo "Please fix the issues before pushing or push with --no-verify flag to omit this check."
echo "===================================="
exit 1
fi
fi

# All goooood in safe's land!
exit 0
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ To create a new component from a template:
yarn cmp MyNewComponent
```

## Pre-push hooks

This repo has a pre-push hook that runs the linter (always) and the tests (if the `RUN_TESTS_ON_PUSH` env variable is set to true)
before pushing. If you want to skip the hooks, you can use the `--no-verify` flag.

## Frameworks

This app is built using the following frameworks:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"cypress:ci": "yarn cypress:run --config baseUrl=http://localhost:8080 --spec cypress/e2e/smoke/*.cy.js",
"serve": "npx -y serve out -p ${REVERSE_PROXY_UI_PORT:=8080}",
"static-serve": "yarn build && yarn serve",
"update-wc": "yarn add @walletconnect/web3wallet@latest @walletconnect/utils@latest @walletconnect/types@latest"
"update-wc": "yarn add @walletconnect/web3wallet@latest @walletconnect/utils@latest @walletconnect/types@latest",
"prepare": "husky"
},
"engines": {
"node": ">=16"
Expand Down Expand Up @@ -132,6 +133,7 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"fake-indexeddb": "^4.0.2",
"husky": "^9.0.11",
"jest": "^29.6.2",
"jest-environment-jsdom": "^29.6.2",
"prettier": "^2.7.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10613,6 +10613,11 @@ humanize-ms@^1.2.1:
dependencies:
ms "^2.0.0"

husky@^9.0.11:
version "9.0.11"
resolved "https://registry.yarnpkg.com/husky/-/husky-9.0.11.tgz#fc91df4c756050de41b3e478b2158b87c1e79af9"
integrity sha512-AB6lFlbwwyIqMdHYhwPe+kjOC3Oc5P3nThEoW/AaO2BX3vJDjWPFxYLxokUZOo6RNX20He3AaT8sESs9NJcmEw==

[email protected], iconv-lite@~0.4.13:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
Expand Down

0 comments on commit b4138d2

Please sign in to comment.