// Next safe build number (CFBundleVersion) from App Store Connect: one above the highest build ever uploaded for the // app, across every version train. Prints only the number on stdout, so scripts can use it: // storebound apple next-build -> 42 // xcodebuild ... CURRENT_PROJECT_VERSION=$(storebound apple next-build) // Then attach exactly that build: storebound apple listing --version x.y.z --build 42 (never "the latest"). import type { Ctx } from '../lib/ctx'; import { need } from '../lib/ctx'; import { printJson } from '../lib/log'; import { nextBuildNumber } from '../lib/release'; import { ascClient, type Asc } from './asc'; /** * The one place that computes the next CFBundleVersion: the highest build of the app over EVERY platform (iOS, macOS, * tvOS, visionOS), every processing state and every page, plus one. CFBundleVersion must be unique across the app * record's builds, so a platform filter (a macOS build once got a number an uploaded macOS build already had) or a * missed page gives a number the store refuses. `apple next-build`, `apple build` and `apple build --platform macos` * (also their dry runs) all call this, so they agree. */ export async function appNextBuild(c: Pick): Promise<{ next: string; builds: number }> { const builds = await c.all(`/v1/builds?filter[app]=${await c.app()}&limit=200&fields[builds]=version`); return { next: nextBuildNumber(builds.map(b => String(b.attributes.version))), builds: builds.length }; } export async function run(ctx: Ctx): Promise { const { config, root } = ctx.loaded; const c = await ascClient(root, need(config.apple?.bundleId, 'apple.bundleId'), config.apple?.appId); const { next, builds } = await appNextBuild(c); if (ctx.args.has('json')) { printJson({ next, builds }); return; } console.error(`[apple] ${builds} builds on App Store Connect; next build number:`); console.log(next); }