diff --git a/.github/actions/classify-mobile-release/classify-mobile-release.mjs b/.github/actions/classify-mobile-release/classify-mobile-release.mjs index 915698cc..7d05a590 100644 --- a/.github/actions/classify-mobile-release/classify-mobile-release.mjs +++ b/.github/actions/classify-mobile-release/classify-mobile-release.mjs @@ -36,7 +36,7 @@ export function selectPreviousTag(tags, { currentTag, currentMatch, containsAppP return tags .filter((candidate) => candidate !== `v${currentTag}`) .map((candidate) => ({ candidate, match: parseReleaseTag(candidate) })) - .filter(({ match }) => match && compareRelease(match, currentMatch) < 0) + .filter(({ match }) => match && compareRelease(match, currentMatch) < 0 && (currentMatch[4] !== undefined || match[4] === undefined)) .filter(({ candidate }) => containsAppPackage(candidate)) .sort((left, right) => compareRelease(right.match, left.match))[0]?.candidate; } @@ -120,6 +120,15 @@ export function classifyRelease({ return 'live-update'; } +/** Requires a store build number greater than every prior native handoff in its release train. */ +export function assertUnusedStoreBuild(buildNumber, handoffs) { + for (const { tag, buildNumber: previousBuild } of handoffs) { + if (Number(buildNumber) <= Number(previousBuild)) { + throw new Error(`Store build ${buildNumber} must exceed ${previousBuild} already handed off by ${tag}.`); + } + } +} + export function buildOutputLines(releaseKind, version, buildNumber) { return [ `release_kind=${releaseKind}`, @@ -196,6 +205,25 @@ export function main({ argv = process.argv.slice(2), env = process.env } = {}) { nativeFilesChanged, nativeDependencyChanges, }); + if (releaseKind === 'store' && tagMatch[4] === undefined) { + const [, major, minor] = tagMatch; + // The release baseline ignores prereleases, but a handoff in this train + // can still have consumed a build number. + const handoffTags = execFileSync('git', ['tag', '--list', `capawesome/v${major}.${minor}.*-*`], { + encoding: 'utf8', + }).trim(); + const handoffs = handoffTags ? handoffTags.split('\n') : []; + assertUnusedStoreBuild( + native.buildNumber, + handoffs.map((tag) => ({ + tag, + buildNumber: readNativeVersions( + gitShow(`${appPath}/android/app/build.gradle`, tag), + gitShow(`${appPath}/ios/App/App.xcodeproj/project.pbxproj`, tag), + ).buildNumber, + })), + ); + } const lines = buildOutputLines(releaseKind, version, native.buildNumber); if (env.GITHUB_OUTPUT) appendFileSync(env.GITHUB_OUTPUT, `${lines.join('\n')}\n`); console.log(`Classified v${version} as ${releaseKind} for native ${native.marketingVersion} (${native.buildNumber}).`); diff --git a/.github/actions/classify-mobile-release/classify-mobile-release.spec.mjs b/.github/actions/classify-mobile-release/classify-mobile-release.spec.mjs index b4a57ab3..5fabe6ab 100644 --- a/.github/actions/classify-mobile-release/classify-mobile-release.spec.mjs +++ b/.github/actions/classify-mobile-release/classify-mobile-release.spec.mjs @@ -2,6 +2,7 @@ import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; import { assertBuildEncodesVersion, + assertUnusedStoreBuild, buildOutputLines, classifyRelease, compareRelease, @@ -75,6 +76,35 @@ describe('previous release selection', () => { ); }); + it('uses the previous stable release for a stable promotion', () => { + const tags = ['v9.0.0', 'v9.1.0-1']; + const previousTag = selectPreviousTag(tags, { + currentTag: '9.1.0', + currentMatch: match('9.1.0'), + containsAppPackage: () => true, + }); + assert.equal(previousTag, 'v9.0.0'); + assert.equal( + classifyRelease( + classification({ + tagMatch: match('9.1.0'), + native: { marketingVersion: '9.1.0', buildNumber: '9010000' }, + previousTag, + previousMatch: parseReleaseTag(previousTag), + }), + ), + 'store', + ); + assert.equal( + selectPreviousTag(tags, { + currentTag: '9.1.0-2', + currentMatch: match('9.1.0-2'), + containsAppPackage: () => true, + }), + 'v9.1.0-1', + ); + }); + it('returns undefined for the first applicable release', () => { assert.equal( selectPreviousTag(['v9.0.0'], { @@ -252,6 +282,18 @@ describe('release classification', () => { }); }); +describe('native handoff build numbers', () => { + it('requires a store build above every prior handoff in its release train', () => { + const handoffs = [ + { tag: 'capawesome/v9.1.0-1', buildNumber: '9010001' }, + { tag: 'capawesome/v9.1.0-2', buildNumber: '9010002' }, + ]; + assert.throws(() => assertUnusedStoreBuild('9010002', handoffs), /already handed off by capawesome\/v9\.1\.0-2/); + assert.throws(() => assertUnusedStoreBuild('9010000', handoffs), /must exceed 9010001/); + assert.doesNotThrow(() => assertUnusedStoreBuild('9010003', handoffs)); + }); +}); + describe('action outputs', () => { it('emits the routing and existing Live Update outputs', () => { assert.deepEqual(buildOutputLines('live-update', '9.0.1', '9000000'), [