#!/usr/bin/env bash # Keep the served companion APK in sync with main on every push. # # When a push to main includes Android changes, rebuild the APK, refresh # neode-ui/public/packages/archipelago-companion.apk, commit it, and ask # you to push again (so the refreshed APK rides along in the same push). # # Enable once per clone: git config core.hooksPath .githooks set -euo pipefail ROOT="$(git rev-parse --show-toplevel)" cd "$ROOT" # ship-companion.sh already (re)published the APK for this push — don't redo it. [ -n "${SHIP_COMPANION:-}" ] && exit 0 PUSH_MAIN=0; RANGE_OLD=""; RANGE_NEW="" while read -r _local_ref local_sha remote_ref remote_sha; do if [ "${remote_ref##*/}" = "main" ]; then PUSH_MAIN=1; RANGE_OLD="$remote_sha"; RANGE_NEW="$local_sha" fi done [ "$PUSH_MAIN" = "1" ] || exit 0 # Loop-break: if the tip is already the auto APK commit, let the push proceed. case "$(git log -1 --pretty=%s)" in *"companion APK"*) exit 0 ;; esac # Only rebuild when this push actually touches the Android app. ZEROS="0000000000000000000000000000000000000000" if [ -z "$RANGE_OLD" ] || [ "$RANGE_OLD" = "$ZEROS" ]; then ANDROID_CHANGED=1 elif git diff --quiet "$RANGE_OLD" "$RANGE_NEW" -- Android/ 2>/dev/null; then ANDROID_CHANGED=0 else ANDROID_CHANGED=1 fi [ "$ANDROID_CHANGED" = "1" ] || exit 0 bash scripts/publish-companion-apk.sh || exit 0 DEST="neode-ui/public/packages/archipelago-companion.apk" if git diff --cached --quiet -- "$DEST"; then exit 0 # APK unchanged — nothing to do fi git commit -q -m "chore(android): update companion APK download [skip ci]" echo "" >&2 echo "▶ Companion APK rebuilt and committed. Run your push again to include it." >&2 exit 1