#!/usr/bin/env bash # Pre-push hook: run the same install + build checks CI runs, but only for the # projects touched by the commits being pushed. # # Each project is a directory with a package.json and a pnpm-lock.yaml. # Bypass with: git push --no-verify set -euo pipefail root=$(git rev-parse --show-toplevel) cd "$root" zero=$(git hash-object --stdin /dev/null 2>&1 || { echo "pre-push: pnpm not found; install it to run the local checks" >&2 exit 1 } failed=() for dir in "${!projects[@]}"; do printf '\npre-push: checking %s\n' "$dir" if ! (cd "$dir" && CI=true pnpm install --frozen-lockfile >/dev/null 2>&1); then echo "pre-push: lockfile out of date in $dir (run pnpm install there)" >&2 failed+=("$dir (install)") continue fi if node -e "const s=require('./$dir/package.json').scripts||{}; process.exit(s.build?0:1)"; then if ! (cd "$dir" && pnpm run build >/tmp/pre-push-build.log 2>&1); then echo "pre-push: build failed in $dir (log: /tmp/pre-push-build.log)" >&2 tail -n 20 /tmp/pre-push-build.log >&2 failed+=("$dir (build)") fi fi done if ((${#failed[@]})); then printf '\npre-push: failing projects: %s\n' "${failed[*]}" >&2 exit 1 fi echo "pre-push: all changed projects install and build"