|
1 | 1 | #!/bin/sh |
| 2 | +# Checks only what this push changes against its merge base with origin/staging (the PR base): |
| 3 | +# biome format + lint on the changed files, then type-check for the affected workspaces. |
| 4 | +# CI runs the full lint, type-check and audit gate on every PR, so it stays the backstop. |
2 | 5 | set -e |
3 | 6 |
|
4 | | -bun run lint:check |
5 | | -bun run type-check |
| 7 | +# git passes one "<local ref> <local sha> <remote ref> <remote sha>" line per pushed ref. |
| 8 | +zero=0000000000000000000000000000000000000000 |
| 9 | +head=$(git rev-parse HEAD) |
| 10 | +pushes_head=false |
| 11 | +while read -r _local_ref local_sha _remote_ref _remote_sha; do |
| 12 | + [ "$local_sha" = "$zero" ] && continue |
| 13 | + if [ "$local_sha" != "$head" ]; then |
| 14 | + # These checks read the working tree, which holds HEAD, not this commit. |
| 15 | + echo "pre-push: $local_sha is not the checked-out commit; leaving it to CI" |
| 16 | + continue |
| 17 | + fi |
| 18 | + pushes_head=true |
| 19 | +done |
| 20 | +[ "$pushes_head" = true ] || exit 0 |
| 21 | + |
| 22 | +base=$(git merge-base HEAD origin/staging 2>/dev/null || true) |
| 23 | +if [ -z "$base" ]; then |
| 24 | + echo "pre-push: origin/staging not found, running the full lint and type-check" |
| 25 | + bun run lint:check |
| 26 | + bun run type-check |
| 27 | + exit 0 |
| 28 | +fi |
| 29 | + |
| 30 | +# Deletions still decide the type-check (an import of a deleted module breaks); biome only |
| 31 | +# reads files that exist. |
| 32 | +changed=$(git diff --name-only "$base" HEAD) |
| 33 | +[ -z "$changed" ] && exit 0 |
| 34 | +existing=$(git diff --name-only --diff-filter=ACMR "$base" HEAD) |
| 35 | + |
| 36 | +if [ -n "$existing" ]; then |
| 37 | + # Word-splitting the list is deliberate; no path biome checks contains a space. |
| 38 | + bunx biome check --no-errors-on-unmatched --files-ignore-unknown=true $existing |
| 39 | +fi |
| 40 | + |
| 41 | +if printf '%s\n' "$changed" | grep -qE '^scripts/'; then |
| 42 | + bun run type-check:scripts:esm |
| 43 | +fi |
| 44 | +TURBO_SCM_BASE="$base" bunx turbo run type-check --affected --output-logs=errors-only |
0 commit comments