Ship-step contract for pipelines: uniform exit codes (0/1/2/3/4/7) in cli/lib/ship-step.ts, one final --json line, --result-file (atomic, also on failure), --progress json, --env-file with secret redaction, --version-from; idempotent play upload / apple upload / play release / apple submit re-runs end with exit 7; play upload takes --track production and --version-code
This commit is contained in:
parent
4eac8e8cd8
commit
06a0b424f5
14 changed files with 928 additions and 24 deletions
|
|
@ -1,10 +1,12 @@
|
|||
// Upload an Android App Bundle to a Google Play testing track.
|
||||
// storebound play upload [<app.aab>] [--track internal|alpha|beta] [--status completed|draft] [--name text] [--not-sent-for-review] [--dry] [--yes] [--json]
|
||||
// Default AAB: the newest in build/android (storebound play build). Package and versionCode are read from the bundle;
|
||||
// the upload is refused when Play already has that versionCode. Release notes: the "What's new" of every listing
|
||||
// language. --dry is read-only (one throwaway edit: version codes and the track are read, the edit is deleted).
|
||||
// A real run asks first (--yes in scripts). Production is not offered here: `storebound play release --production
|
||||
// draft` (and the play-first-release / release-management skills) keep that the owner's step.
|
||||
// storebound play upload [<app.aab>] [--track internal|alpha|beta|production] [--status completed|draft] [--version-code N] [--name text] [--not-sent-for-review] [--dry] [--yes] [--json]
|
||||
// Default AAB: the newest in build/android (storebound play build), or with --version-code N the one with that
|
||||
// versionCode. Package and versionCode are read from the bundle; the upload is refused when Play already has that
|
||||
// versionCode (exit 1), and under the ship-step contract (--json / --result-file, docs/ship-step.md) it is exit 7
|
||||
// "nothing to do" with the track and state that are there: never a second upload. Release notes: the "What's new" of
|
||||
// every listing language. --dry is read-only (one throwaway edit: version codes and the track are read, the edit is
|
||||
// deleted). A real run asks first (--yes in scripts). --track production sends the release to Google's review (a
|
||||
// pipeline's update step); --status draft keeps it for the Console.
|
||||
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
||||
import { join, relative } from 'node:path';
|
||||
import type { Ctx } from '../lib/ctx';
|
||||
|
|
@ -16,29 +18,36 @@ import { nextVersionCode } from '../lib/release';
|
|||
import { playClient } from './client';
|
||||
import { readPlayCopy, refusePlayNotes } from './listing';
|
||||
import { usedVersionCodes } from './next-version-code';
|
||||
import { shipNoop, shipPhase, shipReport, shipRun, shipWarn } from '../lib/ship-step';
|
||||
import { consoleUrl, playTrackPage } from '../lib/console-links';
|
||||
|
||||
const TAG = 'upload';
|
||||
export const UPLOAD_TRACKS = ['internal', 'alpha', 'beta'] as const;
|
||||
export const UPLOAD_TRACKS = ['internal', 'alpha', 'beta', 'production'] as const;
|
||||
|
||||
export async function run(ctx: Ctx): Promise<void> {
|
||||
const { config, root, resolve } = ctx.loaded;
|
||||
const a = ctx.args;
|
||||
const pkg = need(config.play?.packageName, 'play.packageName');
|
||||
const track = a.str('track', 'internal');
|
||||
if (track === 'production') throw new Error('play upload is for testing tracks; production goes through storebound play release --production draft (the owner sends it)');
|
||||
if (!(UPLOAD_TRACKS as readonly string[]).includes(track)) throw new Error(`--track: ${UPLOAD_TRACKS.join(' | ')}`);
|
||||
const status = a.str('status', 'completed');
|
||||
if (!['completed', 'draft'].includes(status)) throw new Error('--status: completed | draft');
|
||||
const wantCode = a.get('version-code');
|
||||
if (wantCode !== undefined && !/^\d+$/.test(wantCode)) throw new Error('--version-code: an integer (the versionCode of the AAB to upload)');
|
||||
let aab = a._.find(x => x.endsWith('.aab'));
|
||||
if (aab) aab = resolve(aab);
|
||||
else {
|
||||
const dir = resolve('build/android');
|
||||
let found: string[] = [];
|
||||
try { found = readdirSync(dir).filter(f => f.endsWith('.aab')).map(f => join(dir, f)).sort((x, y) => statSync(y).mtimeMs - statSync(x).mtimeMs); } catch { /* none */ }
|
||||
if (!found[0]) throw new Error('usage: storebound play upload <app.aab> --track internal (nothing in build/android; storebound play build makes one)');
|
||||
if (wantCode) found = found.filter(f => { try { return aabInfo(f).versionCode === Number(wantCode); } catch { return false; } });
|
||||
if (!found[0]) throw new Error(`usage: storebound play upload <app.aab> --track internal (no ${wantCode ? `versionCode ${wantCode} ` : ''}AAB in build/android; storebound play build makes one)`);
|
||||
aab = found[0];
|
||||
}
|
||||
shipPhase('verify', `checking ${relative(root, aab)}`);
|
||||
const info = aabInfo(aab);
|
||||
if (wantCode && info.versionCode !== Number(wantCode)) throw new Error(`${relative(root, aab)} is versionCode ${info.versionCode}, not ${wantCode} (--version-code)`);
|
||||
shipReport({ track, version: info.versionName ?? undefined, build: String(info.versionCode), url: consoleUrl(playTrackPage(track)) });
|
||||
if (info.packageName !== pkg) throw new Error(`${relative(root, aab)} is ${info.packageName}, the config says ${pkg}`);
|
||||
// Play refuses bundles below its current target API level (cli/lib/store-minimums.ts): stop before any network call
|
||||
const sdkWhy = playTargetSdkProblem(info.targetSdk, { where: targetSdkFile(root) });
|
||||
|
|
@ -56,10 +65,21 @@ export async function run(ctx: Ctx): Promise<void> {
|
|||
}));
|
||||
// an earlier run did it already (the bundle is on Play and on this track): nothing to send again
|
||||
if (used.includes(info.versionCode) && current.some(r => (r.versionCodes ?? []).includes(String(info.versionCode)) && r.status === status)) {
|
||||
if (json) { printJson({ aab: relative(root, aab), packageName: info.packageName, versionCode: info.versionCode, track, status, uploaded: true, alreadyThere: true }); return; }
|
||||
shipNoop({ state: status });
|
||||
if (json) { printJson({ aab: relative(root, aab), packageName: info.packageName, versionCode: info.versionCode, versionName: info.versionName ?? null, track, status, uploaded: true, alreadyThere: true }); return; }
|
||||
done(TAG, `versionCode ${info.versionCode} is on ${track} (${status}) already: nothing uploaded`);
|
||||
return;
|
||||
}
|
||||
if (used.includes(info.versionCode) && !dry) {
|
||||
// the ship-step contract: the versionCode is on Play already, nothing is uploaded again (exit 7 with what is there)
|
||||
const on = await play.read(async id => (await play.call<{ tracks?: { track: string; releases?: { status: string; versionCodes?: string[] }[] }[] }>('GET', `${play.API}/edits/${id}/tracks`)).tracks ?? []).catch(() => []);
|
||||
const where = on.flatMap(t => (t.releases ?? []).filter(r => (r.versionCodes ?? []).includes(String(info.versionCode))).map(r => ({ track: t.track, status: r.status })));
|
||||
const here = where.find(w => w.track === track) ?? where[0];
|
||||
if (here) shipNoop({ track: here.track, state: here.status, url: consoleUrl(playTrackPage(here.track)) });
|
||||
else shipNoop({ state: 'uploaded' });
|
||||
if (!where.some(w => w.track === track)) shipWarn(`versionCode ${info.versionCode} is on Google Play${where.length ? ` (${where.map(w => `${w.track} ${w.status}`).join(', ')})` : ' (in the bundle library, on no track)'} but not on ${track}: storebound play release --version-code ${info.versionCode} --${track} ${status} puts it there`);
|
||||
if (shipRun()) { done(TAG, `versionCode ${info.versionCode} is on Google Play already: nothing uploaded`); return; }
|
||||
}
|
||||
if (used.includes(info.versionCode)) throw new Error(`versionCode ${info.versionCode} is already on Google Play: rebuild with --version-code ${nextVersionCode(used)} (storebound play build)`);
|
||||
const summary = { aab: relative(root, aab), packageName: info.packageName, versionCode: info.versionCode, versionName: info.versionName ?? null, sizeMB: Math.round(size / 104857.6) / 10,
|
||||
track, status, notes: notes.map(n => n.language), replaces: current.map(r => `${r.status} ${(r.versionCodes ?? []).join(',')}`) };
|
||||
|
|
@ -70,15 +90,18 @@ export async function run(ctx: Ctx): Promise<void> {
|
|||
done(TAG, 'upload planned (dry run, read-only)');
|
||||
return;
|
||||
}
|
||||
if (!(await confirm(ctx, `Upload ${info.packageName} versionCode ${info.versionCode} and put it on the ${track} track (${status})? Testers of that track get it.`))) return;
|
||||
if (!(await confirm(ctx, `Upload ${info.packageName} versionCode ${info.versionCode} and put it on the ${track} track (${status})? ${track === 'production' ? 'It goes to Google review and then to every user.' : 'Testers of that track get it.'}`))) return;
|
||||
try {
|
||||
await play.edit(async id => {
|
||||
log(TAG, `uploading ${summary.sizeMB} MB, this can take minutes`);
|
||||
shipPhase('upload', `uploading ${summary.sizeMB} MB`, 0);
|
||||
const b = await play.call<{ versionCode: number }>('POST', `${play.UPLOAD}/edits/${id}/bundles?uploadType=media`, new Uint8Array(readFileSync(aab!)), { 'Content-Type': 'application/octet-stream' });
|
||||
log(TAG, `uploaded versionCode ${b.versionCode}`);
|
||||
shipPhase('upload', `uploaded versionCode ${b.versionCode}`, 100);
|
||||
const release: Record<string, unknown> = { versionCodes: [String(b.versionCode)], status, ...(notes.length ? { releaseNotes: notes } : {}), ...(a.get('name') ? { name: a.get('name') } : {}) };
|
||||
await play.call('PUT', `${play.API}/edits/${id}/tracks/${track}`, { track, releases: [release] });
|
||||
log(TAG, `${track} <- ${b.versionCode} (${status})`);
|
||||
shipPhase('commit', `${track} <- ${b.versionCode} (${status})`);
|
||||
}, { retries: 0, notSentForReview: ctx.args.has('not-sent-for-review'), summary: `upload versionCode ${info.versionCode} to ${track} ${status}` });
|
||||
} catch (e) {
|
||||
if (/draft app|status draft/i.test(String(e)) && status !== 'draft')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue