@sprid/release 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@
3
3
  @sprid/release follows semver: a breaking change to a command's arguments, its
4
4
  output shape or its exit codes is a major release.
5
5
 
6
+ ## 1.0.0 - 2026-09-30
7
+
8
+ - Breaking: saved Sprid workspace identifiers use UUID strings for release annotations.
9
+
10
+ ## 0.1.2 - 2026-09-24
11
+
12
+ - `credentials-push` and `credentials-pull` keep signing keys on EAS (Expo)
13
+ while builds, uploads and submissions stay local. `build.credentialsSource:
14
+ 'eas'` makes `ship` download them before every build. Push is idempotent and
15
+ refuses to swap a different Android upload key without `--replace`.
16
+ - A Play upload to a brand-new app (auto-send mode) commits instead of failing
17
+ on `changesNotSentForReview`, whatever the track.
18
+
6
19
  ## 0.1.1 - 2026-09-22
7
20
 
8
21
  - Install as `@sprid/cli`; the unscoped `sprid` name is refused by npm.
package/README.md CHANGED
@@ -143,6 +143,23 @@ Commands run in `appDir`; artifact paths resolve beside the release config. The
143
143
  command must produce a correctly signed IPA or AAB. Direct upload commands bypass
144
144
  all build/version assumptions.
145
145
 
146
+ ### Signing keys on EAS
147
+
148
+ Expo's EAS can hold the signing keys while this package does the building and
149
+ submitting. `credentials-push` uploads your credentials.json (Android upload
150
+ keystore, iOS distribution certificate, an App Store profile per target) to the
151
+ EAS project; `credentials-pull` downloads them to `~/.sprid/eas-credentials/`,
152
+ owner-only. Set `build.credentialsSource: 'eas'` and `ship` pulls before every
153
+ build, so no machine keeps its own copy. The project is `eas.project`
154
+ (`@owner/slug`) or the Expo config's `owner` + `slug`; sign in with `eas login` or
155
+ set `EXPO_TOKEN`. Both commands are dry runs without `--execute`, print
156
+ fingerprints and ids only, and reuse anything EAS already holds byte for byte.
157
+
158
+ ```sh
159
+ sprid release credentials-push --execute # once, from your local credentials.json
160
+ sprid release credentials-pull --execute # any machine, any time
161
+ ```
162
+
146
163
  `--submit-only` resumes an iOS build or uploads an existing AAB; `asc-upload` uploads an IPA. `--internal` targets internal testing.
147
164
  If Google blocks a draft app, Sprid saves the uploaded bundle as a draft on the
148
165
  requested track, finishes iOS, then exits with `PlayConsoleRequiredError`. Complete
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprid/release",
3
- "version": "0.1.1",
3
+ "version": "1.0.0",
4
4
  "description": "Build, sign and release mobile apps locally. Store copy, screenshots, binary uploads and review submissions from one app-owned configuration. Dry run by default.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
package/src/annotate.ts CHANGED
@@ -13,7 +13,7 @@ import { join } from 'node:path';
13
13
  interface Creds {
14
14
  apiUrl: string;
15
15
  token: string;
16
- workspace?: { id: number } | null;
16
+ workspace?: { id: string } | null;
17
17
  }
18
18
 
