Files
amethyst/.git-hooks/pre-push
Claude a72421c86c build: run the KMP metadata compiles on any push to main
Making them opt-in left a push straight to main (no branch protection)
without the check that 4 PRs breaking main in a day had put there. git
names the target refs on the hook's stdin: a push to refs/heads/main now
turns them on by itself. The read times out, so running the hook by hand
does not wait on the terminal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018fsjDqmcRg2F3kQpXmwgSy
2026-10-24 02:19:07 +00:00

83 lines
3.4 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
GREEN='\033[0;32m'
NO_COLOR='\033[0m'
echo "*********************************************************"
echo "Running git pre-push hook."
echo "*********************************************************"
echo ""
echo "Java Version: "
echo "$JAVA_HOME"
echo "$(java -version)"
echo "Running test... "
# Single-variant pre-push tests. `./gradlew test` would compile six Android
# variants of :amethyst (play/fdroid × debug/release/benchmark) plus full
# native-libs merging per variant — ~6× the work of one variant. CI runs the
# multi-flavor matrix on push to main; pre-push only needs one happy path.
#
# Every KMP module's tests live under <module>:jvmTest - the Kotlin Multiplatform
# plugin registers no plain `test` task - so a module missing from this list is a
# module nobody runs before pushing. Add new KMP modules here when they gain tests.
#
# `./gradlew test` now reaches the KMP modules too (see the `test` alias in the root
# build), but this hook stays explicit: a bare `test` would also pull in :desktopApp:test,
# which needs a display server and is deliberately skipped on CLAUDE_CODE_REMOTE below.
TASKS=(
# The CI lint job's source scan for JVM-only APIs in iOS-targeted code. It reads files, so it
# costs seconds.
:commons:verifyKmpPurity
:commonsUI:verifyKmpPurity
:commons:jvmTest
:commonsUI:jvmTest
# Android-only commonsUI code (e.g. SafeImeInsets) is tested here, not in jvmTest.
:commonsUI:testAndroidHostTest
:nestsClient:jvmTest
:marmotQuic:jvmTest
:amethyst:testPlayDebugUnitTest
:cli:test
)
# The metadata compiles are the rest of the CI lint job. The JVM tests above compile shared code
# for the JVM only, where java.util and java.io APIs (HashMap.putIfAbsent, Dispatchers.IO without
# the kotlinx.coroutines.IO import, AutoCloseable.use on skia or okio types) still resolve; the
# metadata compiles reject them, so a break only iOS would hit fails on any host. They are a third
# full compile of :commons and :commonsUI (8 of the 47 CPU minutes of a cold run, and 2.6 of the
# 6 after a one-line :commonsUI edit), so they are opt-in here and always run in CI's lint job.
# Turn them on when touching commonMain/skikoMain platform APIs or expect/actual:
# PREPUSH_KMP_METADATA=1 git push
# A push to main turns them on by itself: git names the target refs on stdin (the timeout keeps a
# hand-run `bash .git-hooks/pre-push`, which has no such input, from waiting on the terminal).
while read -r -t 5 _local_ref _local_sha remote_ref _remote_sha; do
if [ "$remote_ref" = "refs/heads/main" ]; then
PREPUSH_KMP_METADATA=1
fi
done
# Keep this list in sync with the lint job in .github/workflows/build.yml.
if [ "${PREPUSH_KMP_METADATA:-}" = "1" ]; then
TASKS+=(
:commons:compileCommonMainKotlinMetadata
:commonsUI:compileCommonMainKotlinMetadata
:commonsUI:compileSkikoMainKotlinMetadata
)
fi
if [ "${CLAUDE_CODE_REMOTE:-}" = "true" ]; then
./gradlew "${TASKS[@]}" --quiet
else
./gradlew "${TASKS[@]}" :desktopApp:test --quiet
fi
status=$?
if [ "$status" = 0 ] ; then
echo "All test passed."
exit 0
else
echo "*********************************************************"
echo 1>&2 "Failing check or test"
printf "Fix the compile errors or failing tests above and push again. Run ${GREEN}./gradlew test${NO_COLOR} for the full JVM suite.\n"
echo "*********************************************************"
exit 1
fi