#!/bin/bash # Pre-push backstop: if any commit in the pushed range touches a module whose # release lint now fails, reject the push (e.g. amend/rebase introduced it, # or the pre-commit gate was bypassed). Merge-time lint is the pre-commit # hook's job; this is the second lock. set -u # Under systemd-run (the sanctioned push vehicle) JAVA_HOME may be unset and # `java` resolves to JVM 8, which Gradle rejects. Prefer the JDK 21 sibling # the tooling uses, else any installed 17+. if [ -z "${JAVA_HOME:-}" ] || ! "$JAVA_HOME/bin/java" -version 2>&1 | grep -Eq '"(1[7-9]|2[0-9])'; then for cand in /home/vayun/maos/prebuilts/jdk/jdk21/linux-x86 /usr/lib/jvm/java-17-openjdk-17.0.20.1.1-1.2.el9.x86_64 /usr/lib/jvm/java-17-openjdk; do if [ -x "$cand/bin/java" ]; then export JAVA_HOME="$cand"; break; fi done fi remote="$1" zero="0000000000000000000000000000000000000000" fail=0 while read -r local_ref local_sha remote_ref remote_sha; do case "$remote_ref" in refs/heads/main|refs/heads/master) ;; *) continue ;; esac if [ "$remote_sha" = "$zero" ]; then range="$local_sha"; else range="$remote_sha..$local_sha"; fi mods=$(git diff --name-only "$range" 2>/dev/null | awk -F/ ' { if ($1=="games" && NF>=2) print $1"/"$2; else if ($1=="library" && NF>=2) print $1"/"$2; else if ($1=="sdk" && NF>=2) print $1"/"$2; else print $1; }' | sort -u) tasks="" for m in $mods; do [ -f "$m/build.gradle.kts" ] || continue g="$(echo "$m" | tr / :)" case "$m" in *-wear) g="${g%-wear}:wear" ;; esac # Pure infra carries no lint task at all (mirrors pre-commit). if [ "$g" = "lint-rules" ] || [ "$g" = "build-logic" ]; then continue fi # Pure-JVM/library modules have no release variant — gate on :lint. if grep -Eq 'common-conventions-library|java-library|kotlin\("jvm"\)|org.jetbrains.kotlin.jvm' "$m/build.gradle.kts" 2>/dev/null; then tasks="$tasks :${g}:lint" else tasks="$tasks :${g}:lintVitalRelease" fi done if [ -n "$tasks" ]; then echo "pre-push: release lint backstop for:$tasks" if ! ./gradlew $tasks --console=plain -q; then echo "pre-push: REJECTED — lintVitalRelease failed." >&2 fail=1 fi fi done exit $fail