storebound/cli/play/next-version-code.ts
CRT 3a755823da Guarded read-only run of the Play POST read paths: errorIssues:search in UTC, issues failure keeps the vitals, read-only listing / images dry runs
A live run where only the token exchange, edit insert / delete and Reporting :query were let through:
- health / validate: errorIssues:search answered 400 "Unsupported timezone" for America/Los_Angeles (it takes
  hour-aligned UTC only); the failure dropped the crash and ANR rates and the reason was cut off in the query string.
  Issues are asked in UTC; a failing issues search is a vitals-issues warning; Reporting errors leave out the query.
- play listing --dry / play images --dry wrote into the edit (PUT details and listings, image clears and uploads,
  :validate) before discarding it. Now one throwaway edit is read (details, listings, image sha256) and compared
  with the local copy, then deleted.
- play.read(): one helper for read-only edits (status, next-version-code), always deleted, warns if the delete fails;
  next-version-code counts distinct codes.
- tests on sanitized recorded answers (tests/play-post-reads.test.ts)
2026-10-11 00:41:55 +00:00

27 lines
1.7 KiB
TypeScript

// Next Play versionCode: one above every code in uploaded bundles and on any track. Read-only (the edit is deleted).
// Prints only the number on stdout:
// storebound play next-version-code -> 43
// ./gradlew bundleRelease -PversionCode=$(storebound play next-version-code)
import type { Ctx } from '../lib/ctx';
import { need } from '../lib/ctx';
import { printJson } from '../lib/log';
import { nextVersionCode } from '../lib/release';
import { playClient } from './client';
export async function run(ctx: Ctx): Promise<void> {
const { config, root } = ctx.loaded;
const play = await playClient(root, need(config.play?.packageName, 'play.packageName'));
await play.read(async id => {
const bundles = (await play.call<{ bundles?: { versionCode: number }[] }>('GET', `${play.API}/edits/${id}/bundles`)).bundles ?? [];
const apks = (await play.call<{ apks?: { versionCode: number }[] }>('GET', `${play.API}/edits/${id}/apks`).catch(() => ({ apks: [] }))).apks ?? [];
const tracks = (await play.call<{ tracks?: { releases?: { versionCodes?: string[] }[] }[] }>('GET', `${play.API}/edits/${id}/tracks`)).tracks ?? [];
const codes = [...bundles.map(b => b.versionCode), ...apks.map(a => a.versionCode), ...tracks.flatMap(t => (t.releases ?? []).flatMap(r => r.versionCodes ?? []))];
// the same code is in the bundle list and on every track it was released to: count distinct codes
const distinct = new Set(codes.map(String)).size;
if (ctx.args.has('json')) printJson({ next: nextVersionCode(codes), seen: distinct });
else {
console.error(`[play] ${distinct} distinct version code(s) in bundles, APKs and tracks; next versionCode:`);
console.log(nextVersionCode(codes));
}
});
}