Skip to content

Commit 6e77102

Browse files
authored
ci: make the lefthook pre-push hook actually install (#4642)
## Summary `lefthook.yml` has been in the repo since #4147, but nothing installs lefthook and nothing runs `lefthook install`, so the pre-push hook it describes has never fired for anyone. #3977 had removed the `lefthook` devDependency a week before #4147 landed, and #4147 only added the config file. This supplies the missing half: ```diff + "prepare": "lefthook install", + "lefthook": "^2.1.10", "onlyBuiltDependencies": [ + "lefthook", ``` With those in place, `pnpm install` wires the hook up on clone, and the format and lint checks actually run before a push instead of first failing in CI. Also here: the pre-push jobs run in parallel rather than in sequence, and `CONTRIBUTING.md` documents the hook, including how to skip it and the fact that GitButler only runs hooks when "Run hooks" is enabled in its settings. `lefthook@2.1.10` is the current release.
1 parent 3d0b46f commit 6e77102

6 files changed

Lines changed: 140 additions & 2 deletions

File tree

.oxfmtrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"**/storybook-static/",
2222
"**/.changeset/",
2323
"**/dist/",
24+
"**/.worktrees/",
2425
"internal-packages/tsql/src/grammar/",
2526
"internal-packages/llm-model-catalog/src/defaultPrices.ts",
2627
"internal-packages/llm-model-catalog/src/modelCatalog.ts",

.oxlintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"ignorePatterns": [
1313
"**/dist/**",
1414
"**/build/**",
15+
"**/.worktrees/**",
1516
"**/*.d.ts",
1617
"**/seed.js",
1718
"**/seedCloud.ts",

CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,19 @@ pnpm exec trigger dev --log-level debug
214214
5. Commit the generated migration files as well as the changes to `schema.prisma`.
215215
6. If you're using VSCode you may need to restart the TypeScript server in the webapp to get updated type inference. Open a TypeScript file, then open the Command Palette (View > Command Palette) and run `TypeScript: Restart TS server`.
216216

217+
## Git hooks (lefthook)
218+
219+
We use [lefthook](https://lefthook.dev) for local git hooks, configured in `lefthook.yml` (the source of truth for what runs and when). Today that's a pre-push hook mirroring the CI `code-quality` checks; the set may grow, so check `lefthook.yml` rather than this guide.
220+
221+
Hooks install automatically on `pnpm install`. A failing hook prints exactly what to run to fix it.
222+
223+
**Opting out**
224+
225+
- GitButler skips hooks on `but push` unless you enable **Run hooks** in the project settings (off by default).
226+
- Plain git: `LEFTHOOK=0 git push` / `--no-verify` to skip once; `pnpm exec lefthook uninstall` to remove.
227+
228+
This never affects correctness — CI enforces the same checks on every PR; the hooks just give you faster feedback.
229+
217230
## Making a pull request
218231

219232
**If you get errors, be sure to fix them before committing.**

lefthook.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,29 @@ pre-commit:
1010
# implementation and only runs hooks when "Run hooks" is enabled in its
1111
# settings - with that off, this protects plain `git push` only.
1212
pre-push:
13+
parallel: true
1314
jobs:
1415
- name: format
15-
run: pnpm exec oxfmt --check .
16+
run: |
17+
pnpm exec oxfmt --check . || {
18+
echo ""
19+
echo "✖ Formatting issues found. Fix them with:"
20+
echo ""
21+
echo " pnpm run format"
22+
echo ""
23+
echo " then stage the changes and re-push."
24+
echo ""
25+
exit 1
26+
}
1627
- name: lint
17-
run: pnpm exec oxlint .
28+
run: |
29+
pnpm exec oxlint . || {
30+
echo ""
31+
echo "✖ Lint errors found. Auto-fix what's fixable with:"
32+
echo ""
33+
echo " pnpm run lint:fix"
34+
echo ""
35+
echo " then review, stage, and re-push (some rules need a manual fix)."
36+
echo ""
37+
exit 1
38+
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"@vitest/coverage-v8": "4.1.7",
6464
"autoprefixer": "^10.4.12",
6565
"knip": "6.25.0",
66+
"lefthook": "^2.1.10",
6667
"oxfmt": "^0.54.0",
6768
"oxlint": "^1.69.0",
6869
"pkg-pr-new": "0.0.75",
@@ -157,6 +158,7 @@
157158
"better-sqlite3",
158159
"cpu-features",
159160
"esbuild",
161+
"lefthook",
160162
"prisma",
161163
"protobufjs",
162164
"sharp",

pnpm-lock.yaml

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)