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
53 changes: 41 additions & 12 deletions .github/workflows/android-apk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ name: Android APK
# Node, JDK 21 and the Android SDK; Gradle comes from the project wrapper.
#
# The APK is uploaded as a workflow artifact only (never committed, no
# releases are created). A `checks` job runs the Node test suites first so a
# broken app-logic change can't produce a green APK build unnoticed.
# releases are created). Two test jobs (`worker-api` and `android-app`) run
# the Node test suites first so a broken app-logic change can't produce a
# green APK build unnoticed — kept separate so failures name the culprit.
#
# When a semantic version tag vMAJOR.MINOR.PATCH is pushed, a release job
# additionally validates the signed production APK and publishes a GitHub
Expand Down Expand Up @@ -53,10 +54,18 @@ concurrency:
cancel-in-progress: true

jobs:
checks:
name: App logic + Worker API tests
# ────────────────────────────────────────────────────────────────────────
# Test gates — deliberately kept as TWO separate jobs so a failing run
# always tells you exactly which suite broke: "Worker API tests" vs.
# "Android app logic + UI smoke tests". An Android version bump
# (versionName/versionCode in android/app/build.gradle) must never make
# the Worker API suite fail; the suites are isolated both here and in the
# test files (no fixed production-version baseline anywhere).
# ────────────────────────────────────────────────────────────────────────
worker-api:
name: Worker API tests
runs-on: ubuntu-latest
timeout-minutes: 15
timeout-minutes: 10

steps:
- name: Checkout repository
Expand All @@ -67,25 +76,43 @@ jobs:
with:
node-version: '22'
cache: npm
cache-dependency-path: |
android-app/package-lock.json
worker/package-lock.json
cache-dependency-path: worker/package-lock.json

# The Android app's unit tests + jsdom smoke test are dependency-free
# Node tests (jsdom is reused from the Worker devDependencies below).
- name: Install Worker test dependencies
run: npm ci --prefix worker --no-audit --no-fund

- name: Run Worker API suite (unchanged backend contract)
run: |
node worker/test/worker.test.js
node worker/test/app-update.test.cjs
node worker/test/frontend-smoke-test.cjs
node worker/test/paper-smoke-test.cjs
node worker/test/contribution-points-test.cjs
node worker/test/duplicate-detection-test.cjs
node worker/test/duplicate-index-freshness-test.cjs
node worker/test/admin-ia-test.cjs

android-app:
name: Android app logic + UI smoke tests
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Checkout repository
uses: actions/checkout@v7

- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: '22'
cache: npm
cache-dependency-path: worker/package-lock.json

# The Android app's unit tests + jsdom smoke test are dependency-free
# Node tests (jsdom is reused from the Worker devDependencies below).
- name: Install Worker test dependencies (jsdom reused by Android smoke tests)
run: npm ci --prefix worker --no-audit --no-fund

- name: Run Android app logic + UI smoke tests
run: npm test --prefix android-app

