Skip to content

armgit / lyftr

Public Imported from GitHub
0

Self-hosted fitness tracker. Log workouts, track nutrition, and monitor progress. Docker deployment, mobile-friendly.

ci(mobile): build the release APK on the runner, and make it report the tag it ships under (#87)

Carterb49652de6749
diff --git a/.github/workflows/eas-build.yml b/.github/workflows/eas-build.yml
index 2bb7337..31fad95 100644
--- a/.github/workflows/eas-build.yml
+++ b/.github/workflows/eas-build.yml
@@ -2,14 +2,28 @@
#
# Two paths (matching how OSS Expo apps ship):
# • TESTERS → run this workflow manually (Actions → Run workflow). EAS builds an
-# Android APK; you install it from the build's expo.dev page (download link + QR).
+# Android APK on Expo's servers; you install it from the build's expo.dev page
+# (download link + QR). Queued with --no-wait, per Expo's CI guidance.
# • PUBLIC → push a `v*` tag (the same single tag namespace ci.yml uses for the
-# web/backend release — one tag now covers every platform). EAS builds the APK, and
-# CI attaches it to the GitHub Release for that tag (a permanent, public "Download
-# for Android" asset) alongside the web/backend notes. See RELEASING.md.
+# web/backend release — one tag now covers every platform). The APK is built **on the
+# runner** and attached to the GitHub Release for that tag (a permanent, public
+# "Download for Android" asset) alongside the web/backend notes. See RELEASING.md.
#
-# Native builds are slow + consume EAS quota, so this stays a separate workflow from
-# ci.yml's fast test jobs and never runs per-PR.
+# ── Why the release build runs on the runner (`eas build --local`) ────────────────────
+# It used to submit to hosted EAS and block on the result. That broke for v0.1.0-beta.4:
+# the build spent 3h09m in the free-tier queue, the job hit its 45-minute cap and was
+# cancelled, and the finished APK was never attached — the release shipped assetless
+# while the artifact sat on expo.dev. Raising the cap only widens the window; the queue
+# is unbounded and not ours to control.
+#
+# `--local` runs the same EAS build recipe on the runner: no queue, no EAS build quota,
+# and the artifact lands on disk where the upload step can reach it. Signing is
+# unchanged — credentials still come from the EAS server (`credentialsSource: remote`
+# by default), so releases stay signed with the same keystore and installed apps keep
+# upgrading in place. This is what OSS projects that ship a side-loadable APK do.
+#
+# Native builds are slow, so this stays a separate workflow from ci.yml's fast test jobs
+# and never runs per-PR.
#
# ── One-time setup (required before the first run) ────────────────────────────────────
# 1. `cd mobile && npx eas login` then `npx eas init` (links an EAS project; writes
@@ -25,15 +39,23 @@ on:
workflow_dispatch:
inputs:
platform:
- description: Platform to build
+ description: 'Platform to build (tester builds only — ignored by dry_run_release)'
type: choice
default: android
options: [android, ios, all]
profile:
- description: EAS build profile
+ description: 'EAS build profile (tester builds only — ignored by dry_run_release)'
type: choice
default: preview
options: [preview, production]
+ dry_run_release:
+ description: >-
+ Rehearse the release build instead: build the Android preview APK on the runner
+ exactly as a tag would, upload it as a workflow artifact, and touch no GitHub
+ Release. Ignores the two inputs above — a release is Android/preview by
+ definition, and rehearsing anything else would not be a rehearsal.
+ type: boolean
+ default: false
push:
tags:
- 'v*' # unified tag namespace — same tags ci.yml builds/pushes web+backend images on
@@ -50,7 +72,7 @@ permissions:
jobs:
# On-demand tester build → the APK lives on the EAS build page (install link + QR).
tester-build:
- if: github.event_name == 'workflow_dispatch'
+ if: github.event_name == 'workflow_dispatch' && !inputs.dry_run_release
name: EAS ${{ github.event.inputs.profile }} (${{ github.event.inputs.platform }})
runs-on: ubuntu-latest
timeout-minutes: 20
@@ -83,69 +105,169 @@ jobs:
--non-interactive \
--no-wait
- # Tagged release → wait for the Android APK, then attach it to a GitHub Release.
+ # Tagged release → build the Android APK on this runner, then attach it to the Release.
+ # Also runs on a manual dispatch with dry_run_release, which stops after the artifact
+ # upload — that's how you rehearse a release build without publishing anything.
release-apk:
- if: github.event_name == 'push'
+ if: github.event_name == 'push' || inputs.dry_run_release
name: Release Android APK
runs-on: ubuntu-latest
- timeout-minutes: 45 # waits for the full EAS build, then attaches the APK
+ timeout-minutes: 60 # the whole Gradle build now happens here — no external queue
permissions:
contents: write # create/update the GitHub Release + upload the asset
+ env:
+ EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} # eas needs this for credentials, not just login
steps:
- name: Require EXPO_TOKEN
- env:
- EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
run: |
if [ -z "$EXPO_TOKEN" ]; then
echo "::error::EXPO_TOKEN secret is not set — see this workflow's header for one-time setup."
exit 1
fi
+ # A dispatch form can't hide inputs that don't apply to the path you picked, so say
+ # so in the log rather than failing: the values are harmless here (this job is
+ # Android/preview by definition) and losing a 20-minute build over a dropdown would
+ # be worse than the confusion it prevents.
+ - name: Note ignored inputs
+ if: github.event_name == 'workflow_dispatch' && (inputs.platform != 'android' || inputs.profile != 'preview')
+ run: |
+ echo "::warning::dry_run_release rehearses the release build, which is always \
+ android/preview — ignoring platform=${{ inputs.platform }} profile=${{ inputs.profile }}."
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: package-lock.json
+ # Local Android builds compile with Gradle on this runner, so the JDK is ours to
+ # pin rather than EAS's image's. 17 is what AGP 8 / RN 0.81 expect.
+ - uses: actions/setup-java@v4
+ with:
+ distribution: temurin
+ java-version: '17'
- uses: expo/expo-github-action@v8
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}
- run: npm ci
- # Build with the `preview` profile: distribution:internal → a signed, installable
- # APK (production builds an AAB store bundle, which isn't directly side-loadable).
- # No --no-wait here: we need the finished artifact to attach to the Release.
- - name: Build APK on EAS and capture the artifact URL
- working-directory: mobile
+ # A cold Gradle build re-downloads the whole Android dependency graph (~10 min of
+ # the run). The lockfile keys it: native deps only change when they do.
+ - name: Cache Gradle
+ uses: actions/cache@v4
+ with:
+ path: |
+ ~/.gradle/caches
+ ~/.gradle/wrapper
+ # Keyed on the lockfile alone. app.json used to be in here, but RELEASING.md has
+ # you bump expo.version before every tag — so the release build, the one run that
+ # most needs the cache, was guaranteed to miss and then save a fresh multi-hundred-MB
+ # entry against the repo's cache budget. The app version doesn't affect the graph.
+ key: gradle-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
+ restore-keys: gradle-${{ runner.os }}-
+
+ # The tag is the version, for every platform — #77 unified the namespace, and this
+ # is what comparable self-hosted projects do (Immich tags v3.1.0 and its mobile app
+ # reports 3.1.0). Stamping it here means the APK's versionName can never drift from
+ # the release it's attached to, whatever app.json happens to say.
+ #
+ # A dry run has no tag (the ref is a branch, which can contain slashes and isn't a
+ # version at all), so it falls back to app.json and the stamp is a no-op.
+ - name: Resolve the release version
+ id: ver
+ env:
+ EVENT: ${{ github.event_name }}
+ run: |
+ if [ "$EVENT" = "push" ]; then
+ V="${GITHUB_REF_NAME#v}"
+ # The `v*` trigger matches anything — `vnext` would stamp expo.version="next",
+ # sail past the versionName check (which compares against this same string, so
+ # it can't disagree), and publish lyftr-vnext.apk. Only a real version ships.
+ case "$V" in
+ [0-9]*.[0-9]*.[0-9]*) ;;
+ *) echo "::error::Tag '$GITHUB_REF_NAME' isn't a version — expected vMAJOR.MINOR.PATCH[-suffix]"; exit 1 ;;
+ esac
+ else
+ V="$(node -p "require('./mobile/app.json').expo.version")"
+ fi
+ echo "version=$V" >> "$GITHUB_OUTPUT"
+ echo "name=lyftr-v$V.apk" >> "$GITHUB_OUTPUT"
+
+ # Runner-only edit; never committed. app.json in the repo should be bumped to match
+ # the tag in the release commit anyway (see RELEASING.md) — this is the backstop that
+ # makes a forgotten bump impossible to ship.
+ #
+ # VERSION comes in through env, not ${{ }} interpolation: it derives from a tag name,
+ # and tag text expanded straight into a `run:` script is arbitrary code in a job that
+ # holds contents:write and EXPO_TOKEN. Needs push access to exploit, but the safe form
+ # costs nothing.
+ - name: Stamp the version into app.json
+ env:
+ VERSION: ${{ steps.ver.outputs.version }}
run: |
- eas build -p android --profile preview --non-interactive --json > build.json
node -e '
- const fs = require("fs");
- const raw = JSON.parse(fs.readFileSync("build.json", "utf8"));
- const b = Array.isArray(raw) ? raw[0] : raw;
- // Robust to EAS CLI field renames: deep-scan the build object for any https URL
- // whose path ends in .apk, and fall back to the known artifact fields.
- const found = [];
- (function walk(v) {
- if (typeof v === "string") { if (/^https:\/\/\S+\.apk(\?|$)/i.test(v)) found.push(v); }
- else if (v && typeof v === "object") { for (const k of Object.keys(v)) walk(v[k]); }
- })(b);
- const url = found[0] || b?.artifacts?.applicationArchiveUrl || b?.artifacts?.buildUrl;
- if (!url) {
- console.error("No APK URL found. Full build object:\n" + JSON.stringify(b, null, 2));
- process.exit(1);
- }
- fs.appendFileSync(process.env.GITHUB_ENV, `APK_URL=${url}\n`);
- console.log("APK URL:", url);
+ const fs = require("fs"), p = "mobile/app.json";
+ const j = JSON.parse(fs.readFileSync(p, "utf8"));
+ j.expo.version = process.env.VERSION;
+ fs.writeFileSync(p, JSON.stringify(j, null, 2) + "\n");
'
+ node -p "'app.json version is now ' + require('./mobile/app.json').expo.version"
+
+ # `preview` profile: distribution:internal → a signed, installable APK (production
+ # builds an AAB store bundle, which isn't directly side-loadable). --local keeps the
+ # build on this runner; credentials are still fetched from EAS, so the signing key
+ # is the same one previous releases used.
+ - name: Build the APK on this runner
+ working-directory: mobile
+ env:
+ APK_NAME: ${{ steps.ver.outputs.name }} # via env, same reasoning as the stamp step
+ run: |
+ eas build \
+ --platform android \
+ --profile preview \
+ --local \
+ --non-interactive \
+ --output "$GITHUB_WORKSPACE/$APK_NAME"
+
+ - name: Verify the APK is real and correctly configured
+ env:
+ VERSION: ${{ steps.ver.outputs.version }}
+ APK_NAME: ${{ steps.ver.outputs.name }}
+ run: |
+ APK="$GITHUB_WORKSPACE/$APK_NAME"
+ test -s "$APK" || { echo "::error::No APK at $APK"; exit 1; }
+ test -n "$ANDROID_HOME" || { echo "::error::ANDROID_HOME is unset — can't locate aapt2"; exit 1; }
+ # sort -V, not sort: a lexicographic sort would pick 19.x over a future 9.x and
+ # silently hand us an ancient aapt2 whose dump output can fail these greps on a
+ # perfectly good APK.
+ AAPT="$(find "$ANDROID_HOME/build-tools" -name aapt2 -type f | sort -V | tail -1)"
+ test -x "$AAPT" || { echo "::error::No aapt2 under $ANDROID_HOME/build-tools"; exit 1; }
+ BADGING="$("$AAPT" dump badging "$APK")"
+ echo "$BADGING" | head -1
+ # The whole point of stamping: an APK whose versionName doesn't match the tag it
+ # ships under is the bug this replaced. Never let one out again.
+ echo "$BADGING" | grep -q "versionName='$VERSION'" \
+ || { echo "::error::APK versionName is not $VERSION"; exit 1; }
+ # The user-CA / cleartext policy from #79 is a native config: if the plugin
+ # silently stops applying, self-hosted servers break and only a device test
+ # would catch it. Fail the release here instead.
+ "$AAPT" dump xmltree --file AndroidManifest.xml "$APK" | grep -q networkSecurityConfig \
+ || { echo "::error::APK has no networkSecurityConfig — see issue #79"; exit 1; }
- - name: Download the APK
- run: curl -fL -o "lyftr-${{ github.ref_name }}.apk" "$APK_URL"
+ # Always keep a copy on the run itself: it's the only artifact a dry run produces,
+ # and on a real release it's a fallback if the upload below fails.
+ - uses: actions/upload-artifact@v4
+ with:
+ name: ${{ steps.ver.outputs.name }}
+ path: ${{ steps.ver.outputs.name }}
+ retention-days: 14
+ if-no-files-found: error
- name: Attach APK to the GitHub Release
+ if: github.event_name == 'push'
uses: softprops/action-gh-release@v2
with:
- files: lyftr-${{ github.ref_name }}.apk
+ files: ${{ steps.ver.outputs.name }}
make_latest: false # everything currently ships as a prerelease; revisit once a stable tag lands
prerelease: true # Android betas ship as prereleases (like the web betas)
generate_release_notes: true
@@ -155,7 +277,7 @@ jobs:
append_body: true
body: |
### Android (side-load)
- Download `lyftr-${{ github.ref_name }}.apk` below. On your phone, open it and
+ Download `${{ steps.ver.outputs.name }}` below. On your phone, open it and
allow "install from unknown sources" if prompted.
> iOS is distributed via TestFlight / the App Store (Apple doesn't allow
diff --git a/RELEASING.md b/RELEASING.md
index b3d4394..cd418de 100644
--- a/RELEASING.md
+++ b/RELEASING.md
@@ -20,8 +20,44 @@ Pushing the tag triggers two workflows:
- **`ci.yml`** — builds and pushes the backend/frontend Docker images tagged
with this version (`git describe --tags`).
-- **`eas-build.yml`** — builds the Android APK on EAS and attaches it to the
- GitHub Release for this tag (takes a while; EAS build + APK download).
+- **`eas-build.yml`** — builds the Android APK on the runner (`eas build --local`,
+ so there's no hosted-EAS queue to wait behind) and attaches it to the GitHub
+ Release for this tag. Budget ~30-45 min; it's a full Gradle build.
+
+ To rehearse that build without publishing anything — after touching the mobile
+ native config, say — run the workflow manually with **dry_run_release** checked.
+ It builds the same APK and leaves it as a workflow artifact, touching no Release.
+
+## Mobile version numbers
+
+The tag is the version, on every platform. Before tagging, bump `expo.version` in
+`mobile/app.json` to match the tag you're about to push (tag `v0.4.0` → version
+`0.4.0`). CI also stamps it from the tag at build time, so a forgotten bump can't
+ship a mismatched APK — but the repo shouldn't be lying either.
+
+`versionCode` is a separate monotonic counter tracked on EAS
+(`appVersionSource: remote`), bumped per build and never reset — the same split
+Immich uses (`3.1.0+3057`). Android upgrades are gated on this number, not on the
+version name. Don't hand-edit it to bump a release.
+
+The `versionCode` still in `app.json` was only a seed: EAS initializes the remote
+counter from the app config the first time it builds under `remote`, and this
+project had no remote version configured. It was set to `4`, the highest already
+published. **That initialization has already happened** — the counter now lives on
+EAS and stands at `5`, so the field is inert and the CLI says so on every build.
+Note that dry runs share the counter, so release numbers will have gaps.
+
+To inspect or correct it:
+
+```bash
+cd mobile
+npx eas-cli build:version:get -p android
+npx eas-cli build:version:set -p android # only to repair drift
+```
+
+Note the version *name* may move backwards if the unified tag is below the mobile
+app's old independent numbering — that's cosmetic. What must never go backwards is
+`versionCode`, or Android will refuse the upgrade.
Neither workflow deploys the demo off a tag — that already happens on every
push to `main` (see `deploy-demo` in `ci.yml`). Tags exist purely to version
diff --git a/mobile/app.json b/mobile/app.json
index 85a1143..3a890eb 100644
--- a/mobile/app.json
+++ b/mobile/app.json
@@ -32,7 +32,7 @@
"permissions": [
"android.permission.CAMERA"
],
- "versionCode": 3
+ "versionCode": 4
},
"web": {
"bundler": "metro",
diff --git a/mobile/eas.json b/mobile/eas.json
index cfccd1c..6148b3d 100644
--- a/mobile/eas.json
+++ b/mobile/eas.json
@@ -1,7 +1,7 @@
{
"cli": {
"version": ">= 12.0.0",
- "appVersionSource": "local"
+ "appVersionSource": "remote"
},
"build": {
"development": {