Skip to content

Commit

Permalink
chore(ci): fix git hooks on CI (#41)
Browse files Browse the repository at this point in the history
To resolve issues with `simple-git-hooks` I switched to `husky`.

With `simple-git-hooks` the hooks also run at the GitHub actions, which causes errors. This shouldn't be the case anymore.
  • Loading branch information
mheob authored Sep 16, 2022
1 parent 391af17 commit 7aad5cc
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .changeset/wise-ghosts-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm exec commitlint --edit "$1"
14 changes: 14 additions & 0 deletions .husky/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

[ -n "$CI" ] && exit 0

changedFiles="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"

hasChanged() {
echo "$changedFiles" | grep -q "$1"
}

if hasChanged 'pnpm-lock.yaml'; then
pnpm install
fi
6 changes: 6 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

[ -n "$CI" ] && exit 0

pnpm exec lint-staged
6 changes: 6 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

[ -n "$CI" ] && exit 0

pnpm exec changeset status --since main
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
"clean:root": "rm -rf .turbo && rm -rf node_modules",
"format": "prettier --write \"**/*.{cjs,js,jsx,ts,tsx,json,md,mdx,yml}\"",
"lint": "turbo run lint",
"prepare": "ts-node ./scripts/prepare.ts",
"release": "changeset publish",
"sort-package-json": "pnpm dlx sort-package-json && turbo run sort-package-json",
"version-packages": "changeset version"
},
"simple-git-hooks": {
"pre-commit": "pnpm exec lint-staged && pnpm run changeset status --since main",
"commit-msg": "pnpm exec commitlint --edit ${1}"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
Expand All @@ -36,11 +33,15 @@
"@commitlint/config-conventional": "^17.1.0",
"@mheob/eslint-config": "workspace:*",
"@mheob/prettier-config": "workspace:*",
"@types/node": "^18.7.18",
"eslint": "^8.23.1",
"husky": "^8.0.0",
"is-ci": "^3.0.1",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"simple-git-hooks": "^2.8.0",
"turbo": "^1.4.6"
"ts-node": "^10.9.1",
"turbo": "^1.4.6",
"typescript": "^4.8.3"
},
"packageManager": "pnpm@7.11.0",
"engines": {
Expand Down
59 changes: 51 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions scripts/prepare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { install as installHusky } from 'husky';

const isCI = process.env.CI !== undefined;

if (!isCI) {
installHusky();
}
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./packages/tsconfig/base.json"
}

0 comments on commit 7aad5cc

Please sign in to comment.