Expand Down Expand Up @@ -305,7 +332,8 @@ jobs:
# Production GitHub Release.
#
# Activates ONLY when a semantic version tag vMAJOR.MINOR.PATCH is pushed
# AND the checks + release-apk jobs succeeded. Downloads the signed APK
# AND the worker-api, android-app and release-apk jobs succeeded.
# Downloads the signed APK
# artifact, validates tag/version consistency, re-verifies the APK, and
# creates (or safely updates) a GitHub Release with dsmnru-pyq.apk as the
# direct asset.
Expand All @@ -319,7 +347,8 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 15
needs:
- checks
- worker-api
- android-app
- release-apk
if: startsWith(github.ref, 'refs/tags/v')
permissions:
Expand Down
11 changes: 6 additions & 5 deletions android-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,11 @@ cd android && ./gradlew assembleDebug
```

The GitHub Actions workflow (`.github/workflows/android-apk.yml`) runs on
pushes to `android-app` **and on pull requests targeting it**: the `checks`
job runs the Worker suite and the app's `npm test` (jsdom reused from the
Worker devDependencies) first, then the `debug-apk` job builds the debug APK
in the cloud and uploads it as a workflow artifact — nothing binary is
pushes to `android-app` **and on pull requests targeting it**: the
`worker-api` and `android-app` test jobs run the Worker suite and the app's
`npm test` (jsdom reused from the Worker devDependencies) first — kept as
separate jobs so a failure always names the culprit — then the `debug-apk`
job builds the debug APK in the cloud and uploads it as a workflow artifact — nothing binary is
committed, and no releases are created automatically. A
signed release APK/AAB can be added later via repository secrets
(keystore + `google-services.json` are **never** committed; `build.gradle`
Expand All @@ -248,7 +249,7 @@ with an existing package". The applicationId stays `com.dsmnru.pyq` across
debug and release (one app identity, no second package). Release signing
remains out-of-repo and unconfigured — no production keystore credentials
exist in this repository. `versionCode` is bumped with every released
iteration (currently **5 / 1.3.1**).
iteration (currently **14 / 1.4.3**).

## Deferred by design

Expand Down
46 changes: 37 additions & 9 deletions android-app/test/release-automation.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ test('parses the real android/app/build.gradle', async () => {
const text = await fs.readFile(gradlePath, 'utf8');
const parsed = parseGradleVersions(text);
assert.ok(parsed, 'could not parse build.gradle');
// versionName exists and is a strict MAJOR.MINOR.PATCH semantic version.
// The release flow bumps it for every production release, so only the
// FORMAT is asserted here — never a specific production version.
assert.equal(typeof parsed.versionName, 'string');
assert.match(parsed.versionName, /^\d+\.\d+\.\d+$/, 'versionName must be MAJOR.MINOR.PATCH');
// versionCode exists and is a positive integer.
assert.equal(typeof parsed.versionCode, 'number');
assert.ok(Number.isInteger(parsed.versionCode), 'versionCode must be an integer');
assert.ok(parsed.versionCode > 0, 'versionCode must be positive');
assert.match(parsed.versionName, /^\d+\.\d+\.\d+$/, 'versionName must be semver-ish');
// Baseline stated by the task.
assert.equal(parsed.versionName, '1.4.2', 'production baseline versionName');
assert.equal(parsed.versionCode, 13, 'production baseline versionCode');
});

test('tag version must match Gradle versionName (release gate)', () => {
Expand Down Expand Up @@ -236,9 +239,17 @@ test('workflow file declares tag trigger for v*.*.* and a release job', async ()
);
// Tag trigger.
assert.match(wf, /tags:\s*\n\s*-\s*'v\*\.\*\.\*'/);
// Release job exists and depends on checks + release-apk.
// Release job exists and depends on BOTH test suites + release-apk, so a
// failing Worker API test or Android test blocks the release.
assert.match(wf, /^\s{2}release:/m);
assert.match(wf, /needs:\s*\n\s*-\s*checks\s*\n\s*-\s*release-apk/);
assert.match(wf, /needs:\s*\n\s*-\s*worker-api\s*\n\s*-\s*android-app\s*\n\s*-\s*release-apk/);
// The two test suites live in SEPARATE jobs so a CI failure always names
// the culprit (Worker API vs. Android app) instead of one combined job.
// An Android version bump must never make the Worker API suite fail.
assert.match(wf, /^\s{2}worker-api:/m);
assert.match(wf, /^\s{2}android-app:/m);
assert.match(wf, /node worker\/test\/worker\.test\.js/);
assert.match(wf, /npm test --prefix android-app/);
// Only runs on v* tags.
assert.match(wf, /if:\s*startsWith\(github\.ref,\s*'refs\/tags\/v'\)/);
// Has contents: write for release job.
Expand Down Expand Up @@ -294,9 +305,26 @@ test('release job does NOT appear to use a PAT', async () => {
assert.doesNotMatch(wf, /secrets\.(PAT|PERSONAL|RELEASE)_TOKEN/);
});

test('production baseline versions in build.gradle are unchanged (1.4.2 / 13)', async () => {
test('build.gradle declares exactly one release-ready versionName/versionCode (no fixed baseline)', async () => {
const gradlePath = path.join(REPO_ROOT, 'android-app', 'android', 'app', 'build.gradle');
const text = await fs.readFile(gradlePath, 'utf8');
assert.match(text, /versionCode\s+13\b/, 'versionCode baseline');
assert.match(text, /versionName\s+"1\.4\.2"/, 'versionName baseline');
// The release workflow bumps versionName/versionCode for EVERY production
// release (1.4.1/12 → 1.4.2/13 → 1.4.3/14 → …), so no test may pin a
// specific production version as a permanent baseline. Validate the
// SHAPE of the declarations instead: exactly one of each, and values
// suitable for an Android release. (Cross-checking these against the
// release tag and the built APK is the release job's job.)
const vnDecls = [...text.matchAll(/versionName\s+"([^"]*)"/g)];
const vcDecls = [...text.matchAll(/versionCode\s+(\d+)/g)];
assert.equal(vnDecls.length, 1, 'exactly one versionName declaration expected');
assert.equal(vcDecls.length, 1, 'exactly one versionCode declaration expected');

const versionName = vnDecls[0][1];
const versionCode = Number(vcDecls[0][1]);
// Valid semantic versionName (MAJOR.MINOR.PATCH, no prerelease).
assert.match(versionName, /^\d+\.\d+\.\d+$/, 'versionName must be valid MAJOR.MINOR.PATCH semver');
// Positive integer versionCode, suitable for an Android release.
assert.ok(Number.isInteger(versionCode) && versionCode > 0, 'versionCode must be a positive integer');
// Android versionCodes are signed 32-bit ints — stay within the bound.
assert.ok(versionCode <= 2147483647, 'versionCode must fit the Android signed 32-bit bound');
});
Loading