#!/usr/bin/env bash # Dev release: build arm64 APK, push to webwarden-releases repo, # side-load to connected phone. No signing/publishing. # # Usage: # ./scripts/release-dev.sh # # The APK is signed with the debug keystore (android/app/debug.keystore) # which is fine for local testing. Use release-apk.sh for production. set -euo pipefail cd "$(dirname "$0")/.." MAIN_REPO="$PWD" # ── Version ──────────────────────────────────────────────────────────── VERSION="$(jq -r .version package.json)" COMMIT="$(git rev-parse --short HEAD)" TAG="v${VERSION}-dev-${COMMIT}" APK_NAME="Warden-${TAG}.apk" # ── Build ────────────────────────────────────────────────────────────── echo "→ Building release APK (arm64-v8a)..." ( cd android && ./gradlew assembleRelease -x lint -x test \ -PreactNativeArchitectures=arm64-v8a \ -PenableProguardInReleaseBuilds=true \ -PenableShrinkResourcesInReleaseBuilds=true ) 2>&1 | tail -3 APK_SRC="${MAIN_REPO}/android/app/build/outputs/apk/release/app-release.apk" if [[ ! -f "$APK_SRC" ]]; then echo "FATAL: APK not found at $APK_SRC" exit 1 fi SIZE=$(du -h "$APK_SRC" | cut -f1) SHA=$(sha256sum "$APK_SRC" | awk '{print $1}') echo " APK: ${SIZE}" echo " SHA256: ${SHA}" echo " Tag: ${TAG}" # ── Releases repo ────────────────────────────────────────────────────── RELEASES_REMOTE="ssh://git@orly/home/git/webwarden-releases.git" RELEASES_DIR="$HOME/.cache/warden-releases" if [[ ! -d "$RELEASES_DIR/.git" ]]; then echo "→ Cloning releases repo..." git clone "$RELEASES_REMOTE" "$RELEASES_DIR" 2>/dev/null fi echo "→ Updating releases repo..." cd "$RELEASES_DIR" git pull origin main 2>/dev/null || true mkdir -p "releases/${TAG}" cp "$APK_SRC" "releases/${TAG}/${APK_NAME}" echo "${SHA} ${APK_NAME}" > "releases/${TAG}/SHA256SUMS" git add -A git commit -m "dev: ${TAG} — ${SIZE} sha=${SHA}" 2>/dev/null || true git push origin main 2>&1 # ── Update README in main repo ────────────────────────────────────────── # Only the latest release belongs in the README. Obtainium scans this page # for .apk links, picks the last one alphabetically, and extracts the # version from the filename. Multiple conflicting links cause ambiguity. # Older releases live in the webwarden-releases repo — not in the README. RELEASE_URL="https://git.smesh.lol/webwarden-releases/raw/releases/${TAG}/${APK_NAME}" cd "$MAIN_REPO" if [[ -f README.md ]]; then # Replace the Releases section: drop everything between the header and # the next "#"-level header, then insert the fresh table. awk -v row="| [${APK_NAME}](${RELEASE_URL}) | \`${TAG}\` | \`${SHA}\` |" ' BEGIN { in_rel=0; done=0 } /^## Releases$/ { print; print ""; print "| Version | APK | SHA-256 |"; print "|---------|-----|---------|"; print row; print ""; in_rel=1; next } in_rel && /^## / && !/^## Releases$/ { done=1; in_rel=0 } !in_rel { print } ' README.md > README.md.tmp && mv README.md.tmp README.md git add README.md git commit -m "docs: latest release — ${TAG}" 2>/dev/null || true git push smesh main 2>&1 || true fi # ── Side-load ────────────────────────────────────────────────────────── DEVICE=$(adb devices 2>/dev/null | grep -v 'List of' | grep -v '^$' | awk '{print $1}' | head -1) if [[ -n "$DEVICE" ]]; then echo "→ Installing on ${DEVICE}..." adb -s "$DEVICE" install -r "$APK_SRC" 2>&1 echo "✓ Installed." else echo "ℹ No device connected — skip side-load." fi echo echo "Done. APK at: ${RELEASES_DIR}/releases/${TAG}/${APK_NAME}"