release-dev.sh raw

   1  #!/usr/bin/env bash
   2  # Dev release: build arm64 APK, push to webwarden-releases repo,
   3  # side-load to connected phone. No signing/publishing.
   4  #
   5  # Usage:
   6  #   ./scripts/release-dev.sh
   7  #
   8  # The APK is signed with the debug keystore (android/app/debug.keystore)
   9  # which is fine for local testing. Use release-apk.sh for production.
  10  
  11  set -euo pipefail
  12  
  13  cd "$(dirname "$0")/.."
  14  MAIN_REPO="$PWD"
  15  
  16  # ── Version ────────────────────────────────────────────────────────────
  17  VERSION="$(jq -r .version package.json)"
  18  COMMIT="$(git rev-parse --short HEAD)"
  19  TAG="v${VERSION}-dev-${COMMIT}"
  20  APK_NAME="Warden-${TAG}.apk"
  21  
  22  # ── Build ──────────────────────────────────────────────────────────────
  23  echo "→ Building release APK (arm64-v8a)..."
  24  ( cd android && ./gradlew assembleRelease -x lint -x test \
  25      -PreactNativeArchitectures=arm64-v8a \
  26      -PenableProguardInReleaseBuilds=true \
  27      -PenableShrinkResourcesInReleaseBuilds=true ) 2>&1 | tail -3
  28  
  29  APK_SRC="${MAIN_REPO}/android/app/build/outputs/apk/release/app-release.apk"
  30  if [[ ! -f "$APK_SRC" ]]; then
  31    echo "FATAL: APK not found at $APK_SRC"
  32    exit 1
  33  fi
  34  SIZE=$(du -h "$APK_SRC" | cut -f1)
  35  SHA=$(sha256sum "$APK_SRC" | awk '{print $1}')
  36  echo "   APK:    ${SIZE}"
  37  echo "   SHA256: ${SHA}"
  38  echo "   Tag:    ${TAG}"
  39  
  40  # ── Releases repo ──────────────────────────────────────────────────────
  41  RELEASES_REMOTE="ssh://git@orly/home/git/webwarden-releases.git"
  42  RELEASES_DIR="$HOME/.cache/warden-releases"
  43  
  44  if [[ ! -d "$RELEASES_DIR/.git" ]]; then
  45    echo "→ Cloning releases repo..."
  46    git clone "$RELEASES_REMOTE" "$RELEASES_DIR" 2>/dev/null
  47  fi
  48  
  49  echo "→ Updating releases repo..."
  50  cd "$RELEASES_DIR"
  51  git pull origin main 2>/dev/null || true
  52  
  53  mkdir -p "releases/${TAG}"
  54  cp "$APK_SRC" "releases/${TAG}/${APK_NAME}"
  55  echo "${SHA}  ${APK_NAME}" > "releases/${TAG}/SHA256SUMS"
  56  
  57  git add -A
  58  git commit -m "dev: ${TAG} — ${SIZE} sha=${SHA}" 2>/dev/null || true
  59  git push origin main 2>&1
  60  
  61  # ── Update README in main repo ──────────────────────────────────────────
  62  # Only the latest release belongs in the README. Obtainium scans this page
  63  # for .apk links, picks the last one alphabetically, and extracts the
  64  # version from the filename. Multiple conflicting links cause ambiguity.
  65  # Older releases live in the webwarden-releases repo — not in the README.
  66  RELEASE_URL="https://git.smesh.lol/webwarden-releases/raw/releases/${TAG}/${APK_NAME}"
  67  cd "$MAIN_REPO"
  68  if [[ -f README.md ]]; then
  69    # Replace the Releases section: drop everything between the header and
  70    # the next "#"-level header, then insert the fresh table.
  71    awk -v row="| [${APK_NAME}](${RELEASE_URL}) | \`${TAG}\` | \`${SHA}\` |" '
  72      BEGIN { in_rel=0; done=0 }
  73      /^## Releases$/  { print; print ""; print "| Version | APK | SHA-256 |"; print "|---------|-----|---------|"; print row; print ""; in_rel=1; next }
  74      in_rel && /^## / && !/^## Releases$/ { done=1; in_rel=0 }
  75      !in_rel { print }
  76    ' README.md > README.md.tmp && mv README.md.tmp README.md
  77    git add README.md
  78    git commit -m "docs: latest release — ${TAG}" 2>/dev/null || true
  79    git push smesh main 2>&1 || true
  80  fi
  81  
  82  # ── Side-load ──────────────────────────────────────────────────────────
  83  DEVICE=$(adb devices 2>/dev/null | grep -v 'List of' | grep -v '^$' | awk '{print $1}' | head -1)
  84  if [[ -n "$DEVICE" ]]; then
  85    echo "→ Installing on ${DEVICE}..."
  86    adb -s "$DEVICE" install -r "$APK_SRC" 2>&1
  87    echo "✓ Installed."
  88  else
  89    echo "ℹ  No device connected — skip side-load."
  90  fi
  91  
  92  echo
  93  echo "Done. APK at: ${RELEASES_DIR}/releases/${TAG}/${APK_NAME}"
  94