rouse-context/.github/workflows/release.yml
monkopedia-coder 69a826f603
Some checks failed
Android CI / test (push) Has been cancelled
CI / Lint (push) Has been cancelled
CI / Build & Test (push) Has been cancelled
Upload the Google AAB to Play testing tracks from release.yml (#798)
* Upload the Google AAB to Play testing tracks from release.yml

Play releases were uploaded by hand. Jason set up keyless Workload Identity
Federation for a play-publisher service account limited to testing tracks;
this wires it in.

play-upload.yml (workflow_dispatch + workflow_call) downloads the -google.aab
already attached to a tag's GitHub release -- no rebuild, signing stays in
release.yml -- authenticates via google-github-actions/auth, and runs
scripts/play-upload.sh, which drives the Android Publisher v3 edit directly
with curl: insert, bundles.upload, tracks.update, validate, then commit, or
on a dry run (the default for manual runs) list tracks and delete the edit.
Any failure deletes the edit and prints the HTTP status and body. Production,
FOSS artifacts and bundles whose manifest package is not com.rousecontext are
refused before any request.

release.yml gains a play-upload job (tag pushes only, after build) calling
it with track alpha, dry_run false. The build job is untouched.

scripts/tests/play-upload-test.sh runs the script against a mock Publisher
server and is wired into ci.yml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYSPuh9bZEJkrzvnEpY1QK

* Address review on #798: push-only Play job, fail-closed dry run

- release.yml: the play-upload job now also requires
  github.event_name == 'push'. A manual dispatch of release.yml on a tag
  ref satisfies startsWith(github.ref, 'refs/tags/v') and DOES re-run
  "Create GitHub Release"; it must not also commit to Play. Comment
  corrected to say so.
- play-upload.sh: --dry-run takes a value and commits only on exactly
  `false`; omitted, empty, True, FALSE, 0, typos are all dry runs. The
  workflow passes inputs.dry_run through verbatim.
- aab_manifest.py: bounds-check 64- and 32-bit fixed fields.
- Harness: fail-closed cases (11 values + omitted + missing value) and
  truncated fixed-field cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYSPuh9bZEJkrzvnEpY1QK

---------

Co-authored-by: Monkopedia <monkopedia@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 17:50:18 -04:00

278 lines
13 KiB
YAML

name: Release
on:
push:
tags: ['v*']
workflow_dispatch:
inputs:
version:
description: 'Version tag (e.g. v1.0.0) — only used for the GitHub release title when triggered manually'
required: false
concurrency:
group: release
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write # create GitHub release + upload assets
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- name: Cache Gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-release-${{ hashFiles('**/*.gradle.kts', 'gradle/libs.versions.toml') }}
- name: Decode release keystore
run: |
mkdir -p .signing
echo "${{ secrets.RELEASE_KEYSTORE }}" | base64 -d > .signing/release.keystore
# Distribution is a build flag, not a product flavor (#467): the bare
# build is FOSS (UnifiedPush, no Firebase), `-Pgoogle` swaps in the
# Firebase-backed sources. Both variants write to the SAME unprefixed
# `release/` output paths, so we build FOSS first, copy its signed APK
# out to `dist/`, then `clean` and build Google — the clean guarantees
# the source-set selection for the second variant starts from scratch
# rather than reusing the first variant's merged manifest/resources.
- name: Build FOSS release APK (default, no flag)
env:
ROUSE_RELEASE_STORE_PASSWORD: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
ROUSE_RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
run: |
./gradlew :app:assembleRelease
- name: Extract version from APK
id: version
run: |
# Pull versionName from the build output metadata (same for both variants).
VERSION=$(grep -oP '"versionName"\s*:\s*"\K[^"]+' app/build/outputs/apk/release/output-metadata.json || echo "unknown")
echo "name=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=${GITHUB_REF_NAME:-${{ github.event.inputs.version || format('v{0}', env.VERSION) }}}" >> "$GITHUB_OUTPUT"
# A release with no changelog ships a blank "What's New" on F-Droid and
# Play. v1.0.9 went out that way: changelogs existed for versionCode 4-9
# and nothing checked that 10 had one. fdroidserver reads fastlane
# metadata from the tree at the recipe's `commit:`, so a missing file is
# not fixable after the fact without moving that pin. Fail here instead.
- name: "Changelog exists for this versionCode"
run: |
set -euo pipefail
CODE=$(grep -oP '"versionCode"\s*:\s*\K[0-9]+' \
app/build/outputs/apk/release/output-metadata.json | head -1)
if [ -z "$CODE" ]; then
echo "::error::could not read versionCode from output-metadata.json"
exit 1
fi
F="fastlane/metadata/android/en-US/changelogs/${CODE}.txt"
if [ ! -f "$F" ]; then
echo "::error::missing $F — every release needs a changelog entry for its versionCode."
# `find ... -printf '%f' | sort` rather than `ls` (SC2012): same
# sorted basenames on this tree, but it does not break on a name
# containing a newline or a glob character.
# The trailing `|| true` is deliberate and is not a route to
# green: this is the diagnostic half of a failure the `::error::`
# line above has ALREADY declared, and the `exit 1` below is the
# verdict. Hoisting the pipeline into an assignment would let a
# missing or unreadable changelogs/ directory kill the step here --
# after the error line, before the exit, with the listing that
# explains WHICH versionCodes do exist missing (#628's shape).
echo "Present: $(find fastlane/metadata/android/en-US/changelogs/ \
-maxdepth 1 -type f -printf '%f\n' | sort | tr '\n' ' ' || true)"
exit 1
fi
if [ ! -s "$F" ]; then
echo "::error::$F exists but is empty."
exit 1
fi
# Assigned, then printed. `-s "$F"` two lines up already established
# the file is non-empty, so a `wc` that cannot read it means the tree
# changed underneath this step -- worth stopping a signed RELEASE
# build over rather than printing "( bytes)" and shipping. `wc` writes
# its own reason to stderr first, so the step fails WITH one.
BYTES=$(wc -c < "$F")
echo "OK: $F ($BYTES bytes) for versionCode $CODE"
- name: Stage FOSS APK
run: |
mkdir -p dist
cp app/build/outputs/apk/release/app-release.apk \
"dist/rouse-context-${{ steps.version.outputs.name }}-foss.apk"
# The R8 mapping is the only thing that turns a release build's crash
# traces back into code, and the runner that made it is thrown away with
# the job (#755). Both variants write the SAME `release/` mapping path and
# the Google build starts with `clean`, so the FOSS mapping must be staged
# here, before that build deletes it. Verified against the staged APK by map id (R8 writes it into every
# frame's SourceFile as `r8-map-id-<pg_map_id>`), so a mapping from the
# wrong build fails here instead of shipping as a useless asset.
- name: "Stage FOSS R8 mapping (#755)"
env:
MAPPING: app/build/outputs/mapping/release/mapping.txt
APK: dist/rouse-context-${{ steps.version.outputs.name }}-foss.apk
OUT: dist/rouse-context-${{ steps.version.outputs.name }}-foss-mapping.txt
run: |
set -euo pipefail
if [ ! -s "$MAPPING" ]; then
echo "::error::$MAPPING is missing or empty; a release without its R8 mapping files crash reports nobody can decode."
exit 1
fi
if ! ID=$(grep -m1 -oP '^# pg_map_id: \K[0-9a-f]{64}$' "$MAPPING"); then
echo "::error::no 64-hex pg_map_id header in $MAPPING"
exit 1
fi
unzip -p "$APK" 'classes*.dex' > "$RUNNER_TEMP/foss-dex.bin"
if ! grep -qaF "r8-map-id-$ID" "$RUNNER_TEMP/foss-dex.bin"; then
echo "::error::$APK does not carry r8-map-id-$ID; $MAPPING is not its mapping."
exit 1
fi
cp "$MAPPING" "$OUT"
echo "OK: $OUT (pg_map_id $ID)"
# Verify the STAGED file, not the build output: step ordering plus a copy
# is the only thing that distinguishes the two artifacts (both variants
# write the same unprefixed `release/` path), so the thing that must be
# proven clean is the exact file that gets uploaded. Issue #548.
- name: "Staged FOSS APK contains no Google/Firebase code (issue #548)"
run: |
bash scripts/check-apk-distribution.sh \
--apk "dist/rouse-context-${{ steps.version.outputs.name }}-foss.apk" \
--expect foss
- name: Build Google release APK + AAB (-Pgoogle)
env:
ROUSE_RELEASE_STORE_PASSWORD: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
ROUSE_RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
# `clean` first so the Google source set isn't contaminated by the FOSS
# build's merged outputs (both share the unprefixed `release/` paths).
run: |
./gradlew clean :app:assembleRelease :app:bundleRelease -Pgoogle
- name: Stage Google APK + AAB
run: |
cp app/build/outputs/apk/release/app-release.apk \
"dist/rouse-context-${{ steps.version.outputs.name }}-google.apk"
cp app/build/outputs/bundle/release/app-release.aab \
"dist/rouse-context-${{ steps.version.outputs.name }}-google.aab"
# If the two builds/stages ever get reordered or a copy silently fails,
# the FOSS APK gets published twice under two names. This catches that
# from the other side, and doubles as the positive control proving the
# FOSS check above ran with patterns that still match Firebase.
- name: "Staged Google APK really contains Firebase (issue #548)"
run: |
bash scripts/check-apk-distribution.sh \
--apk "dist/rouse-context-${{ steps.version.outputs.name }}-google.apk" \
--expect google
# Same as "Stage FOSS R8 mapping" (#755). One R8 run backs both the Google
# APK and the AAB, so this one mapping covers both.
- name: "Stage Google R8 mapping (#755)"
env:
MAPPING: app/build/outputs/mapping/release/mapping.txt
APK: dist/rouse-context-${{ steps.version.outputs.name }}-google.apk
OUT: dist/rouse-context-${{ steps.version.outputs.name }}-google-mapping.txt
run: |
set -euo pipefail
if [ ! -s "$MAPPING" ]; then
echo "::error::$MAPPING is missing or empty; a release without its R8 mapping files crash reports nobody can decode."
exit 1
fi
if ! ID=$(grep -m1 -oP '^# pg_map_id: \K[0-9a-f]{64}$' "$MAPPING"); then
echo "::error::no 64-hex pg_map_id header in $MAPPING"
exit 1
fi
unzip -p "$APK" 'classes*.dex' > "$RUNNER_TEMP/google-dex.bin"
if ! grep -qaF "r8-map-id-$ID" "$RUNNER_TEMP/google-dex.bin"; then
echo "::error::$APK does not carry r8-map-id-$ID; $MAPPING is not its mapping."
exit 1
fi
cp "$MAPPING" "$OUT"
echo "OK: $OUT (pg_map_id $ID)"
- name: Upload FOSS APK artifact
uses: actions/upload-artifact@v4
with:
name: release-apk-foss
path: dist/rouse-context-${{ steps.version.outputs.name }}-foss.apk
- name: Upload Google APK artifact
uses: actions/upload-artifact@v4
with:
name: release-apk-google
path: dist/rouse-context-${{ steps.version.outputs.name }}-google.apk
- name: Upload Google AAB artifact (for Play Console)
uses: actions/upload-artifact@v4
with:
name: release-aab-google
path: dist/rouse-context-${{ steps.version.outputs.name }}-google.aab
- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v2
with:
name: Rouse Context ${{ steps.version.outputs.name }}
generate_release_notes: true
body: |
## Downloads
Two builds ship with each release — both signed with the same release key:
| Asset | Distribution | Use when |
| --- | --- | --- |
| `rouse-context-${{ steps.version.outputs.name }}-foss.apk` | **FOSS** (UnifiedPush, no Firebase/Google Play services) | Sideloading on de-Googled devices / F-Droid-style installs. |
| `rouse-context-${{ steps.version.outputs.name }}-google.apk` | **Google** (Firebase Cloud Messaging) | Sideloading on devices with Google Play services. |
| `rouse-context-${{ steps.version.outputs.name }}-google.aab` | **Google** App Bundle | Play Console upload only — not directly installable. |
| `rouse-context-${{ steps.version.outputs.name }}-{foss,google}-mapping.txt` | R8 mapping | Deobfuscating crash traces from that build (match its `r8-map-id-…`). |
---
# Default is false: an unmatched path is skipped with a warning and
# the release still publishes. Every file below is required (#755).
fail_on_unmatched_files: true
files: |
dist/rouse-context-${{ steps.version.outputs.name }}-foss.apk
dist/rouse-context-${{ steps.version.outputs.name }}-google.apk
dist/rouse-context-${{ steps.version.outputs.name }}-google.aab
dist/rouse-context-${{ steps.version.outputs.name }}-foss-mapping.txt
dist/rouse-context-${{ steps.version.outputs.name }}-google-mapping.txt
# Upload the Google AAB just attached to the release to Play's closed testing
# track. A separate job (and a reusable workflow) rather than an
# `on: release` workflow because a release created with GITHUB_TOKEN does not
# trigger other workflows' `release` events.
#
# Tag PUSHES only -- `github.event_name == 'push'` is load-bearing. A manual
# dispatch of this workflow with a tag selected as its ref also has
# `github.ref` = refs/tags/v*, and the build job's "Create GitHub Release"
# step (gated on that ref alone) DOES run for it and re-publish the release.
# That re-run must not also commit a Play release: to upload by hand, run
# play-upload.yml directly, where dry_run defaults to true. A dispatch on a
# branch ref creates no release and no upload.
#
# play-upload.yml reads the -google.aab asset and never the FOSS build;
# nothing in the `build` job above changes for it.
play-upload:
needs: build
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
permissions:
id-token: write # Workload Identity Federation (no key, no secret)
contents: read
uses: ./.github/workflows/play-upload.yml
with:
tag: ${{ github.ref_name }}
track: alpha
dry_run: false