Skip to main content

max / makeover-webview

2.0 KB · 51 lines History Blame Raw
1 #!/bin/bash
2 # Canonical pre-push gate: blocks a push whose test targets do not build.
3 #
4 # DO NOT EDIT IN PLACE. The master is _private/infra/bootstrap/githooks/pre-push.
5 #
6 # Bypass for a work-in-progress push: git push --no-verify
7 #
8 # `cargo check` and `cargo clippy` both compile only the lib and bin targets, so a
9 # break confined to `tests/` or a `#[cfg(test)]` module is clean under both and
10 # lands unnoticed (goingson's sqlx 0.9 upgrade shipped exactly that way).
11 # `--no-run` builds every test target without running them, which is the cheap
12 # half of the suite and enough to catch a compile break. Tests still run
13 # separately.
14 #
15 # `--workspace` is load-bearing wherever default-members is narrower than the
16 # workspace: goingson's is src-tauri alone, so a bare `cargo test --no-run` would
17 # skip core, db-sqlite, go-mcp and got.
18 #
19 # Only installed in repos with a root Cargo.toml. MNW and synckit have none by
20 # design (standalone crates, no root workspace), so there is no one command to run
21 # and they get the pre-commit gates only.
22 set -euo pipefail
23
24 ROOT="$(git rev-parse --show-toplevel)"
25 cd "$ROOT"
26
27 # See the canonical pre-commit: a hook run from an editor or a cron job does not
28 # get the profile's PATH, and a hook that cannot find cargo is worse than none.
29 export PATH="$HOME/.cargo/bin:$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin:$PATH"
30
31 [ -f "$ROOT/Cargo.toml" ] || exit 0
32
33 # Refs arrive on stdin as "<local ref> <local sha> <remote ref> <remote sha>".
34 # A branch deletion has an all-zero local sha and no tree to build.
35 pushing=0
36 while read -r _local_ref local_sha _remote_ref _remote_sha; do
37 case "$local_sha" in
38 *[!0]*) pushing=1 ;;
39 esac
40 done
41 [ "$pushing" -eq 1 ] || exit 0
42
43 echo "pre-push: building test targets (cargo test --no-run --workspace)..."
44 if ! cargo test --no-run --workspace; then
45 echo "pre-push: test targets failed to build."
46 echo "pre-push: push aborted (use --no-verify to bypass)."
47 exit 1
48 fi
49
50 echo "pre-push: test targets build clean."
51