diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 00000000..973aa11a --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,48 @@ +#!/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.zip, 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" + +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.zip" +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 diff --git a/neode-ui/public/packages/archipelago-companion.apk.zip b/neode-ui/public/packages/archipelago-companion.apk.zip index 248894dd..e8e0e97d 100644 Binary files a/neode-ui/public/packages/archipelago-companion.apk.zip and b/neode-ui/public/packages/archipelago-companion.apk.zip differ diff --git a/scripts/publish-companion-apk.sh b/scripts/publish-companion-apk.sh new file mode 100755 index 00000000..52818138 --- /dev/null +++ b/scripts/publish-companion-apk.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# Build the Archipelago companion debug APK and stage it as the served download +# at neode-ui/public/packages/archipelago-companion.apk.zip. +# +# Run manually, or automatically via the pre-push hook (.githooks/pre-push). +set -euo pipefail + +ROOT="$(git rev-parse --show-toplevel)" +cd "$ROOT" + +JAVA="${JAVA_HOME:-/opt/homebrew/opt/openjdk@17}" +SDK="${ANDROID_HOME:-$HOME/Library/Android/sdk}" + +if [ ! -x "$JAVA/bin/java" ] || [ ! -d "$SDK" ]; then + echo "publish-companion-apk: JDK or Android SDK not found — skipping." >&2 + echo " (set JAVA_HOME and ANDROID_HOME to build the companion APK)" >&2 + exit 0 +fi + +echo "publish-companion-apk: building debug APK…" >&2 +( cd Android && JAVA_HOME="$JAVA" ANDROID_HOME="$SDK" ./gradlew -q :app:assembleDebug ) + +APK="Android/app/build/outputs/apk/debug/app-debug.apk" +DEST="neode-ui/public/packages/archipelago-companion.apk.zip" +mkdir -p "$(dirname "$DEST")" + +TMP="$(mktemp -d)" +cp "$APK" "$TMP/app-debug.apk" +# -X drops platform-specific extra fields for a stabler archive. +( cd "$TMP" && zip -q -X archipelago-companion.apk.zip app-debug.apk ) +cp "$TMP/archipelago-companion.apk.zip" "$DEST" +rm -rf "$TMP" + +git add "$DEST" +echo "publish-companion-apk: staged $DEST" >&2