Files
amethyst/.git-hooks/pre-push

93 lines
4.0 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
: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=$?
# Android lint, CI's lint-android job, which nothing above covers: a media3 @UnstableApi call
# passes every test and fails only here (#4649). Its own Gradle invocation after the test JVMs
# have exited, for memory (see the lint-android note in .github/workflows/build.yml). playDebug
# reuses :amethyst:testPlayDebugUnitTest's compile; CI's benchmark variant would compile a second one.
if [ "$status" = 0 ] ; then
echo "Running Android lint... "
./gradlew :amethyst:lintPlayDebug --quiet
status=$?
fi
if [ "$status" = 0 ] ; then
echo "All test passed."
exit 0
else
echo "*********************************************************"
echo 1>&2 "Failing check or test"
printf "Fix the compile errors, failing tests or lint errors above and push again. Run ${GREEN}./gradlew test${NO_COLOR} for the full JVM suite.\n"
printf "Lint report: amethyst/build/reports/lint-results-playDebug.html\n"
echo "*********************************************************"
exit 1
fi