diff options
Diffstat (limited to '.githooks/pre-commit')
| -rwxr-xr-x | .githooks/pre-commit | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 4a3bcc5..9b12c78 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -9,23 +9,37 @@ fail() { exit 1 } -echo "== [1/9] Build ==" +# The server first, because it is the fast one: ten seconds against several minutes, so a Go +# mistake is reported before the Android build has begun rather than after it. +# +# It had no gate at all until now. Twenty-five server commits went in on a human remembering to +# type "go test" and reading the output -- the exact habit the Gradle wrappers exist to replace. +echo "== [1/10] Server: format, build, vet, tests ==" +if [ -f server/go.mod ]; then + if ! /workspace/devtools/bin/go-verify server; then + fail "the server did not pass -- see the report above." + fi +else + echo "pre-commit: no server module here, skipping." +fi + +echo "== [2/10] Build ==" ./gradlew :app:compileDebugKotlin -q -echo "== [2/9] Tests ==" +echo "== [3/10] Tests ==" ./gradlew :app:testDebugUnitTest -q -echo "== [3/9] Static analysis: lint ==" +echo "== [4/10] Static analysis: lint ==" if ! ./gradlew :app:lintDebug -q; then fail "lint failed -- fix all lint ERRORS before committing (warnings are fine to accumulate, see CLAUDE.md)." fi -echo "== [4/9] Static analysis: detekt (code-quality auditor) ==" +echo "== [5/10] Static analysis: detekt (code-quality auditor) ==" if ! ./gradlew :app:detekt -q; then fail "detekt found new issues beyond the tracked baseline. Fix them, or if they're genuinely pre-existing debt being touched incidentally, regenerate the baseline with './gradlew :app:detektBaseline' and explain why in the commit message." fi -echo "== [5/9] Coverage must not decrease ==" +echo "== [6/10] Coverage must not decrease ==" ./gradlew :app:jacocoTestReport -q REPORT="app/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml" BASELINE_FILE=".coverage-baseline" @@ -59,7 +73,7 @@ else echo "pre-commit: coverage ${BASELINE}% -> ${CURRENT}%" fi -echo "== [6/9] WebView JavaScript justification ==" +echo "== [7/10] WebView JavaScript justification ==" STAGED_KT=$(git diff --cached --name-only --diff-filter=ACM -- '*.kt' || true) if [ -n "$STAGED_KT" ]; then for f in $STAGED_KT; do @@ -73,14 +87,14 @@ if [ -n "$STAGED_KT" ]; then done fi -echo "== [7/9] Manifest permission diff ==" +echo "== [8/10] Manifest permission diff ==" if git diff --cached --name-only | grep -q '^app/src/main/AndroidManifest.xml$'; then if git diff --cached -- app/src/main/AndroidManifest.xml | grep -qE '^\+.*<uses-permission'; then echo "pre-commit: WARNING -- AndroidManifest.xml adds a new <uses-permission>. Make sure the commit message says why." fi fi -echo "== [8/9] Secret scan ==" +echo "== [9/10] Secret scan ==" if [ -z "${SECRET_SCAN_OVERRIDE:-}" ]; then SECRET_HIT=$(git diff --cached -U0 -- . ':!*.lock' | grep -E '^\+' | grep -viE '^\+\+\+' | grep -E '(api[_-]?key|secret|password|token)["'\'' ]*[:=]["'\'' ]*[A-Za-z0-9_\-]{16,}' || true) if [ -n "$SECRET_HIT" ]; then @@ -91,7 +105,7 @@ else echo "pre-commit: secret scan skipped (SECRET_SCAN_OVERRIDE set)" fi -echo "== [9/9] Exported Room schemas are append-only ==" +echo "== [10/10] Exported Room schemas are append-only ==" # A schema JSON already committed describes a database version that exists on a phone. Room # rewrites the file for whatever version the @Database annotation declares, so editing an entity # before bumping that number silently overwrites the record of the old shape -- and the migration |