19
19
  function loadCreds(): Creds | null {
package/src/cli.ts CHANGED
@@ -8,6 +8,7 @@ import { pushPlayMetadata } from './play/metadata.ts';
8
8
  import { pushPlayScreenshots } from './play/screenshots.ts';
9
9
  import { pushPlayGraphics } from './play/graphics.ts';
10
10
  import { ship } from './ship.ts';
11
+ import { pullEasCredentials, pushEasCredentials } from './eas/credentials.ts';
11
12
  import { bumpVersion, readAppVersion } from './bump.ts';
12
13
  import { uploadIpa } from './asc/upload.ts';
13
14
  import { submitForReview } from './asc/submit.ts';
@@ -27,6 +28,8 @@ const value = (name: string) => {
27
28
  const COMMANDS: Record<string, { usage: string; bool: string[]; values?: string[] }> = {
28
29
  ship: { usage: 'ship [--execute] [--patch|--minor|--major] [--ios-only|--android-only] [--build-only|--submit-only]', bool: ['execute', 'patch', 'minor', 'major', 'ios-only', 'android-only', 'build-only', 'submit-only', 'no-bump', 'no-submit', 'internal', 'allow-dirty', 'push-store-copy', 'replace-submission'] },
29
30
  bump: { usage: 'bump [--execute] [--patch|--minor|--major]', bool: ['execute', 'patch', 'minor', 'major'] },
31
+ 'credentials-pull': { usage: 'credentials-pull [--execute] [--ios-only|--android-only]', bool: ['execute', 'ios-only', 'android-only'] },
32
+ 'credentials-push': { usage: 'credentials-push [--execute] [--ios-only|--android-only] [--replace] [--from <credentials.json>]', bool: ['execute', 'ios-only', 'android-only', 'replace'], values: ['from'] },
30
33
  'asc-upload': { usage: 'asc-upload --ipa <file> [--execute]', bool: ['execute'], values: ['ipa'] },
31
34
  'play-upload': { usage: 'play-upload --aab <file> --version <version> [--track production|beta|internal] [--execute]', bool: ['execute'], values: ['aab', 'version', 'track'] },
32
35
  'asc-submit': { usage: 'asc-submit --version <version> --build <number> [--execute] [--attach-only]', bool: ['execute', 'attach-only', 'push-store-copy', 'replace-submission'], values: ['version', 'build'] },
@@ -48,7 +51,7 @@ function printUsage(command?: string): void {
48
51
  }
49
52
  console.log('Usage: sprid release <command> [flags]\n');
50
53
  console.log('Commands:');
51
- for (const name of ['ship', 'bump', 'asc-upload', 'play-upload', 'asc-submit', 'metadata', 'screenshots', 'graphics']) console.log(` ${COMMANDS[name].usage}`);
54
+ for (const name of ['ship', 'bump', 'credentials-pull', 'credentials-push', 'asc-upload', 'play-upload', 'asc-submit', 'metadata', 'screenshots', 'graphics']) console.log(` ${COMMANDS[name].usage}`);
52
55
  console.log('\nWithout --execute every command is a dry run: it prints what it would send.');
53
56
  console.log('Per-store names also work: asc-metadata, play-metadata, asc-screenshots, play-screenshots, play-graphics.');
54
57
  console.log('\n--config <file> accepts TS, JS, MJS or JSON. Paths resolve beside that file.');
@@ -122,6 +125,12 @@ async function main() {
122
125
  return;
123
126
  }
124
127
  if (command === 'bump') { if (execute) bumpVersion(config, bumpKinds[0]); else console.log({ current: readAppVersion(config), bump: bumpKinds[0] ?? 'build' }); return; }
128
+ if (command === 'credentials-pull' || command === 'credentials-push') {
129
+ const platforms = { ios: !has('android-only'), android: !has('ios-only') };
130
+ if (command === 'credentials-pull') await pullEasCredentials(config, { execute, ...platforms });
131
+ else await pushEasCredentials(config, { execute, replace: has('replace'), from: value('from') && releasePath(config, value('from')!), ...platforms });
132
+ return;
133
+ }
125
134
  if (command === 'asc-upload') { const path = releasePath(config, requireValue('ipa')); if (execute) await uploadIpa(config, path); else console.log(`Upload IPA: ${path}`); return; }
126
135
  if (command === 'play-upload') {
127
136
  const path = releasePath(config, requireValue('aab')); const version = requireValue('version'); const track = value('track') ?? 'production';
package/src/config.ts CHANGED
@@ -161,6 +161,13 @@ export interface BuildConfig {
161
161
  * For paths relative to the repo root, set `'.'`.
162
162
  */
163
163
  credentialsPathBase?: string;
164
+ /**
165
+ * Where signing credentials come from. `'local'` (default) reads
166
+ * credentials.json as below. `'eas'` downloads the project's EAS credentials
167
+ * into a private folder (see `eas`) at the start of every `ship`, so EAS is
168
+ * the one copy and nothing on this machine has to be kept in sync.
169
+ */
170
+ credentialsSource?: 'local' | 'eas';
164
171
  /**
165
172
  * Checks to run in `appDir` BEFORE the version bump, so a failure costs
166
173
  * seconds instead of a finished archive sitting on a bad tree.
@@ -293,6 +300,13 @@ export interface AppReleaseConfig {
293
300
  requiredProdEnv?: (string | RequiredEnvVar)[];
294
301
  /** Local build + sign mechanics, needed by the `ship` command. */
295
302
  build?: BuildConfig;
303
+ /** EAS project whose credentials `credentials-pull`/`-push` and `credentialsSource: 'eas'` use. */
304
+ eas?: {
305
+ /** `@owner/slug`. Default: read from the Expo app config's `owner` + `slug`. */
306
+ project?: string;
307
+ /** Where pulled credentials are written. Default `~/.sprid/eas-credentials/<owner>/<slug>`. */
308
+ credentialsDir?: string;
309
+ };
296
310
  /** Store-listing copy by copy-locale key — lets the metadata commands run with no app script. */
297
311
  storeCopy?: Record<string, StoreCopy>;
298
312
  /** Play listing contact/default-language details. */
@@ -0,0 +1,326 @@
1
+ /**
2
+ * Signing credentials held by Expo (EAS), used by a local build.
3
+ *
4
+ * EAS is a good place to KEEP signing material: one encrypted copy per project,
5
+ * shared by everyone on the account, and what `eas build` would sign with if a
6
+ * team ever moves there. It is not where this package builds or submits. So:
7
+ *
8
+ * credentials-push upload a local credentials.json to EAS (one-time setup)
9
+ * credentials-pull download EAS's copy into a private local folder
10
+ * ship pulls first when `build.credentialsSource` is 'eas'
11
+ *
12
+ * Everything goes through EAS's GraphQL API, the same one `eas credentials`
13
+ * uses, because that command is an interactive menu with no flags. Auth is
14
+ * `$EXPO_TOKEN` (CI) or the session `eas login` leaves in ~/.expo/state.json.
15
+ * No secret is ever printed; the dry run reports fingerprints and ids only.
16
+ */
17
+ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
18
+ import { spawnSync } from 'node:child_process';
19
+ import { createHash } from 'node:crypto';
20
+ import { homedir } from 'node:os';
21
+ import { dirname, isAbsolute, resolve } from 'node:path';
22
+ import { releasePath, resolveCredentialsJson, type AppReleaseConfig } from '../config.ts';
23
+
24
+ const ENDPOINT = 'https://api.expo.dev/graphql';
25
+
26
+ // ── transport ────────────────────────────────────────────────────────────────
27
+
28
+ function authHeaders(): Record<string, string> {
29
+ if (process.env.EXPO_TOKEN) return { authorization: `Bearer ${process.env.EXPO_TOKEN}` };
30
+ const statePath = resolve(homedir(), '.expo/state.json');
31
+ const secret = existsSync(statePath)
32
+ ? (JSON.parse(readFileSync(statePath, 'utf8')).auth?.sessionSecret as string | undefined)
33
+ : undefined;
34
+ if (!secret) throw new Error('Not signed in to Expo. Run `eas login`, or set EXPO_TOKEN.');
35
+ return { 'expo-session': secret };
36
+ }
37
+
38
+ export type Gql = (query: string, variables?: Record<string, unknown>) => Promise<any>;
39
+
40
+ export function createEasClient(fetchImpl: typeof fetch = fetch): Gql {
41
+ const headers = { 'content-type': 'application/json', ...authHeaders() };
42
+ return async (query, variables = {}) => {
43
+ const res = await fetchImpl(ENDPOINT, { method: 'POST', headers, body: JSON.stringify({ query, variables }) });
44
+ const body = (await res.json().catch(() => ({}))) as { data?: any; errors?: { message: string }[] };
45
+ if (!res.ok || body.errors?.length) {
46
+ throw new Error(`EAS API: ${body.errors?.map((e) => e.message).join('; ') ?? res.status}`);
47
+ }
48
+ return body.data;
49
+ };
50
+ }
51
+
52
+ // ── project ──────────────────────────────────────────────────────────────────
53
+
54
+ /** `@owner/slug`: `eas.project` when set, else read from the Expo app config's owner + slug. */
55
+ export function easProjectName(config: AppReleaseConfig): string {
56
+ if (config.eas?.project) return config.eas.project;
57
+ const appJsonPath = config.configFile?.format === 'split'
58
+ ? releasePath(config, config.configFile.buildConfigPath!)
59
+ : config.configFile && releasePath(config, config.configFile.path);
60
+ if (appJsonPath?.endsWith('.json') && existsSync(appJsonPath)) {
61
+ const expo = JSON.parse(readFileSync(appJsonPath, 'utf8')).expo ?? {};
62
+ if (expo.owner && expo.slug) return `@${expo.owner}/${expo.slug}`;
63
+ }
64
+ throw new Error('Set eas.project ("@owner/slug") in the release config; it could not be read from the app config.');
65
+ }
66
+
67
+ /** Where pulled credentials land: private to this user, outside every repo. */
68
+ export function easCredentialsDir(config: AppReleaseConfig): string {
69
+ if (config.eas?.credentialsDir) return releasePath(config, config.eas.credentialsDir);
70
+ return resolve(homedir(), '.sprid/eas-credentials', easProjectName(config).replace(/^@/, ''));
71
+ }
72
+
73
+ interface IosTarget {
74
+ target: string;
75
+ bundleId: string;
76
+ /** Path relative to the credentials folder, as credentials.json and iosExtensions name it. */
77
+ profilePath: string;
78
+ }
79
+
80
+ function iosTargets(config: AppReleaseConfig): IosTarget[] {
81
+ if (!config.appId) return [];
82
+ return [
83
+ { target: config.build?.xcodeName ?? 'app', bundleId: config.appId, profilePath: `ios/${config.appId}.mobileprovision` },
84
+ ...(config.build?.iosExtensions ?? []).map((e) => {
85
+ if (isAbsolute(e.profilePath)) throw new Error(`iosExtensions profilePath must be relative when credentials come from EAS: ${e.profilePath}`);
86
+ return { target: e.target, bundleId: e.bundleId, profilePath: e.profilePath };
87
+ }),
88
+ ];
89
+ }
90
+
91
+ function androidPackage(config: AppReleaseConfig): string | undefined {
92
+ return config.play?.packageName;
93
+ }
94
+
95
+ const sha256 = (b64: string) => createHash('sha256').update(Buffer.from(b64, 'base64')).digest('hex').slice(0, 16);
96
+
97
+ // ── read ─────────────────────────────────────────────────────────────────────
98
+
99
+ const PROJECT_QUERY = `query($name: String!) { app { byFullName(fullName: $name) {
100
+ id
101
+ ownerAccount { id name appleTeams { id appleTeamIdentifier } }
102
+ androidAppCredentials { id applicationIdentifier androidAppBuildCredentialsList {
103
+ id name isDefault androidKeystore { id keystore keystorePassword keyAlias keyPassword sha256CertificateFingerprint } } }
104
+ iosAppCredentials { id appleAppIdentifier { id bundleIdentifier } iosAppBuildCredentialsList {
105
+ id iosDistributionType
106
+ distributionCertificate { id serialNumber certificateP12 certificatePassword developerPortalIdentifier validityNotAfter }
107
+ provisioningProfile { id provisioningProfile developerPortalIdentifier expiration } } }
108
+ } } }`;
109
+
110
+ async function readProject(gql: Gql, name: string) {
111
+ const app = (await gql(PROJECT_QUERY, { name })).app.byFullName;
112
+ if (!app) throw new Error(`EAS project ${name} not found, or this login cannot see it.`);
113
+ return app;
114
+ }
115
+
116
+ // ── pull ─────────────────────────────────────────────────────────────────────
117
+
118
+ export interface PullResult {
119
+ credentialsJson: string;
120
+ wrote: string[];
121
+ }
122
+
123
+ /**
124
+ * Download the default Android keystore and the App Store credentials for the
125
+ * app and every iOS extension, and write a credentials.json in the layout
126
+ * `loadSigningCredentials` reads. Missing platforms are skipped, not faked.
127
+ */
128
+ export async function pullEasCredentials(
129
+ config: AppReleaseConfig,
130
+ opts: { execute: boolean; ios?: boolean; android?: boolean; gql?: Gql } = { execute: false },
131
+ ): Promise<PullResult> {
132
+ const name = easProjectName(config);
133
+ const dir = easCredentialsDir(config);
134
+ const credentialsJson = resolve(dir, 'credentials.json');
135
+ const gql = opts.gql ?? createEasClient();
136
+ const app = await readProject(gql, name);
137
+ const out: Record<string, any> = {};
138
+ const files: [string, Buffer][] = [];
139
+
140
+ const pkg = androidPackage(config);
141
+ if (opts.android !== false && pkg) {
142
+ const creds = app.androidAppCredentials.find((c: any) => c.applicationIdentifier === pkg);
143
+ const build = creds?.androidAppBuildCredentialsList.find((b: any) => b.isDefault) ?? creds?.androidAppBuildCredentialsList[0];
144
+ const ks = build?.androidKeystore;
145
+ if (!ks) throw new Error(`EAS holds no keystore for ${pkg} on ${name}. Run credentials-push first.`);
146
+ files.push(['android/keystore.jks', Buffer.from(ks.keystore, 'base64')]);
147
+ out.android = { keystore: { keystorePath: 'android/keystore.jks', keystorePassword: ks.keystorePassword, keyAlias: ks.keyAlias, keyPassword: ks.keyPassword ?? ks.keystorePassword } };
148
+ console.log(` android ${pkg}: keystore ${ks.keyAlias} (SHA-256 ${ks.sha256CertificateFingerprint})`);
149
+ }
150
+
151
+ if (opts.ios !== false) {
152
+ for (const [i, t] of iosTargets(config).entries()) {
153
+ const creds = app.iosAppCredentials.find((c: any) => c.appleAppIdentifier.bundleIdentifier === t.bundleId);
154
+ const build = creds?.iosAppBuildCredentialsList.find((b: any) => b.iosDistributionType === 'APP_STORE');
155
+ if (!build?.distributionCertificate || !build?.provisioningProfile) {
156
+ throw new Error(`EAS holds no App Store credentials for ${t.bundleId} on ${name}. Run credentials-push first.`);
157
+ }
158
+ const cert = build.distributionCertificate;
159
+ files.push([t.profilePath, Buffer.from(build.provisioningProfile.provisioningProfile, 'base64')]);
160
+ if (i === 0) {
161
+ files.push(['ios/dist-cert.p12', Buffer.from(cert.certificateP12, 'base64')]);
162
+ out.ios = { distributionCertificate: { path: 'ios/dist-cert.p12', password: cert.certificatePassword }, provisioningProfilePath: t.profilePath };
163
+ }
164
+ console.log(` ios ${t.bundleId}: cert ${cert.developerPortalIdentifier ?? cert.serialNumber}, profile ${build.provisioningProfile.developerPortalIdentifier ?? build.provisioningProfile.id} (expires ${build.provisioningProfile.expiration?.slice(0, 10)})`);
165
+ }
166
+ }
167
+
168
+ if (!opts.execute) {
169
+ console.log(`\n Dry run. Would write ${files.length + 1} files to ${dir}`);
170
+ return { credentialsJson, wrote: [] };
171
+ }
172
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
173
+ chmodSync(dir, 0o700);
174
+ const wrote: string[] = [];
175
+ for (const [rel, bytes] of files) {
176
+ const path = resolve(dir, rel);
177
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
178
+ writeFileSync(path, bytes, { mode: 0o600 });
179
+ wrote.push(path);
180
+ }
181
+ writeFileSync(credentialsJson, JSON.stringify(out, null, 2), { mode: 0o600 });
182
+ wrote.push(credentialsJson);
183
+ console.log(` Wrote ${wrote.length} files to ${dir}`);
184
+ return { credentialsJson, wrote };
185
+ }
186
+
187
+ // ── push ─────────────────────────────────────────────────────────────────────
188
+
189
+ /**
190
+ * Upload the local credentials.json (the one `ship` would otherwise sign with)
191
+ * to EAS. Idempotent: a keystore, certificate or profile EAS already holds
192
+ * byte for byte is reused, never duplicated. A DIFFERENT default Android
193
+ * keystore is refused unless `replace`, because swapping an upload key is a
194
+ * Play Console conversation, not a sync.
195
+ */
196
+ export async function pushEasCredentials(
197
+ config: AppReleaseConfig,
198
+ opts: { execute: boolean; replace?: boolean; ios?: boolean; android?: boolean; from?: string; gql?: Gql } = { execute: false },
199
+ ): Promise<void> {
200
+ const name = easProjectName(config);
201
+ const gql = opts.gql ?? createEasClient();
202
+ const app = await readProject(gql, name);
203
+ const accountId = app.ownerAccount.id;
204
+ const { path, base } = opts.from ? { path: opts.from, base: dirname(opts.from) } : resolveCredentialsJson(config);
205
+ const local = JSON.parse(readFileSync(path, 'utf8'));
206
+ console.log(` From ${path}\n To EAS ${name}${opts.execute ? '' : ' (dry run)'}\n`);
207
+ const run = async (label: string, fn: () => Promise<unknown>) => {
208
+ console.log(` ${opts.execute ? '+' : '~'} ${label}`);
209
+ if (opts.execute) await fn();
210
+ };
211
+
212
+ // Android: the keystore becomes the project's default build credentials.
213
+ const pkg = androidPackage(config);
214
+ if (opts.android !== false && pkg && local.android?.keystore) {
215
+ const k = local.android.keystore;
216
+ const b64 = readFileSync(resolve(base, k.keystorePath)).toString('base64');
217
+ let creds = app.androidAppCredentials.find((c: any) => c.applicationIdentifier === pkg);
218
+ const current = creds?.androidAppBuildCredentialsList.find((b: any) => b.isDefault);
219
+ if (current?.androidKeystore?.keystore === b64) {
220
+ console.log(` = android ${pkg}: EAS already holds this keystore as the default`);
221
+ } else if (current?.androidKeystore && !opts.replace) {
222
+ throw new Error(
223
+ `EAS already has a different default keystore for ${pkg} (${current.androidKeystore.keyAlias}, SHA-256 ${current.androidKeystore.sha256CertificateFingerprint}). ` +
224
+ 'Pass --replace only if Play Console expects the local one.',
225
+ );
226
+ } else {
227
+ await run(`android ${pkg}: keystore ${k.keyAlias} (${sha256(b64)}) as the default build credentials`, async () => {
228
+ if (!creds) {
229
+ creds = (await gql(`mutation($a: ID!, $p: String!) { androidAppCredentials { createAndroidAppCredentials(androidAppCredentialsInput: {}, appId: $a, applicationIdentifier: $p) { id } } }`, { a: app.id, p: pkg })).androidAppCredentials.createAndroidAppCredentials;
230
+ }
231
+ const ks = (await gql(`mutation($i: AndroidKeystoreInput!, $a: ID!) { androidKeystore { createAndroidKeystore(androidKeystoreInput: $i, accountId: $a) { id } } }`, {
232
+ i: { base64EncodedKeystore: b64, keystorePassword: k.keystorePassword, keyAlias: k.keyAlias, keyPassword: k.keyPassword },
233
+ a: accountId,
234
+ })).androidKeystore.createAndroidKeystore;
235
+ if (current) {
236
+ await gql(`mutation($b: ID!, $k: ID!) { androidAppBuildCredentials { setKeystore(id: $b, keystoreId: $k) { id } } }`, { b: current.id, k: ks.id });
237
+ } else {
238
+ await gql(`mutation($i: AndroidAppBuildCredentialsInput!, $c: ID!) { androidAppBuildCredentials { createAndroidAppBuildCredentials(androidAppBuildCredentialsInput: $i, androidAppCredentialsId: $c) { id } } }`, {
239
+ i: { isDefault: true, name: 'release', keystoreId: ks.id },
240
+ c: creds!.id,
241
+ });
242
+ }
243
+ });
244
+ }
245
+ }
246
+
247
+ // iOS: one App Store build credential per target, all on the same certificate.
248
+ if (opts.ios !== false && local.ios?.distributionCertificate && config.appId) {
249
+ const teamIdentifier = config.appleTeamId;
250
+ const team = app.ownerAccount.appleTeams.find((t: any) => t.appleTeamIdentifier === teamIdentifier);
251
+ if (!team) throw new Error(`EAS account ${app.ownerAccount.name} has no Apple team ${teamIdentifier}. Run \`eas credentials\` once with an Apple login to register it.`);
252
+
253
+ const account = (await gql(`query($n: String!) { account { byName(accountName: $n) { appleDistributionCertificates { id serialNumber } } } }`, { n: app.ownerAccount.name })).account.byName;
254
+ const p12 = readFileSync(resolve(base, local.ios.distributionCertificate.path));
255
+ const serial = p12Serial(p12, local.ios.distributionCertificate.password);
256
+ let certId: string | undefined = account.appleDistributionCertificates.find((c: any) => c.serialNumber?.toUpperCase() === serial)?.id;
257
+ if (certId) console.log(` = ios distribution certificate ${serial}: already on EAS`);
258
+ else {
259
+ await run(`ios distribution certificate ${serial}`, async () => {
260
+ certId = (await gql(`mutation($i: AppleDistributionCertificateInput!, $a: ID!) { appleDistributionCertificate { createAppleDistributionCertificate(appleDistributionCertificateInput: $i, accountId: $a) { id } } }`, {
261
+ i: { certP12: p12.toString('base64'), certPassword: local.ios.distributionCertificate.password, appleTeamId: team.id },
262
+ a: accountId,
263
+ })).appleDistributionCertificate.createAppleDistributionCertificate.id;
264
+ });
265
+ }
266
+
267
+ let parentIdentifierId: string | undefined;
268
+ for (const [i, t] of iosTargets(config).entries()) {
269
+ const profilePath = i === 0 ? resolve(base, local.ios.provisioningProfilePath) : resolve(base, t.profilePath);
270
+ const profile = readFileSync(profilePath).toString('base64');
271
+ let creds = app.iosAppCredentials.find((c: any) => c.appleAppIdentifier.bundleIdentifier === t.bundleId);
272
+ const build = creds?.iosAppBuildCredentialsList.find((b: any) => b.iosDistributionType === 'APP_STORE');
273
+ if (build?.provisioningProfile?.provisioningProfile === profile && build?.distributionCertificate?.serialNumber?.toUpperCase() === serial) {
274
+ console.log(` = ios ${t.bundleId}: EAS already holds this profile and certificate`);
275
+ parentIdentifierId ??= creds.appleAppIdentifier.id;
276
+ continue;
277
+ }
278
+ await run(`ios ${t.bundleId}: App Store profile ${profilePath.split('/').pop()} on certificate ${serial}`, async () => {
279
+ let identifierId: string = creds?.appleAppIdentifier.id;
280
+ if (!identifierId) {
281
+ const found = (await gql(`query($n: String!, $b: String!) { account { byName(accountName: $n) { appleAppIdentifiers(bundleIdentifier: $b) { id } } } }`, { n: app.ownerAccount.name, b: t.bundleId })).account.byName.appleAppIdentifiers[0];
282
+ identifierId = found?.id ?? (await gql(`mutation($i: AppleAppIdentifierInput!, $a: ID!) { appleAppIdentifier { createAppleAppIdentifier(appleAppIdentifierInput: $i, accountId: $a) { id } } }`, {
283
+ i: { bundleIdentifier: t.bundleId, appleTeamId: team.id, ...(i > 0 && parentIdentifierId ? { parentAppleAppId: parentIdentifierId } : {}) },
284
+ a: accountId,
285
+ })).appleAppIdentifier.createAppleAppIdentifier.id;
286
+ }
287
+ if (i === 0) parentIdentifierId = identifierId;
288
+ if (!creds) {
289
+ creds = (await gql(`mutation($i: IosAppCredentialsInput!, $a: ID!, $id: ID!) { iosAppCredentials { createIosAppCredentials(iosAppCredentialsInput: $i, appId: $a, appleAppIdentifierId: $id) { id } } }`, {
290
+ i: { appleTeamId: team.id }, a: app.id, id: identifierId,
291
+ })).iosAppCredentials.createIosAppCredentials;
292
+ }
293
+ const profileId = (await gql(`mutation($i: AppleProvisioningProfileInput!, $a: ID!, $id: ID!) { appleProvisioningProfile { createAppleProvisioningProfile(appleProvisioningProfileInput: $i, accountId: $a, appleAppIdentifierId: $id) { id } } }`, {
294
+ i: { appleProvisioningProfile: profile }, a: accountId, id: identifierId,
295
+ })).appleProvisioningProfile.createAppleProvisioningProfile.id;
296
+ if (build) {
297
+ await gql(`mutation($b: ID!, $c: ID!) { iosAppBuildCredentials { setDistributionCertificate(id: $b, distributionCertificateId: $c) { id } } }`, { b: build.id, c: certId });
298
+ await gql(`mutation($b: ID!, $p: ID!) { iosAppBuildCredentials { setProvisioningProfile(id: $b, provisioningProfileId: $p) { id } } }`, { b: build.id, p: profileId });
299
+ } else {
300
+ await gql(`mutation($i: IosAppBuildCredentialsInput!, $c: ID!) { iosAppBuildCredentials { createIosAppBuildCredentials(iosAppBuildCredentialsInput: $i, iosAppCredentialsId: $c) { id } } }`, {
301
+ i: { iosDistributionType: 'APP_STORE', distributionCertificateId: certId, provisioningProfileId: profileId },
302
+ c: creds.id,
303
+ });
304
+ }
305
+ });
306
+ if (i === 0) parentIdentifierId ??= creds?.appleAppIdentifier?.id;
307
+ }
308
+ }
309
+ if (!opts.execute) console.log('\n Dry run. Nothing was sent to EAS. Add --execute to upload.');
310
+ }
311
+
312
+ /** The certificate serial inside a .p12, upper-case hex, as EAS stores it. */
313
+ function p12Serial(p12: Buffer, password: string): string {
314
+ const read = (legacy: boolean) =>
315
+ spawnSync('openssl', ['pkcs12', '-nokeys', '-passin', 'env:P12_PASSWORD', ...(legacy ? ['-legacy'] : [])], {
316
+ input: p12,
317
+ env: { ...process.env, P12_PASSWORD: password },
318
+ });
319
+ let pem = read(true);
320
+ if (pem.status !== 0) pem = read(false);
321
+ if (pem.status !== 0) throw new Error('Could not open the distribution certificate .p12 (wrong password?).');
322
+ const serial = spawnSync('openssl', ['x509', '-noout', '-serial'], { input: pem.stdout }).stdout.toString();
323
+ const match = serial.match(/serial=([0-9A-Fa-f]+)/);
324
+ if (!match) throw new Error('Could not read the certificate serial from the .p12.');
325
+ return match[1].toUpperCase();
326
+ }
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from './asc/index.ts';
7
7
  export * from './play/index.ts';
8
8
 
9
9
  export { ship, type ShipOptions } from './ship.ts';
10
+ export { pullEasCredentials, pushEasCredentials, easProjectName, easCredentialsDir } from './eas/credentials.ts';
10
11
  export { bumpVersion, readAppVersion, type AppVersion, type BumpKind } from './bump.ts';
11
12
  export { uploadIpa } from './asc/upload.ts';
12
13
  export { submitForReview, type SubmitOptions } from './asc/submit.ts';
@@ -97,10 +97,13 @@ export async function finalizePlayRelease(config: AppReleaseConfig, opts: {
97
97
  console.log(` ✓ Android upload complete${sendForReview ? ' (sent for review).' : ' (not sent for review).'}`);
98
98
  } catch (err: any) {
99
99
  const body = err?.message ?? '';
100
- if (sendForReview && String(body).includes('changesNotSentForReview must not be set')) {
100
+ // An app in auto-send mode (every new app, until its first release)
101
+ // refuses the flag either way. A draft release is never reviewed, so
102
+ // committing without it only sends what was asked for.
103
+ if (String(body).includes('changesNotSentForReview must not be set')) {
101
104
  console.log(' Play auto-sends edits for review; retrying without the flag.');
102
105
  await play.edits.commit({ packageName, editId });
103
- console.log(' ✓ Android upload complete (sent for review by Google auto-send mode).');
106
+ console.log(` ✓ Android upload complete (${release.status === 'draft' ? 'saved as a draft release' : 'sent for review by Google auto-send mode'}).`);
104
107
  } else {
105
108
  throw err;
106
109
  }
package/src/ship.ts CHANGED
@@ -5,6 +5,7 @@ import type { BumpKind } from './bump.ts';
5
5
  import { bumpVersion, readAppVersion } from './bump.ts';
6
6
  import { assertRequiredProdEnv } from './env-guard.ts';
7
7
  import { loadSigningCredentials } from './build/credentials.ts';
8
+ import { pullEasCredentials } from './eas/credentials.ts';
8
9
  import { loadSentryToken } from './build/sentry.ts';
9
10
  import { exportPublicEnvFromEas, loadBuildEnv } from './build/env-sources.ts';
10
11
  import { hideEnvFiles } from './build/env-files.ts';
@@ -120,7 +121,16 @@ export async function ship(config: AppReleaseConfig, opts: ShipOptions = {}): Pr
120
121
  // Load configured public settings and allowlisted build secrets before prebuild.
121
122
  exportPublicEnvFromEas(config);
122
123
  loadBuildEnv(config);
123
- const creds = !((ios && !config.build.commands?.ios) || (android && !config.build.commands?.android)) ? {} : loadSigningCredentials(config, { ios: ios && !config.build.commands?.ios, android: android && !config.build.commands?.android });
124
+ const signIos = ios && !config.build.commands?.ios;
125
+ const signAndroid = android && !config.build.commands?.android;
126
+ let signingConfig = config;
127
+ if ((signIos || signAndroid) && config.build.credentialsSource === 'eas') {
128
+ // EAS holds the signing material; fetch this run's copy before loading it.
129
+ console.log('── Pulling signing credentials from EAS...');
130
+ const pulled = await pullEasCredentials(config, { execute: true, ios: signIos, android: signAndroid });
131
+ signingConfig = { ...config, build: { ...config.build, credentialsJson: pulled.credentialsJson, credentialsPathBase: undefined } };
132
+ }
133
+ const creds = !(signIos || signAndroid) ? {} : loadSigningCredentials(signingConfig, { ios: signIos, android: signAndroid });
124
134
  const sentryToken = loadSentryToken(config);
125
135
 
126
136
  if (opts.skipBump) console.log('── Skipping version bump.');