live read run fixes: Xcode-managed profiles in signing, TestFlight-only release trains, scan skips agent worktrees and takes an absolute --config, --all-pages paging meta, iap-submit json, report hints

This commit is contained in:
CRTkafa 2026-10-11 17:24:56 +00:00
parent 0856f2d1b2
commit 3a775f7808
15 changed files with 282 additions and 30 deletions

View file

@ -45,6 +45,11 @@ export async function readSubmitState(c: Asc, appId: string, want: string[]): Pr
return { appVersions, iaps, subs, groups, draft };
}
/** The requests a run would send: none when nothing is left to submit (seen live: every product already in review). */
export function planRequests<R>(prepare: R[], plan: { items: unknown[]; submit: R }): R[] {
return plan.items.length ? [...prepare, plan.submit] : [];
}
export async function run(ctx: Ctx): Promise<void> {
const { config, root } = ctx.loaded;
const a = ctx.args;
@ -73,7 +78,7 @@ export async function run(ctx: Ctx): Promise<void> {
const prepare = plan.prepare.map(r => bindIds(r, { app: appId }));
if (a.has('json')) {
printJson({ dryRun: dry, items: plan.items, skipped: plan.skipped, firstOfType: plan.firstOfType, hasApprovedVersion: plan.hasApprovedVersion,
needsAppVersion: plan.needsAppVersion, blockers: plan.blockers, draft: state.draft?.id ?? null, requests: [...prepare, plan.submit].map(r => describeReq(r)) });
needsAppVersion: plan.needsAppVersion, blockers: plan.blockers, draft: state.draft?.id ?? null, requests: planRequests(prepare, plan).map(r => describeReq(r)) });
if (dry || plan.blockers.length) { if (plan.blockers.length) process.exitCode = 1; return; }
} else {
for (const it of plan.items) log(TAG, `submit: ${it.label}`);
@ -84,7 +89,7 @@ export async function run(ctx: Ctx): Promise<void> {
if (plan.blockers.length) { process.exitCode = 1; done(TAG, 'nothing sent: fix the blockers above'); return; }
if (!plan.items.length) { done(TAG, 'nothing to submit'); return; }
if (dry) {
await execute(c.asc, [...prepare, plan.submit], { dry, tag: TAG });
await execute(c.asc, planRequests(prepare, plan), { dry, tag: TAG });
done(TAG, `dry run: ${plan.items.length} item(s) would go into ${state.draft ? `draft ${state.draft.id}` : 'a new draft submission'}`);
return;
}

View file

@ -18,7 +18,7 @@ import { buildCsr, csrContent, newSigningKey, spkiOfKey } from '../lib/csr';
import { done, log, printJson, warn } from '../lib/log';
import {
type ApiCert, type ApiProfile, type AppleSigning, capabilitySpecs, CERT_LIMIT, certificateReq, certSha1, certSpki, type CertType,
explainCertError, parseIdentities, pickCertificate, planCapabilities, planProfile, profileDirs, type ProfileType,
explainCertError, parseIdentities, pickCertificate, planCapabilities, planProfile, profileDirs, type ProfileType, readProfiles,
} from '../lib/signing';
import { textTable } from '../lib/table';
import { type Asc, ascClient, type J } from './asc';
@ -55,15 +55,7 @@ export async function findBundleId(c: Asc, identifier: string): Promise<J | null
return hit;
}
async function profilesOf(c: Asc, bundleIdId: string, type: ProfileType): Promise<ApiProfile[]> {
const ps = await c.all(`/v1/bundleIds/${bundleIdId}/profiles?limit=200`);
const out: ApiProfile[] = [];
for (const p of ps.filter((p: J) => p.attributes.profileType === type)) {
const certs = await c.all(`/v1/profiles/${p.id}/relationships/certificates?limit=200`);
out.push({ id: p.id, attributes: p.attributes, certIds: certs.map((x: J) => x.id) });
}
return out;
}
const profilesOf = (c: Asc, bundleIdId: string, type: ProfileType): Promise<ApiProfile[]> => readProfiles(p => c.all(p), bundleIdId, type);
const installedAt = (uuid: string | undefined): string[] => (uuid ? profileDirs(homedir()).map(d => join(d, `${uuid}.mobileprovision`)).filter(existsSync) : []);
@ -143,6 +135,10 @@ export async function run(ctx: Ctx): Promise<void> {
const p = profiles.get(id)!;
if (!bundles.get(id)) return { bundleId: id, name: null, uuid: null, state: 'bundle id not registered', installed: false, why: 'register it first (storebound apple bundle for the app; extensions in Certificates, Identifiers & Profiles)' };
const r = p.plan?.reuse;
const managed = p.list.find(x => x.managed && x.attributes.profileState === 'ACTIVE');
if (!r && managed && (s.style ?? 'automatic') === 'automatic')
return { bundleId: id, name: managed.attributes.name ?? null, uuid: managed.attributes.uuid ?? null, state: 'Xcode-managed', installed: installedAt(managed.attributes.uuid).length > 0,
why: `automatic signing: xcodebuild -allowProvisioningUpdates keeps it (expires ${managed.attributes.expirationDate?.slice(0, 10) ?? '?'})` };
return { bundleId: id, name: r?.attributes.name ?? null, uuid: r?.attributes.uuid ?? null, state: r ? 'ACTIVE' : 'needs a new profile',
installed: installedAt(r?.attributes.uuid).length > 0, why: p.plan?.why ?? 'waits for a usable certificate' };
}),

View file

@ -62,7 +62,18 @@ export async function run(ctx: Ctx): Promise<void> {
if (!/READY_FOR_SALE|READY_FOR_DISTRIBUTION|PENDING_DEVELOPER_RELEASE|PENDING_APPLE_RELEASE|ACCEPTED/.test(st)) continue;
phased[v.id] = (await c.maybe(`/v1/appStoreVersions/${v.id}/appStoreVersionPhasedRelease`))?.data ?? null;
}
printJson({ app, versions, builds: builds.data, iaps, subs, phased });
// builds attached to a version but older than the five newest (so the train shows their number too)
const known = new Set((builds.data as { id: string }[]).map(b => b.id));
const missing = [...new Set(versions.map(v => v.relationships?.build?.data?.id).filter((id): id is string => !!id && !known.has(id)))];
const attachedBuilds = missing.length ? ((await c.asc('GET', `/v1/builds?filter[id]=${missing.join(',')}&limit=${missing.length}`)).data ?? []) : [];
// build id -> marketing version (CFBundleShortVersionString): a TestFlight-only version is a train at "testing"
const buildVersions: Record<string, string> = {};
const pre = new Map(((builds.included ?? []) as { id: string; type?: string; attributes?: { version?: string } }[]).map(p => [p.id, p.attributes?.version] as const));
for (const b of builds.data as { id: string; relationships?: { preReleaseVersion?: { data?: { id?: string } } } }[]) {
const v = pre.get(b.relationships?.preReleaseVersion?.data?.id ?? '');
if (v) buildVersions[b.id] = v;
}
printJson({ app, versions, builds: builds.data, attachedBuilds, buildVersions, iaps, subs, phased });
return;
}