Skip to content

Agent Mesh

mobile: build Google Play bundles and publish on demand

Antonio Ojea1d29e80ea06c
diff --git a/.github/workflows/mobile.yml b/.github/workflows/mobile.yml
new file mode 100644
index 00000000..3b3daa5e
--- /dev/null
+++ b/.github/workflows/mobile.yml
@@ -0,0 +1,212 @@
+name: Mobile App
+
+# Builds SAM Connect (Android) on every release tag, in parallel with the
+# goreleaser workflow that publishes the Go binaries, and on demand from any
+# ref. A dispatch may also publish the bundle to a Google Play track, keyless
+# via Workload Identity Federation: repository variables
+# WIF_PROVIDER_NAME_APP_STORE / SERVICE_ACCOUNT_EMAIL_APP_STORE name a
+# service account invited in Play Console with release rights.
+#
+# Play needs a strictly increasing versionCode. It defaults to this
+# workflow's run number, which is tied to this file's path: renaming the
+# file resets the counter, so override build_number if that ever happens.
+
+on:
+ push:
+ tags:
+ - "v*"
+ workflow_dispatch:
+ inputs:
+ track:
+ description: 'Google Play track to publish to (none = build only)'
+ type: choice
+ options: [none, internal, alpha, beta, production]
+ default: none
+ build_number:
+ description: 'Android versionCode (default: this workflow run number)'
+ type: string
+ default: ''
+
+run-name: "mobile ${{ github.ref_name }}${{ inputs.track && format(' ({0})', inputs.track) || '' }} by ${{ github.actor }}"
+
+permissions: {}
+
+env:
+ APP_DIR: mobile/sam-node-app
+ PACKAGE_NAME: dev.sammesh.connect
+
+jobs:
+ build:
+ name: Build APK and bundle
+ runs-on: ubuntu-latest
+ timeout-minutes: 45
+ permissions:
+ contents: read
+ outputs:
+ bundle: ${{ steps.upload-key.outputs.present }}
+ steps:
+ - name: Checkout
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ fetch-depth: 0
+ persist-credentials: false
+ - name: Set up Go
+ uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
+ with:
+ go-version: stable
+ cache: false
+ - name: Set up Java
+ uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
+ with:
+ distribution: 'temurin'
+ java-version: '17'
+ - name: Set up Android NDK
+ run: |
+ yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses
+ $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "ndk;26.1.10909125"
+ - name: Set up Flutter
+ uses: subosito/flutter-action@1a449444c387b1966244ae4d4f8c696479add0b2 # v2
+ with:
+ channel: 'stable'
+ cache: true
+
+ - name: Determine version
+ env:
+ REF_TYPE: ${{ github.ref_type }}
+ REF_NAME: ${{ github.ref_name }}
+ INPUT_BUILD_NUMBER: ${{ inputs.build_number }}
+ RUN_NUMBER: ${{ github.run_number }}
+ run: |
+ if [[ "${REF_TYPE}" == "tag" ]]; then
+ name="${REF_NAME#v}"
+ else
+ name="$(git describe --tags --always)"; name="${name#v}"
+ fi
+ number="${INPUT_BUILD_NUMBER:-${RUN_NUMBER}}"
+ if ! [[ "${number}" =~ ^[0-9]+$ ]]; then
+ echo "::error::build_number must be a positive integer (got '${number}')"; exit 1
+ fi
+ echo "MOBILE_BUILD_NAME=${name}" >> "$GITHUB_ENV"
+ echo "MOBILE_BUILD_NUMBER=${number}" >> "$GITHUB_ENV"
+ echo "Building ${name} (versionCode ${number})"
+
+ - name: Install upload key
+ # Step-level `if` cannot read `secrets`, so surface presence as an output.
+ # The key signs both the APK and the bundle when present; without it the
+ # APK falls back to the debug key and the bundle is skipped.
+ id: upload-key
+ env:
+ ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
+ run: |
+ if [[ -z "${ANDROID_KEYSTORE_BASE64}" ]]; then
+ echo "present=false" >> "$GITHUB_OUTPUT"
+ echo "::notice::ANDROID_KEYSTORE_BASE64 not set; skipping the Google Play bundle."
+ exit 0
+ fi
+ path="$RUNNER_TEMP/upload-keystore.jks"
+ echo "${ANDROID_KEYSTORE_BASE64}" | base64 --decode > "${path}"
+ echo "ANDROID_KEYSTORE_PATH=${path}" >> "$GITHUB_ENV"
+ echo "present=true" >> "$GITHUB_OUTPUT"
+ - name: Refuse to publish without an upload key
+ if: github.event_name == 'workflow_dispatch' && inputs.track != 'none' && steps.upload-key.outputs.present != 'true'
+ run: |
+ echo "::error::Publishing to Google Play needs the ANDROID_KEYSTORE_BASE64 / ANDROID_KEYSTORE_PASSWORD / ANDROID_KEY_ALIAS / ANDROID_KEY_PASSWORD secrets."
+ exit 1
+
+ - name: Build APK
+ env:
+ GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}
+ ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
+ ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
+ ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
+ run: make mobile-app-apk
+ - name: Build Google Play bundle
+ if: steps.upload-key.outputs.present == 'true'
+ env:
+ GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}
+ ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
+ ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
+ ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
+ run: make mobile-app-bundle
+ - name: Remove upload key
+ if: always() && steps.upload-key.outputs.present == 'true'
+ run: rm -f "$ANDROID_KEYSTORE_PATH"
+
+ - name: Upload APK artifact
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: sam-connect-apk
+ path: ${{ env.APP_DIR }}/build/app/outputs/flutter-apk/app-release.apk
+ if-no-files-found: error
+ - name: Upload bundle artifact
+ if: steps.upload-key.outputs.present == 'true'
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: sam-connect-aab
+ path: ${{ env.APP_DIR }}/build/app/outputs/bundle/release/app-release.aab
+ if-no-files-found: error
+
+ attach-to-release:
+ name: Attach to GitHub release
+ if: github.ref_type == 'tag'
+ needs: build
+ runs-on: ubuntu-latest
+ timeout-minutes: 40
+ permissions:
+ contents: write
+ steps:
+ - name: Download artifacts
+ uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
+ with:
+ pattern: sam-connect-*
+ merge-multiple: true
+ path: dist
+ - name: Upload to release
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ GH_REPO: ${{ github.repository }}
+ TAG_NAME: ${{ github.ref_name }}
+ run: |
+ # The goreleaser workflow creates the release from the same tag push;
+ # wait for it rather than racing to create one ourselves.
+ for _ in $(seq 1 60); do
+ gh release view "$TAG_NAME" >/dev/null 2>&1 && break
+ echo "waiting for release $TAG_NAME to be created by goreleaser..."; sleep 30
+ done
+ gh release view "$TAG_NAME" >/dev/null
+ gh release upload "$TAG_NAME" dist/* --clobber
+
+ publish:
+ name: Publish to Google Play (${{ inputs.track }})
+ if: github.event_name == 'workflow_dispatch' && inputs.track != 'none'
+ needs: build
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+ permissions:
+ contents: read
+ id-token: write
+ steps:
+ - name: Checkout
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ sparse-checkout: hack/publish-play.sh
+ sparse-checkout-cone-mode: false
+ - name: Download bundle
+ uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
+ with:
+ name: sam-connect-aab
+ path: dist
+ - name: Google Auth
+ id: auth
+ uses: google-github-actions/auth@c200f3691d83b41bf9bbd8638997a462592937ed # v2
+ with:
+ workload_identity_provider: ${{ vars.WIF_PROVIDER_NAME_APP_STORE }}
+ service_account: ${{ vars.SERVICE_ACCOUNT_EMAIL_APP_STORE }}
+ token_format: access_token
+ access_token_scopes: https://www.googleapis.com/auth/androidpublisher
+ - name: Upload to track
+ env:
+ PLAY_ACCESS_TOKEN: ${{ steps.auth.outputs.access_token }}
+ TRACK: ${{ inputs.track }}
+ run: ./hack/publish-play.sh "$PACKAGE_NAME" "$TRACK" dist/app-release.aab
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 24669b87..3c9c27aa 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -25,33 +25,9 @@ jobs:
with:
go-version: stable
cache: false
- - name: Set up Java
- uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
- with:
- distribution: 'temurin'
- java-version: '17'
- - name: Set up Android NDK
- run: |
- yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses
- $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "ndk;26.1.10909125"
- - name: Set up Flutter
- uses: subosito/flutter-action@1a449444c387b1966244ae4d4f8c696479add0b2 # v2
- with:
- channel: 'stable'
- - name: Build Mobile App
- env:
- GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}
- GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
- run: make mobile-app-apk
- - name: Restore files rewritten by the Flutter build
- # `flutter build` re-resolves pubspec.lock (and may rewrite
- # analysis_options.yaml), leaving the tree dirty and failing
- # GoReleaser's git state validation. Build outputs are untracked, so
- # restoring tracked files keeps the APK available for the upload step.
- run: |
- git -C mobile/sam-node-app checkout -- .
- git status --porcelain
- name: Run GoReleaser
+ # The mobile app is built and attached to this release by the
+ # parallel "Mobile App" workflow (.github/workflows/mobile.yml).
uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7.2.3
with:
distribution: goreleaser
@@ -59,9 +35,3 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- - name: Upload Mobile App to Release
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- GH_REPO: ${{ github.repository }}
- TAG_NAME: ${{ github.ref_name }}
- run: gh release upload "$TAG_NAME" mobile/sam-node-app/build/app/outputs/flutter-apk/app-release.apk --clobber
diff --git a/.gitignore b/.gitignore
index f48c4b0e..c63f0761 100644
--- a/.gitignore
+++ b/.gitignore
@@ -61,3 +61,9 @@ mobile/logcat.txt
/rootfs.ext4
/rootfs.tar
+# Android upload keystore and Firebase config: secrets, wherever they land.
+*.jks
+*.keystore
+key.properties
+google-services.json
+
diff --git a/Makefile b/Makefile
index d1233036..41cd61d6 100644
--- a/Makefile
+++ b/Makefile
@@ -39,7 +39,7 @@ build:
go -C cmd/sam-a2a-bridge build -v -o "$(OUT_DIR)/sam-a2a-bridge" .
-.PHONY: mobile-ffi-host mobile-ffi-android mobile-ffi-android-x86_64 mobile-ffi-ios mobile-ffi mobile-app-apk mobile-app-apk-emulator
+.PHONY: mobile-ffi-host mobile-ffi-android mobile-ffi-android-x86_64 mobile-ffi-ios mobile-ffi mobile-app-apk mobile-app-apk-emulator mobile-app-bundle
mobile-ffi-host:
mkdir -p "$(OUT_DIR)"
CGO_ENABLED=1 go build -v -buildmode=c-shared -o "$(OUT_DIR)/libsam.so" ./mobile/sam-node-ffi
@@ -65,47 +65,58 @@ mobile-ffi-ios:
mobile-ffi: mobile-ffi-host mobile-ffi-android mobile-ffi-android-x86_64 mobile-ffi-ios
-mobile-app-apk: mobile-ffi-android
+MOBILE_APP_DIR=mobile/sam-node-app
+# Optional overrides of pubspec.yaml's `version: X.Y.Z+N`. Google Play rejects
+# a bundle whose versionCode (N) it has already seen, so CI passes a fresh one.
+MOBILE_BUILD_NAME?=
+MOBILE_BUILD_NUMBER?=
+MOBILE_FLUTTER_BUILD_FLAGS=$(if $(MOBILE_BUILD_NAME),--build-name=$(MOBILE_BUILD_NAME)) $(if $(MOBILE_BUILD_NUMBER),--build-number=$(MOBILE_BUILD_NUMBER))
+
+.PHONY: mobile-app-google-services
+mobile-app-google-services:
@if [ -n "$$GOOGLE_SERVICES_JSON" ]; then \
echo "Decoding google-services.json from GOOGLE_SERVICES_JSON environment variable..."; \
- echo "$$GOOGLE_SERVICES_JSON" | base64 --decode > mobile/sam-node-app/android/app/google-services.json; \
+ echo "$$GOOGLE_SERVICES_JSON" | base64 --decode > $(MOBILE_APP_DIR)/android/app/google-services.json; \
elif [ -n "$$GOOGLE_SERVICES_JSON_BASE64" ]; then \
echo "Decoding google-services.json from GOOGLE_SERVICES_JSON_BASE64 environment variable..."; \
- echo "$$GOOGLE_SERVICES_JSON_BASE64" | base64 --decode > mobile/sam-node-app/android/app/google-services.json; \
- elif [ ! -f mobile/sam-node-app/android/app/google-services.json ]; then \
- if [ -f mobile/sam-node-app/android/app/google-services.json.tmpl ]; then \
+ echo "$$GOOGLE_SERVICES_JSON_BASE64" | base64 --decode > $(MOBILE_APP_DIR)/android/app/google-services.json; \
+ elif [ ! -f $(MOBILE_APP_DIR)/android/app/google-services.json ]; then \
+ if [ -f $(MOBILE_APP_DIR)/android/app/google-services.json.tmpl ]; then \
echo "Copying google-services.json from template..."; \
- cp mobile/sam-node-app/android/app/google-services.json.tmpl mobile/sam-node-app/android/app/google-services.json; \
+ cp $(MOBILE_APP_DIR)/android/app/google-services.json.tmpl $(MOBILE_APP_DIR)/android/app/google-services.json; \
else \
echo "Error: google-services.json is missing."; \
- echo "Please set GOOGLE_SERVICES_JSON or GOOGLE_SERVICES_JSON_BASE64 environment variable with the base64-encoded configuration, or place the file directly at mobile/sam-node-app/android/app/google-services.json"; \
+ echo "Please set GOOGLE_SERVICES_JSON or GOOGLE_SERVICES_JSON_BASE64 environment variable with the base64-encoded configuration, or place the file directly at $(MOBILE_APP_DIR)/android/app/google-services.json"; \
exit 1; \
fi; \
fi
- mkdir -p mobile/sam-node-app/android/app/src/main/jniLibs/arm64-v8a
- cp "$(OUT_DIR)/android/libsam.so" mobile/sam-node-app/android/app/src/main/jniLibs/arm64-v8a/libsam.so
- cd mobile/sam-node-app && flutter build apk --release
-mobile-app-apk-emulator: mobile-ffi-android-x86_64
- @if [ -n "$$GOOGLE_SERVICES_JSON" ]; then \
- echo "Decoding google-services.json from GOOGLE_SERVICES_JSON environment variable..."; \
- echo "$$GOOGLE_SERVICES_JSON" | base64 --decode > mobile/sam-node-app/android/app/google-services.json; \
- elif [ -n "$$GOOGLE_SERVICES_JSON_BASE64" ]; then \
- echo "Decoding google-services.json from GOOGLE_SERVICES_JSON_BASE64 environment variable..."; \
- echo "$$GOOGLE_SERVICES_JSON_BASE64" | base64 --decode > mobile/sam-node-app/android/app/google-services.json; \
- elif [ ! -f mobile/sam-node-app/android/app/google-services.json ]; then \
- if [ -f mobile/sam-node-app/android/app/google-services.json.tmpl ]; then \
- echo "Copying google-services.json from template..."; \
- cp mobile/sam-node-app/android/app/google-services.json.tmpl mobile/sam-node-app/android/app/google-services.json; \
- else \
- echo "Error: google-services.json is missing."; \
- echo "Please set GOOGLE_SERVICES_JSON or GOOGLE_SERVICES_JSON_BASE64 environment variable with the base64-encoded configuration, or place the file directly at mobile/sam-node-app/android/app/google-services.json"; \
- exit 1; \
- fi; \
+.PHONY: mobile-app-jnilibs-arm64
+mobile-app-jnilibs-arm64: mobile-ffi-android
+ mkdir -p $(MOBILE_APP_DIR)/android/app/src/main/jniLibs/arm64-v8a
+ cp "$(OUT_DIR)/android/libsam.so" $(MOBILE_APP_DIR)/android/app/src/main/jniLibs/arm64-v8a/libsam.so
+
+mobile-app-apk: mobile-app-jnilibs-arm64 mobile-app-google-services
+ cd $(MOBILE_APP_DIR) && flutter build apk --release $(MOBILE_FLUTTER_BUILD_FLAGS)
+
+mobile-app-apk-emulator: mobile-ffi-android-x86_64 mobile-app-google-services
+ mkdir -p $(MOBILE_APP_DIR)/android/app/src/main/jniLibs/x86_64
+ cp "$(OUT_DIR)/android-x86_64/libsam.so" $(MOBILE_APP_DIR)/android/app/src/main/jniLibs/x86_64/libsam.so
+ cd $(MOBILE_APP_DIR) && flutter build apk --release $(MOBILE_FLUTTER_BUILD_FLAGS)
+
+# Android App Bundle for Google Play. Play rejects debug-signed bundles, so an
+# upload key is required: either $(MOBILE_APP_DIR)/android/key.properties or
+# the ANDROID_KEYSTORE_PATH / ANDROID_KEYSTORE_PASSWORD / ANDROID_KEY_ALIAS /
+# ANDROID_KEY_PASSWORD environment variables (see mobile/sam-node-app/README.md).
+.PHONY: mobile-app-bundle
+mobile-app-bundle: mobile-app-jnilibs-arm64 mobile-app-google-services
+ @if [ ! -f $(MOBILE_APP_DIR)/android/key.properties ] && [ -z "$$ANDROID_KEYSTORE_PATH" ]; then \
+ echo "Error: no upload key configured; Google Play rejects debug-signed bundles." >&2; \
+ echo "Create $(MOBILE_APP_DIR)/android/key.properties or export ANDROID_KEYSTORE_PATH, ANDROID_KEYSTORE_PASSWORD, ANDROID_KEY_ALIAS and ANDROID_KEY_PASSWORD. See $(MOBILE_APP_DIR)/README.md#publishing-to-google-play." >&2; \
+ exit 1; \
fi
- mkdir -p mobile/sam-node-app/android/app/src/main/jniLibs/x86_64
- cp "$(OUT_DIR)/android-x86_64/libsam.so" mobile/sam-node-app/android/app/src/main/jniLibs/x86_64/libsam.so
- cd mobile/sam-node-app && flutter build apk --release
+ cd $(MOBILE_APP_DIR) && flutter build appbundle --release $(MOBILE_FLUTTER_BUILD_FLAGS)
+ @echo "Bundle: $(MOBILE_APP_DIR)/build/app/outputs/bundle/release/app-release.aab"
.PHONY: proto
proto:
diff --git a/hack/publish-play.sh b/hack/publish-play.sh
new file mode 100755
index 00000000..248a0a00
--- /dev/null
+++ b/hack/publish-play.sh
@@ -0,0 +1,70 @@
+#!/usr/bin/env bash
+# Copyright 2026 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Uploads an Android App Bundle to a Google Play track with the Play
+# Developer Publishing API: open an edit, upload the bundle, point the track
+# at the new versionCode, commit. Four calls, no SDK.
+#
+# Auth is a bearer token in PLAY_ACCESS_TOKEN, minted for the
+# https://www.googleapis.com/auth/androidpublisher scope by a service account
+# that Play Console lists under "Users and permissions" with release rights.
+# The token reaches curl through a header file, never through argv.
+#
+# usage: publish-play.sh <package-name> <track> <bundle.aab>
+
+set -o errexit
+set -o nounset
+set -o pipefail
+
+if [[ $# -ne 3 ]]; then
+ echo "usage: $0 <package-name> <track> <bundle.aab>" >&2
+ exit 2
+fi
+package=$1
+track=$2
+bundle=$3
+
+: "${PLAY_ACCESS_TOKEN:?PLAY_ACCESS_TOKEN must hold an androidpublisher access token}"
+[[ -f "${bundle}" ]] || { echo "bundle not found: ${bundle}" >&2; exit 1; }
+case "${track}" in
+ internal|alpha|beta|production) ;;
+ *) echo "track must be internal, alpha, beta or production (got '${track}')" >&2; exit 1 ;;
+esac
+
+api="https://androidpublisher.googleapis.com/androidpublisher/v3/applications/${package}"
+upload="https://androidpublisher.googleapis.com/upload/androidpublisher/v3/applications/${package}"
+
+auth_header=$(mktemp)
+trap 'rm -f "${auth_header}"' EXIT
+chmod 0600 "${auth_header}"
+printf 'Authorization: Bearer %s\n' "${PLAY_ACCESS_TOKEN}" > "${auth_header}"
+
+play() {
+ curl --silent --show-error --fail-with-body --header "@${auth_header}" "$@"
+}
+
+edit_id=$(play -X POST "${api}/edits" -H 'Content-Type: application/json' -d '{}' | jq -r .id)
+echo "opened edit ${edit_id}"
+
+version_code=$(play -X POST "${upload}/edits/${edit_id}/bundles?uploadType=media" \
+ -H 'Content-Type: application/octet-stream' --data-binary "@${bundle}" | jq -r .versionCode)
+echo "uploaded ${bundle} as versionCode ${version_code}"
+
+release=$(jq -nc --arg track "${track}" --arg vc "${version_code}" \
+ '{track: $track, releases: [{versionCodes: [$vc], status: "completed"}]}')
+play -X PUT "${api}/edits/${edit_id}/tracks/${track}" -H 'Content-Type: application/json' -d "${release}" >/dev/null
+
+play -X POST "${api}/edits/${edit_id}:commit" >/dev/null
+echo "published ${package} versionCode ${version_code} to the ${track} track"
diff --git a/mobile/sam-node-app/README.md b/mobile/sam-node-app/README.md
index e46d4d5b..8432bfa5 100644
--- a/mobile/sam-node-app/README.md
+++ b/mobile/sam-node-app/README.md
@@ -56,6 +56,41 @@ cd mobile/sam-node-app
flutter run
```
+### 3. Publishing to Google Play
+
+Google Play takes an Android App Bundle (`.aab`) signed with an **upload key**; it rejects the debug key that `make mobile-app-apk` falls back to. Set the key up once:
+
+1. Create the upload keystore outside the repository (`*.jks` and `key.properties` are git-ignored anyway, but keep it out of the tree). `keytool` prompts for the passwords, so they never appear in a shell history:
+ ```bash
+ keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload
+ ```
+ Back the file up: with [Play App Signing](https://support.google.com/googleplay/android-developer/answer/9842756) Google holds the app signing key and this is only the upload key, but losing it still means a key-reset request.
+2. Tell Gradle where it is, in `mobile/sam-node-app/android/key.properties`:
+ ```properties
+ storeFile=/home/you/upload-keystore.jks
+ storePassword=...
+ keyAlias=upload
+ keyPassword=...
+ ```
+ CI uses the equivalent environment variables instead of a file: `ANDROID_KEYSTORE_PATH`, `ANDROID_KEYSTORE_PASSWORD`, `ANDROID_KEY_ALIAS`, `ANDROID_KEY_PASSWORD`.
+3. Build from the repository root:
+ ```bash
+ make mobile-app-bundle MOBILE_BUILD_NAME=1.2.3 MOBILE_BUILD_NUMBER=42
+ ```
+ The bundle lands in `mobile/sam-node-app/build/app/outputs/bundle/release/app-release.aab`. `MOBILE_BUILD_NAME`/`MOBILE_BUILD_NUMBER` override the `version: X.Y.Z+N` in `pubspec.yaml`; Play refuses a `versionCode` (`N`) it has already seen, so bump it on every upload.
+4. Upload the `.aab` in the Play Console (**Release → Testing/Production → Create new release**).
+
+#### From CI
+
+The **Mobile App** workflow ([`.github/workflows/mobile.yml`](../../.github/workflows/mobile.yml)) builds the APK and, when the upload key is configured, the bundle:
+
+* **On every `v*` tag**, in parallel with the goreleaser workflow that ships the Go binaries; both artifacts are attached to the GitHub release, the tag supplies the version name.
+* **On demand** (**Actions → Mobile App → Run workflow**) from any branch or tag. Pick a Google Play **track** (`internal`, `alpha`, `beta`, `production`) to publish the bundle after the build, or leave `none` to only build; the APK and `.aab` are always available as run artifacts. `build_number` overrides the versionCode, which otherwise is the workflow run number.
+
+Repository secrets for signing: `ANDROID_KEYSTORE_BASE64` (`base64 -w0 upload-keystore.jks`), `ANDROID_KEYSTORE_PASSWORD`, `ANDROID_KEY_ALIAS`, `ANDROID_KEY_PASSWORD` — the values you chose when running `keytool` above. Without them the APK is debug-signed and the bundle is skipped. `GOOGLE_SERVICES_JSON_BASE64` is the base64 of the `google-services.json` downloaded from the Firebase Console (*Project settings → Your apps → dev.sammesh.connect*); without it the build uses the dummy template and Firebase features fail at runtime.
+
+Publishing is keyless: [`hack/publish-play.sh`](../../hack/publish-play.sh) drives the Play Developer API with a short-lived token minted through Workload Identity Federation from the repository variables `WIF_PROVIDER_NAME_APP_STORE` and `SERVICE_ACCOUNT_EMAIL_APP_STORE`. That service account must be invited in **Play Console → Users and permissions** with *Release to production / testing tracks* rights on the app, and the very first release of a new app still has to go through the console (the API cannot create the app listing).
+
---
## How to Use the Application
diff --git a/mobile/sam-node-app/android/app/build.gradle.kts b/mobile/sam-node-app/android/app/build.gradle.kts
index 80293a0b..029ff835 100644
--- a/mobile/sam-node-app/android/app/build.gradle.kts
+++ b/mobile/sam-node-app/android/app/build.gradle.kts
@@ -1,3 +1,5 @@
+import java.util.Properties
+
plugins {
id("com.android.application")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
@@ -6,6 +8,23 @@ plugins {
id("com.google.devtools.ksp")
}
+// Release (Play upload) signing: android/key.properties for a workstation,
+// ANDROID_KEYSTORE_* environment variables for CI. Both are git-ignored /
+// never committed; when neither is present the build falls back to the debug
+// key so `flutter run --release` and local APKs keep working.
+val keystoreProperties = Properties().apply {
+ val f = rootProject.file("key.properties")
+ if (f.exists()) f.inputStream().use { load(it) }
+}
+fun signingValue(propertyKey: String, envKey: String): String? =
+ keystoreProperties.getProperty(propertyKey)?.takeIf { it.isNotBlank() } ?: System.getenv(envKey)?.takeIf { it.isNotBlank() }
+
+val releaseStoreFile = signingValue("storeFile", "ANDROID_KEYSTORE_PATH")
+val releaseStorePassword = signingValue("storePassword", "ANDROID_KEYSTORE_PASSWORD")
+val releaseKeyAlias = signingValue("keyAlias", "ANDROID_KEY_ALIAS")
+val releaseKeyPassword = signingValue("keyPassword", "ANDROID_KEY_PASSWORD")
+val hasReleaseSigning = listOf(releaseStoreFile, releaseStorePassword, releaseKeyAlias, releaseKeyPassword).all { it != null }
+
android {
namespace = "dev.sammesh.connect"
compileSdk = 37 // Keep as 37, Gradle usually maps this correctly, but let's check if it needs to be 37
@@ -28,9 +47,17 @@ android {
buildTypes {
release {
- // TODO: Add your own signing config for the release build.
- // Signing with the debug keys for now, so `flutter run --release` works.
- signingConfig = signingConfigs.getByName("debug")
+ if (hasReleaseSigning) {
+ signingConfig = signingConfigs.create("release") {
+ storeFile = file(releaseStoreFile!!)
+ storePassword = releaseStorePassword
+ keyAlias = releaseKeyAlias
+ keyPassword = releaseKeyPassword
+ }
+ } else {
+ logger.warn("No release signing configured (android/key.properties or ANDROID_KEYSTORE_*); signing release with the debug key.")
+ signingConfig = signingConfigs.getByName("debug")
+ }
}
}
}