Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/scripts/verify-android-aab-signature.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail

if [[ $# -ne 2 ]]; then
echo "Usage: $0 <aab> <expected-certificate-sha256>" >&2
exit 2
fi

aab_path="$1"
expected_sha256="$(printf '%s' "$2" | tr -d ':' | tr '[:upper:]' '[:lower:]')"

if [[ ! -f "$aab_path" ]]; then
echo "Release artifact not found: $aab_path" >&2
exit 1
fi

if ! jarsigner -verify -certs "$aab_path" >/dev/null 2>&1; then
echo "AAB signature verification failed." >&2
jarsigner -verify -certs "$aab_path"
exit 1
fi

aab_sha256="$({ keytool -printcert -jarfile "$aab_path"; } | awk -F': ' '/SHA256:/{print $NF; exit}' | tr -d ':' | tr '[:upper:]' '[:lower:]')"
if [[ -z "$aab_sha256" || "$aab_sha256" != "$expected_sha256" ]]; then
echo "AAB signer does not match the expected upload certificate." >&2
exit 1
fi

echo "AAB signature verified with the expected upload certificate."
18 changes: 3 additions & 15 deletions .github/scripts/verify-android-release-signatures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,12 @@ aab_path="$1"
apk_path="$2"
expected_sha256="$(printf '%s' "$3" | tr -d ':' | tr '[:upper:]' '[:lower:]')"

for artifact_path in "$aab_path" "$apk_path"; do
if [[ ! -f "$artifact_path" ]]; then
echo "Release artifact not found: $artifact_path" >&2
exit 1
fi
done

if ! jarsigner -verify -certs "$aab_path" >/dev/null 2>&1; then
echo "AAB signature verification failed." >&2
jarsigner -verify -certs "$aab_path"
if [[ ! -f "$apk_path" ]]; then
echo "Release artifact not found: $apk_path" >&2
exit 1
fi

aab_sha256="$({ keytool -printcert -jarfile "$aab_path"; } | awk -F': ' '/SHA256:/{print $NF; exit}' | tr -d ':' | tr '[:upper:]' '[:lower:]')"
if [[ -z "$aab_sha256" || "$aab_sha256" != "$expected_sha256" ]]; then
echo "AAB signer does not match the expected upload certificate." >&2
exit 1
fi
"$(dirname "$0")/verify-android-aab-signature.sh" "$aab_path" "$3"

apksigner_path="$(find "$ANDROID_HOME/build-tools" -type f -name apksigner -print | sort -V | tail -n 1)"
if [[ -z "$apksigner_path" ]]; then
Expand Down
136 changes: 136 additions & 0 deletions .github/workflows/android-app-distribution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Android App Distribution

on:
push:
branches:
- main

permissions:
contents: read

concurrency:
group: android-app-distribution
cancel-in-progress: false

jobs:
distribute:
if: github.ref == 'refs/heads/main'
runs-on: blacksmith-4vcpu-ubuntu-2404
environment: android-release
defaults:
run:
working-directory: android
env:
FIREBASE_APP_ID: 1:569439646238:android:593114316e11ddb48df40f
FIREBASE_TESTER_GROUP: android-internal
FIREBASE_TOOLS_VERSION: 15.24.0
EXPECTED_UPLOAD_CERT_SHA256: 9E:FB:99:19:6B:2D:F6:56:FD:FA:1D:88:3D:33:00:7E:0F:E0:DA:28:AB:FF:A6:F8:BC:C3:3D:42:0F:CA:E1:37

steps:
- name: Checkout merged commit
uses: actions/checkout@v4

- name: Set distribution version
shell: bash
run: |
set -euo pipefail
version_code=$((1000000000 + GITHUB_RUN_NUMBER))
if (( version_code > 2100000000 )); then
echo "App Distribution versionCode exceeds the Google Play limit." >&2
exit 1
fi
echo "ANDROID_VERSION_CODE=$version_code" >> "$GITHUB_ENV"
echo "ANDROID_VERSION_NAME=0.1.0-merge.$GITHUB_RUN_NUMBER" >> "$GITHUB_ENV"

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4

- name: Prepare protected credentials
shell: bash
env:
ANDROID_UPLOAD_KEYSTORE_BASE64: ${{ secrets.ANDROID_UPLOAD_KEYSTORE_BASE64 }}
FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_JSON: ${{ secrets.FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_JSON }}
run: |
set -euo pipefail
keystore_path="$RUNNER_TEMP/opencode-mobile-upload.jks"
firebase_credentials_path="$RUNNER_TEMP/firebase-app-distribution.json"
printf '%s' "$ANDROID_UPLOAD_KEYSTORE_BASE64" | base64 --decode > "$keystore_path"
printf '%s' "$FIREBASE_APP_DISTRIBUTION_SERVICE_ACCOUNT_JSON" > "$firebase_credentials_path"
chmod 600 "$keystore_path" "$firebase_credentials_path"
echo "ANDROID_UPLOAD_KEYSTORE_PATH=$keystore_path" >> "$GITHUB_ENV"
echo "GOOGLE_APPLICATION_CREDENTIALS=$firebase_credentials_path" >> "$GITHUB_ENV"

- name: Build signed App Bundle
env:
ANDROID_UPLOAD_STORE_PASSWORD: ${{ secrets.ANDROID_UPLOAD_STORE_PASSWORD }}
ANDROID_UPLOAD_KEY_ALIAS: ${{ secrets.ANDROID_UPLOAD_KEY_ALIAS }}
ANDROID_UPLOAD_KEY_PASSWORD: ${{ secrets.ANDROID_UPLOAD_KEY_PASSWORD }}
run: ./gradlew :app:bundleRelease --stacktrace

- name: Verify App Bundle signature
working-directory: .
run: |
.github/scripts/verify-android-aab-signature.sh \
android/app/build/outputs/bundle/release/app-release.aab \
"$EXPECTED_UPLOAD_CERT_SHA256"

- name: Upload signed App Bundle artifact
uses: actions/upload-artifact@v4
with:
name: android-app-distribution-${{ github.sha }}-${{ github.run_number }}
path: android/app/build/outputs/bundle/release/app-release.aab
if-no-files-found: error
retention-days: 7

- name: Distribute to Firebase tester group
shell: bash
run: |
set -euo pipefail
short_sha="$(git rev-parse --short=12 HEAD)"
subject="$(git log -1 --pretty=%s)"
release_notes="Merge $short_sha: $subject"
if ! distribution_output="$(
npx --yes "firebase-tools@$FIREBASE_TOOLS_VERSION" \
appdistribution:distribute \
app/build/outputs/bundle/release/app-release.aab \
--app "$FIREBASE_APP_ID" \
--groups "$FIREBASE_TESTER_GROUP" \
--release-notes "$release_notes" \
2>&1
)"; then
printf '%s\n' "$distribution_output"
exit 1
fi
firebase_console_uri="$(
sed -n 's/^.*View this release in the Firebase console: //p' <<<"$distribution_output" | tail -n 1
)"
testing_uri="$(
sed -n 's/^.*Share this release with testers who have access: //p' <<<"$distribution_output" | tail -n 1
)"
if [[ -z "$firebase_console_uri" || -z "$testing_uri" ]]; then
echo "Firebase CLI did not return the expected stable release links." >&2
exit 1
fi
{
echo "## Android App Distribution"
echo
echo "- Commit: \`$GITHUB_SHA\`"
echo "- Version: \`$ANDROID_VERSION_NAME\` (\`$ANDROID_VERSION_CODE\`)"
echo "- Tester group: \`$FIREBASE_TESTER_GROUP\`"
echo "- [Firebase release]($firebase_console_uri)"
echo "- [Open in the tester experience]($testing_uri)"
} >> "$GITHUB_STEP_SUMMARY"

