Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
main ▾

Modern-Apps.git / .githooks / pre-push

pre-push55 lines · 2.2 KiBRaw
1#!/bin/bash
2# Pre-push backstop: if any commit in the pushed range touches a module whose
3# release lint now fails, reject the push (e.g. amend/rebase introduced it,
4# or the pre-commit gate was bypassed). Merge-time lint is the pre-commit
5# hook's job; this is the second lock.
6set -u
7# Under systemd-run (the sanctioned push vehicle) JAVA_HOME may be unset and
8# `java` resolves to JVM 8, which Gradle rejects. Prefer the JDK 21 sibling
9# the tooling uses, else any installed 17+.
10if [ -z "${JAVA_HOME:-}" ] || ! "$JAVA_HOME/bin/java" -version 2>&1 | grep -Eq '"(1[7-9]|2[0-9])'; then
11 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
12 if [ -x "$cand/bin/java" ]; then export JAVA_HOME="$cand"; break; fi
13 done
14fi
15remote="$1"
16zero="0000000000000000000000000000000000000000"
17fail=0
18while read -r local_ref local_sha remote_ref remote_sha; do
19 case "$remote_ref" in
20 refs/heads/main|refs/heads/master) ;;
21 *) continue ;;
22 esac
23 if [ "$remote_sha" = "$zero" ]; then range="$local_sha"; else range="$remote_sha..$local_sha"; fi
24 mods=$(git diff --name-only "$range" 2>/dev/null | awk -F/ '
25 {
26 if ($1=="games" && NF>=2) print $1"/"$2;
27 else if ($1=="library" && NF>=2) print $1"/"$2;
28 else if ($1=="sdk" && NF>=2) print $1"/"$2;
29 else print $1;
30 }' | sort -u)
31 tasks=""
32 for m in $mods; do
33 [ -f "$m/build.gradle.kts" ] || continue
34 g="$(echo "$m" | tr / :)"
35 case "$m" in *-wear) g="${g%-wear}:wear" ;; esac
36 # Pure infra carries no lint task at all (mirrors pre-commit).
37 if [ "$g" = "lint-rules" ] || [ "$g" = "build-logic" ]; then
38 continue
39 fi
40 # Pure-JVM/library modules have no release variant — gate on :lint.
41 if grep -Eq 'common-conventions-library|java-library|kotlin\("jvm"\)|org.jetbrains.kotlin.jvm' "$m/build.gradle.kts" 2>/dev/null; then
42 tasks="$tasks :${g}:lint"
43 else
44 tasks="$tasks :${g}:lintVitalRelease"
45 fi
46 done
47 if [ -n "$tasks" ]; then
48 echo "pre-push: release lint backstop for:$tasks"
49 if ! ./gradlew $tasks --console=plain -q; then
50 echo "pre-push: REJECTED — lintVitalRelease failed." >&2
51 fail=1
52 fi
53 fi
54done
55exit $fail