From 5b27624c33937d672d94f18d16b49b6d4bde4cf9 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 28 Nov 2026 00:30:01 +0100 Subject: [PATCH] fix(native-release): publish the Android APK for release tags only A prerelease tag or a run started by hand is a testing build on the internal track, so it no longer replaces the public APK in liketrek/trek-android. --- .github/workflows/native-release.yml | 5 +++-- scripts/ci/android-apk-release.mjs | 15 +++++++++++++-- scripts/ci/android-apk-release.test.mjs | 11 ++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/native-release.yml b/.github/workflows/native-release.yml index 1d29dce6c..18d9a7d5d 100644 --- a/.github/workflows/native-release.yml +++ b/.github/workflows/native-release.yml @@ -107,8 +107,9 @@ jobs: # The same build for installs outside Google Play: the universal APK Google # Play makes of this bundle, signed with the Play app signing key, published - # to liketrek/trek-android for Obtainium (wiki/Native-Apps.md). Held back - # while the app needs a server version that is not released yet. + # to liketrek/trek-android for Obtainium (wiki/Native-Apps.md). Only for a + # release tag, and held back while the app needs a server version that is + # not released yet. - name: Whether the latest server release serves this build id: released env: diff --git a/scripts/ci/android-apk-release.mjs b/scripts/ci/android-apk-release.mjs index 9120585c4..19dd3f412 100644 --- a/scripts/ci/android-apk-release.mjs +++ b/scripts/ci/android-apk-release.mjs @@ -15,8 +15,9 @@ // be cut from dev before the server it needs is released. It may go out // once the latest server release answers a nativeApi at least that high // (its server/src/nest/health/features.controller.ts, which the workflow -// writes out with git show). Prints publish=true or publish=false, for -// $GITHUB_OUTPUT. +// writes out with git show). Only a release tag goes out (vX.Y.Z, pushed): +// a prerelease tag or a run started by hand is a testing build. Prints +// publish=true or publish=false, for $GITHUB_OUTPUT. // // download // Asks the Play Developer API for the universal APK of that version code, @@ -54,7 +55,17 @@ export function mayPublish(appMinimum, released) { return released >= appMinimum; } +/** Whether the run was started by pushing a release tag, not a prerelease tag or by hand. */ +export function isReleaseRun(eventName, ref) { + return eventName === 'push' && /^refs\/tags\/v\d+\.\d+\.\d+$/.test(ref ?? ''); +} + function guard(releasedFeatures) { + if (!isReleaseRun(process.env.GITHUB_EVENT_NAME, process.env.GITHUB_REF)) { + console.error(`${process.env.GITHUB_REF} is not a release tag: hold back`); + console.log('publish=false'); + return; + } const appMinimum = appMinimumApi(readFileSync(APP_MIN_FILE, 'utf8')); const released = serverApi(readFileSync(releasedFeatures, 'utf8')); const publish = mayPublish(appMinimum, released); diff --git a/scripts/ci/android-apk-release.test.mjs b/scripts/ci/android-apk-release.test.mjs index fa105a811..40798b46a 100644 --- a/scripts/ci/android-apk-release.test.mjs +++ b/scripts/ci/android-apk-release.test.mjs @@ -1,4 +1,4 @@ -import { appMinimumApi, mayPublish, serverApi, universalDownloadId } from './android-apk-release.mjs'; +import { appMinimumApi, isReleaseRun, mayPublish, serverApi, universalDownloadId } from './android-apk-release.mjs'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; @@ -27,6 +27,15 @@ describe('android-apk-release', () => { assert.equal(mayPublish(4, 3), false); }); + it('publishes only for a pushed release tag', () => { + assert.equal(isReleaseRun('push', 'refs/tags/v5.2.2'), true); + assert.equal(isReleaseRun('push', 'refs/tags/v5.2.2-tf.1'), false); + assert.equal(isReleaseRun('push', 'refs/heads/dev'), false); + assert.equal(isReleaseRun('workflow_dispatch', 'refs/tags/v5.2.2'), false); + assert.equal(isReleaseRun('workflow_dispatch', 'refs/heads/dev'), false); + assert.equal(isReleaseRun('push', undefined), false); + }); + it('finds the universal APK in a generatedApks answer, and nothing in one without it', () => { assert.equal( universalDownloadId({ generatedApks: [{ generatedSplitApks: [{}] }, { generatedUniversalApk: { downloadId: 'abc' } }] }),