- name: Remove temporary credentials
if: always()
shell: bash
run: |
rm -f \
"$RUNNER_TEMP/opencode-mobile-upload.jks" \
"$RUNNER_TEMP/firebase-app-distribution.json"
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ skipped). Android Build and iOS Build stay manual.
| iOS Checks | PR (non-draft) + dispatch | Build, analyzer, unit tests |
| Android Build | `workflow_dispatch` | Assemble debug APK |
| Android Release | `workflow_dispatch` on `main` | Build and verify signed AAB + APK, then publish to Play internal |
| Android App Distribution | `push` to `main` | Build and verify a signed AAB, then distribute it to the private Firebase tester group |
| Android Test Lab | `workflow_dispatch` on `main` | Run bounded Robo tests against a signed release APK |
| iOS Build | `workflow_dispatch` | Simulator build |

Expand All @@ -83,8 +84,8 @@ gh workflow run "Android Release" --ref main -f version_name=0.1.0
gh workflow run "Android Test Lab" --ref main -f release_run_id=<android-release-run-id>
```

Android Release and Android Test Lab use the protected `android-release`
environment. See the
Android Release, Android App Distribution, and Android Test Lab use the
protected `android-release` environment. See the
[Android release operator runbook](docs/features/android-release-distribution/operator-runbook.md)
for secrets, artifacts, Play internal testing, Test Lab, and recovery
instructions.
Expand Down
24 changes: 24 additions & 0 deletions docs/features/android-release-distribution/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,27 @@ Developer account exists.
**Why:** Android distribution should not wait on unavailable Apple account
infrastructure. The intentional difference remains recorded in
[`parity-gaps.md`](parity-gaps.md).

## Separate Firebase App Distribution install channel

**Status:** Accepted for OPE-73 implementation

**Decision:** Distribute AABs through Firebase App Distribution and Google Play
internal app sharing. Treat this as a separate install channel from the Play
internal testing track. The owner uninstalls the Play-internal build once before
installing the first Firebase build; later Firebase builds update within that
channel.

**Why:** Google Play re-signs internal-app-sharing APKs with a dedicated test
certificate that differs from the normal Play app-signing certificate. An
in-place update across those certificates is not possible. AAB delivery still
provides device-specific APKs and a stable certificate for subsequent private
tester updates.

**Versioning:** Use `1000000000 + github.run_number` for the App Distribution
workflow. The reserved high range is monotonic inside this channel and remains
separate from the canonical Play release workflow's version sequence.

**Revisit when:** Firebase supports delivery with the normal Play app-signing
certificate or the project replaces App Distribution with a Play testing-track
release on every merge.
136 changes: 136 additions & 0 deletions docs/features/android-release-distribution/ope-73-plan.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OPE-73 — Firebase App Distribution On Every Merge</title>
<style>
:root {
color-scheme: light dark;
--bg: #f4f6f8;
--surface: #ffffff;
--text: #17202a;
--muted: #52606d;
--border: #d9e2ec;
--accent: #006b5f;
--pending: #9a6700;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #111820;
--surface: #18222d;
--text: #edf2f7;
--muted: #b8c4cf;
--border: #344454;
--accent: #62d5c5;
--pending: #f2c66d;
}
}
* { box-sizing: border-box; }
body {
margin: 0;
background: var(--bg);
color: var(--text);
font: 16px/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
main { width: min(1040px, calc(100% - 32px)); margin: 40px auto; }
h1, h2 { line-height: 1.2; }
h1 { margin-bottom: 8px; }
h2 { margin-top: 32px; }
.lead { color: var(--muted); max-width: 760px; }
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 12px;
margin: 24px 0;
}
.card, .flow-step, table {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 10px;
}
.card { padding: 16px; }
.card strong { display: block; color: var(--accent); margin-bottom: 4px; }
.flow {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
}
.flow-step { padding: 14px; }
.flow-step span { color: var(--muted); display: block; font-size: 0.9rem; }
table { width: 100%; border-collapse: separate; border-spacing: 0; overflow: hidden; }
th, td { padding: 12px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: 0; }
.pending { color: var(--pending); font-weight: 700; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
a { color: var(--accent); }
@media (max-width: 760px) { .flow { grid-template-columns: 1fr; } }
</style>
</head>
<body>
<main>
<h1>OPE-73 — Firebase App Distribution On Every Merge</h1>
<p class="lead">
Every successful merge to <code>main</code> produces one AAB and distributes
it to the private <code>android-internal</code> tester group without publishing
another Play testing-track release.
</p>

<section class="cards" aria-label="Plan summary">
<div class="card"><strong>Trigger</strong>Every push to protected <code>main</code></div>
<div class="card"><strong>Artifact</strong>Signed Android App Bundle</div>
<div class="card"><strong>Audience</strong>Private <code>android-internal</code> group</div>
<div class="card"><strong>Status</strong><span class="ok">Ready for first run</span></div>
</section>

<h2>Delivery flow</h2>
<div class="flow">
<div class="flow-step"><strong>1. Merge</strong><span>Exact commit lands on main</span></div>
<div class="flow-step"><strong>2. Build</strong><span>Protected CI signs and verifies the AAB</span></div>
<div class="flow-step"><strong>3. Distribute</strong><span>Firebase uploads through Play internal app sharing</span></div>
<div class="flow-step"><strong>4. Install</strong><span>Private tester receives the Play-generated build</span></div>
</div>

<h2>Checkpoints</h2>
<table>
<thead><tr><th>Checkpoint</th><th>Required result</th><th>Status</th></tr></thead>
<tbody>
<tr>
<td>Owner setup</td>
<td>Link Firebase to Play; create the private group, dedicated App Distribution service account, JSON key, and protected GitHub secret.</td>
<td class="ok">Complete</td>
</tr>
<tr>
<td>Agent implementation</td>
<td>Add the main-push workflow, signing and signature verification, AAB upload, release notes, summaries, serialization, and cleanup.</td>
<td class="ok">Implemented</td>
</tr>
<tr>
<td>Acceptance</td>
<td>One merged build reaches Firebase, targets the private group, and installs through the tester flow without a Play-track release.</td>
<td class="pending">Not started</td>
</tr>
</tbody>
</table>

<h2>Boundaries and risks</h2>
<table>
<thead><tr><th>Topic</th><th>Contract</th></tr></thead>
<tbody>
<tr><td>Signing</td><td>Upload-key-signed AAB; internal app sharing generates APKs with a separate test certificate. The first Firebase install requires uninstalling the Play-internal build.</td></tr>
<tr><td>Versioning</td><td>App Distribution reserves <code>1000000000 + run_number</code> for monotonic updates inside its separate tester channel.</td></tr>
<tr><td>Credentials</td><td>Dedicated Firebase App Distribution Admin identity in the protected environment; PRs receive no credentials.</td></tr>
<tr><td>Run ordering</td><td>Serialize without cancellation so a later merge cannot suppress an earlier distribution.</td></tr>
<tr><td>Failure</td><td>A failed distribution fails the workflow but does not revert the merge.</td></tr>
<tr><td>Excluded</td><td>No public invite, runtime SDK, in-app alert, feedback UI, extra Play-track release, Test Lab trigger, or iOS work.</td></tr>
</tbody>
</table>

<p>
Source of truth: <a href="./ope-73-plan.md">ope-73-plan.md</a> ·
Linear: <a href="https://linear.app/opencode-mobile/issue/OPE-73/distribute-every-merged-android-build-through-firebase-app">OPE-73</a>
</p>
</main>
</body>
</html>
Loading
Loading