// Upload an AAB (or reuse an uploaded versionCode) and put it on one or more tracks in one edit, with the "What's new" // of every listing language as release notes. // storebound play release app-release.aab [--internal completed] [--production draft] [--name "1.0.0 (3)"] [--dry] // storebound play release --version-code 3 --production draft // Tracks: internal, alpha (closed), beta (open), production; status completed | draft | inProgress | halted. // Without a track flag: internal, completed. A production release that is not a draft asks for confirmation. // Draft app (never published): Play only accepts status "draft" on any track; the first production release is sent // from the Console (see the play-first-release skill). import { readFileSync, statSync } from 'node:fs'; import type { Ctx } from '../lib/ctx'; import { confirm, need } from '../lib/ctx'; import { done, log } from '../lib/log'; import { playClient } from './client'; import { readPlayCopy } from './listing'; const TRACKS = ['internal', 'alpha', 'beta', 'production']; const STATUSES = ['completed', 'draft', 'inProgress', 'halted']; export async function run(ctx: Ctx): Promise { const { config, root } = ctx.loaded; const pkg = need(config.play?.packageName, 'play.packageName'); const a = ctx.args; const aab = a._.find(x => x.endsWith('.aab')); const fixed = a.get('version-code'); if (!aab && !fixed) throw new Error('usage: play release | --version-code N [--internal completed] [--production draft] [--name text] [--dry]'); const tracks = TRACKS.filter(t => a.has(t)).map(t => ({ track: t, status: a.get(t) === 'true' ? 'draft' : a.get(t)! })); if (!tracks.length) tracks.push({ track: 'internal', status: 'completed' }); for (const t of tracks) if (!STATUSES.includes(t.status)) throw new Error(`--${t.track}: status must be one of ${STATUSES.join(', ')}`); const fraction = a.get('fraction'); const live = tracks.find(t => t.track === 'production' && t.status !== 'draft'); if (live && !a.has('dry') && !(await confirm(ctx, `Release to PRODUCTION as "${live.status}" (public once Google approves)?`))) return; const notes = readPlayCopy(ctx).filter(c => c.whatsNew).map(c => ({ language: c.lang, text: c.whatsNew })); const play = await playClient(root, pkg); try { await play.edit(async id => { let code = fixed ?? ''; if (aab) { log('play', `uploading ${aab} (${(statSync(aab).size / 1048576).toFixed(1)} MB), this can take minutes`); const b = await play.call<{ versionCode: number }>('POST', `${play.UPLOAD}/edits/${id}/bundles?uploadType=media`, new Uint8Array(readFileSync(aab)), { 'Content-Type': 'application/octet-stream' }); code = String(b.versionCode); log('play', `uploaded versionCode ${code}`); } for (const t of tracks) { const release: Record = { versionCodes: [code], status: t.status }; if (notes.length) release.releaseNotes = notes; if (a.get('name')) release.name = a.get('name'); if (t.status === 'inProgress') release.userFraction = Number(fraction ?? 0.1); await play.call('PUT', `${play.API}/edits/${id}/tracks/${t.track}`, { track: t.track, releases: [release] }); log('play', `${t.track} <- ${code} (${t.status}, notes in ${notes.length} languages)`); } }, { dry: a.has('dry'), retries: aab ? 0 : 3 }); } catch (e) { if (/draft app|status draft/i.test(String(e))) throw new Error(`${(e as Error).message}\n\nThis app has never been published: the API may only create DRAFT releases. Re-run with --production draft, then send it from the Console (skill play-first-release).`); throw e; } done('play', 'release done'); }