Compare commits

...
Author SHA1 Message Date
Expo CI 102f06cc50 v24.14.0 2026-10-14 21:08:28 +00:00
Gabe Debes f96c266645 [build-tools] Allow iOS recordings to finish before shutdown (#4626) 2026-10-14 13:19:11 -07:00
Tomasz Mazur 5739556d67 [build-tools] download the upterm binary through build cache (#4442) 2026-10-14 14:20:52 +00:00
Ash Wu 821dcd1a96 [eas-cli] add a platform filter and per-platform totals to workflow:insights:maestro (#4613)
* [eas-cli] regenerate GraphQL types

* [eas-cli] add a platform filter and per-platform totals to workflow:insights:maestro
2026-10-14 16:36:04 +08:00
Byron Karlen 3b59a744da [docs] Add protected resources page (#4616) 2026-10-13 15:56:16 -07:00
Szymon DziedzicandClaude Opus 5.5 73edec4d68 [build-tools] Disable Argent video watermark in remote sessions (#4574)
* [build-tools] Disable Argent video watermark in remote sessions

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [build-tools] Add changelog entry for Argent watermark change

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [build-tools] Continue the Argent session when disabling the video watermark fails

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
2026-10-13 16:05:03 +02:00
Stanisław Chmiela 13fe586f3f [build-tools] Add native Google Play submission function (#4512)
# Why

To remove submission service altogether we also need to support Google Play uploads here.

# How

Adds `eas/submit_to_google_play`: load the service account, create an edit, upload the APK/AAB, update the track, and commit. Returns `version_code` after the commit succeeds.

The binary, its type, and package name come from the caller. We'll use `eas/download_build` and `eas/read_android_app_info` for that.

# Test Plan

- CI should pass.
- Full live submission passed on October 8 with current source `5915d062d`: uploaded an AAB for `com.exposervices.workflowstesting` to `internal` as draft version `146`. The default review setting worked without a retry. A fresh edit confirmed the draft and release notes. Temporary credentials and binaries were removed.
2026-10-13 15:40:19 +02:00
Stanisław Chmiela c3413315d1 [build-tools] Add resumable Google Play uploads (#4516)
# Why

When uploading files to Google Play it's best we do this thing called "resumable uploads".

# How

Added more utils and a separate namespace that handles:
- creating the upload session
- uploading to the upload session in chunks.

It tries to be smart about errors and retries. Mostly AI-driven code.

# Test Plan

CI should pass. Also tested live with staging key.
2026-10-13 12:23:56 +02:00
Kudo Chien 6c256fd9d2 [build-tools] Open Android URLs in the app package instead of the launch activity (#4559) 2026-10-13 13:10:46 +08:00
42 changed files with 3046 additions and 274 deletions

No files matched your search

+9
View File
@@ -8,10 +8,18 @@ This is the log of notable changes to EAS CLI and related packages.
### 🎉 New features
- [eas-cli] Add `--platform` to `eas workflow:insights:maestro` and list Maestro runs and flows per platform. ([#4613](https://github.com/expo/eas-cli/pull/4613) by [@hSATAC](https://github.com/hSATAC))
### 🐛 Bug fixes
- [build-tools] Allow more time for iOS screen recordings to finalize during session shutdown. ([#4626](https://github.com/expo/eas-cli/pull/4626) by [@gwdp](https://github.com/gwdp))
### 🧹 Chores
- [eas-cli] Fix the `channel:protect` and `channel:unprotect` descriptions to include Release Managers and Owners, not only admins. ([#4616](https://github.com/expo/eas-cli/pull/4616) by [@byronkarlen](https://github.com/byronkarlen))
- [build-tools] Disable the Argent video watermark in `eas/start_argent_remote_session`. ([#4574](https://github.com/expo/eas-cli/pull/4574) by [@szdziedzic](https://github.com/szdziedzic))
- [build-tools] Download the upterm binary through the build cache proxy. ([#4442](https://github.com/expo/eas-cli/pull/4442) by [@AHGIJMKLKKZNPJKQR](https://github.com/AHGIJMKLKKZNPJKQR))
## [24.13.0](https://github.com/expo/eas-cli/releases/tag/v24.13.0) - 2026-10-12
### 🎉 New features
@@ -54,6 +62,7 @@ This is the log of notable changes to EAS CLI and related packages.
- [build-tools] Improve the embedded bundle upload output in build logs. ([#4557](https://github.com/expo/eas-cli/pull/4557) by [@gwdp](https://github.com/gwdp))
- [build-tools] Allow the unnotarized mitmproxy cask to run in iOS network capture sessions. ([#4556](https://github.com/expo/eas-cli/pull/4556) by [@gwdp](https://github.com/gwdp))
- [build-tools] Encode macOS simulator session previews with cwebp, because Homebrew's FFmpeg cannot encode WebP. ([#4549](https://github.com/expo/eas-cli/pull/4549) by [@szdziedzic](https://github.com/szdziedzic))
- [build-tools] Open Android URLs with a VIEW intent instead of pinning them to the launch activity. ([#4559](https://github.com/expo/eas-cli/pull/4559) by [@kudo](https://github.com/kudo))
### 🧹 Chores
+1 -1
View File
@@ -1,5 +1,5 @@
{
"npmClient": "yarn",
"version": "24.13.0",
"version": "24.14.0",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@expo/build-tools",
"version": "24.13.0",
"version": "24.14.0",
"bugs": "https://github.com/expo/eas-cli/issues",
"license": "BUSL-1.1",
"author": "Expo <[email protected]>",
@@ -11,7 +11,7 @@ import { getEasFunctions } from '../easFunctions';
jest.mock('fs');
describe('hook anchor self-declarations', () => {
it('exactly the four v0 functions declare anchors, with these bindings', () => {
it('declares the expected hook anchors', () => {
const declarations: Record<string, HookAnchorId> = {};
for (const buildFunction of getEasFunctions(createCustomBuildContextMock())) {
if (buildFunction.__hookId !== undefined) {
@@ -24,6 +24,7 @@ describe('hook anchor self-declarations', () => {
'eas/checkout': 'checkout',
'eas/install_node_modules': 'install_node_modules',
'eas/upload_to_asc': 'submit',
'eas/submit_to_google_play': 'submit',
'eas/maestro_tests': 'maestro_tests',
});
});
@@ -87,6 +88,17 @@ describe('hook anchor self-declarations', () => {
bundle_short_version: '1.0.0',
},
],
[
'eas/submit_to_google_play',
'before_submit',
'after_submit',
{
artifact_path: 'app.aab',
artifact_type: 'aab',
package_name: 'com.example.app',
service_account_key_path: 'key.json',
},
],
[
'eas/maestro_tests',
'before_maestro_tests',
@@ -29,6 +29,7 @@ import { createPrebuildBuildFunction } from './functions/prebuild';
import { createReadAppConfigBuildFunction } from './functions/readAppConfig';
import { createReadIpaInfoBuildFunction } from './functions/readIpaInfo';
import { createReadAndroidAppInfoBuildFunction } from './functions/readAndroidAppInfo';
import { createSubmitToGooglePlayBuildFunction } from './functions/submitToGooglePlay';
import { createReadPackageJsonBuildFunction } from './functions/readPackageJson';
import { createRepackBuildFunction } from './functions/repack';
import { createReportMaestroTestResultsFunction } from './functions/reportMaestroTestResults';
@@ -141,6 +142,7 @@ export function getEasFunctions(ctx: CustomBuildContext): BuildFunction[] {
calculateEASUpdateRuntimeVersionFunction(),
createSubmissionEntityFunction(),
createSubmitToGooglePlayBuildFunction(),
createUploadToAscBuildFunction(),
createUpdateTestFlightMetadataBuildFunction(),
@@ -179,17 +179,7 @@ describe(launchApplicationAsync, () => {
expect(mockedSpawn).toHaveBeenNthCalledWith(
2,
'adb',
[
'shell',
'am',
'start',
'-a',
'android.intent.action.VIEW',
'-d',
'exp://example.test',
'-n',
'host.exp.exponent/host.exp.exponent.MainActivity',
],
['shell', 'am', 'start', '-a', 'android.intent.action.VIEW', '-d', 'exp://example.test'],
{ env: {}, logger }
);
expect(logger.info).toHaveBeenNthCalledWith(
@@ -242,17 +232,7 @@ describe(launchApplicationAsync, () => {
);
expect(mockedSpawn).toHaveBeenCalledWith(
'adb',
[
'shell',
'am',
'start',
'-a',
'android.intent.action.VIEW',
'-d',
'exp://example.test',
'-n',
'com.example.app/com.example.app.MainActivity',
],
['shell', 'am', 'start', '-a', 'android.intent.action.VIEW', '-d', 'exp://example.test'],
expect.any(Object)
);
});
@@ -188,7 +188,7 @@ describe('createStartArgentRemoteSessionBuildFunction orchestration', () => {
}
);
it('enables the event log flag, shares one path, and starts/stops the collector', async () => {
it('enables the event log flag, disables the video watermark, shares one path, and starts/stops the collector', async () => {
const ctx = {} as unknown as CustomBuildContext;
const buildFunction = createStartArgentRemoteSessionBuildFunction(ctx);
@@ -231,6 +231,20 @@ describe('createStartArgentRemoteSessionBuildFunction orchestration', () => {
jest.mocked(spawnDetached).mock.invocationCallOrder[0]
);
// (2b) The video watermark flag is disabled, before the tool-server is launched.
const disableWatermarkIndex = spawnCalls.findIndex(
([command, args]) =>
command === 'bun' &&
Array.isArray(args) &&
args[0] === 'x' &&
args.includes('disable') &&
args.includes('video-watermark')
);
expect(disableWatermarkIndex).toBeGreaterThanOrEqual(0);
expect(jest.mocked(spawn).mock.invocationCallOrder[disableWatermarkIndex]).toBeLessThan(
jest.mocked(spawnDetached).mock.invocationCallOrder[0]
);
// (3) The tool-server and the collector are pinned to the exact same event log path.
const serverEnv = jest.mocked(spawnDetached).mock.calls[0][0].env;
expect(serverEnv.ARGENT_EVENT_LOG).toBe(EXPECTED_EVENT_LOG_PATH);
@@ -267,6 +281,43 @@ describe('createStartArgentRemoteSessionBuildFunction orchestration', () => {
expect(mockPreviewStopAsync).toHaveBeenCalledTimes(1);
});
it('continues the session when disabling the video watermark fails', async () => {
const error = new Error('bun x failed');
jest
.mocked(spawn)
.mockImplementation(
(_command, args) =>
(args.includes('video-watermark')
? Promise.reject(error)
: Promise.resolve(undefined)) as never
);
const logger = { info: jest.fn(), warn: jest.fn() };
const buildFunction = createStartArgentRemoteSessionBuildFunction({} as CustomBuildContext);
await buildFunction.fn!(
{
logger,
global: { runtimePlatform: BuildRuntimePlatform.LINUX },
} as unknown as BuildStepContext,
{
inputs: {
package_version: { value: undefined },
max_idle_time_minutes: { value: undefined },
},
outputs: {},
env: {},
} as never
);
expect(logger.warn).toHaveBeenCalledWith(
{ err: error },
expect.stringContaining('Could not disable the Argent video watermark')
);
expect(spawnDetached).toHaveBeenCalledTimes(1);
expect(uploadRemoteSessionConfigAsync).toHaveBeenCalledTimes(1);
expect(waitForDeviceRunSessionStoppedAsync).toHaveBeenCalledTimes(1);
});
it('hands the launch inputs to serve-sim and announces them on an iOS session', async () => {
const ctx = {} as unknown as CustomBuildContext;
const logger = { info: jest.fn(), warn: jest.fn() };
@@ -0,0 +1,222 @@
import { SystemError, UserError } from '@expo/eas-build-job';
import nock from 'nock';
import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { createGlobalContextMock } from '../../../__tests__/utils/context';
import {
api,
editPath,
mockToken,
packageName,
serviceAccount,
} from '../../utils/android/__tests__/googlePlayTestUtils';
import { createSubmitToGooglePlayBuildFunction } from '../submitToGooglePlay';
jest.unmock('node-fetch');
jest.unmock('fs');
jest.unmock('node:fs');
jest.unmock('fs/promises');
jest.unmock('node:fs/promises');
let directory: string;
let keyPath: string;
let artifactPath: string;
const session = '/upload/test-session';
const createPath = `/androidpublisher/v3/applications/${packageName}/edits`;
beforeEach(async () => {
nock.disableNetConnect();
directory = await fs.mkdtemp(path.join(os.tmpdir(), 'play-submit-test-'));
keyPath = path.join(directory, 'key.json');
artifactPath = path.join(directory, 'app.aab');
await fs.writeFile(artifactPath, 'binary');
await fs.writeFile(
keyPath,
JSON.stringify({
...serviceAccount,
type: 'service_account',
private_key: serviceAccount.private_key.export({ format: 'pem', type: 'pkcs8' }),
})
);
});
afterEach(async () => {
const pending = nock.pendingMocks();
nock.cleanAll();
nock.enableNetConnect();
await fs.rm(directory, { recursive: true, force: true });
expect(pending).toEqual([]);
});
function submission(extra: Record<string, unknown> = {}, signal?: AbortSignal) {
const fn = createSubmitToGooglePlayBuildFunction();
const step = fn.createBuildStepFromFunctionCall(createGlobalContextMock({}), {
callInputs: {
artifact_path: artifactPath,
artifact_type: 'aab',
package_name: packageName,
service_account_key_path: keyPath,
...extra,
},
});
const setters = step.outputs.map(output => jest.spyOn(output, 'set'));
return {
setters,
step,
run: async () =>
await fn.fn!(step.ctx, {
inputs: Object.fromEntries(
step.inputs!.map(input => [input.id, { value: input.rawValue }])
),
outputs: Object.fromEntries(step.outputs.map(output => [output.id, output])),
env: {},
signal,
}),
};
}
function upload() {
mockToken();
api().post(createPath).reply(200, { id: 'edit' });
api()
.post(`/upload${editPath}/bundles`)
.query({ uploadType: 'resumable' })
.reply(200, '', { Location: `https://androidpublisher.googleapis.com${session}` });
nock('https://androidpublisher.googleapis.com').put(session).reply(200, { versionCode: 145 });
}
it.each([
['completed', undefined, { status: 'completed' }],
['completed', 0, 'invalid'],
['completed', 0.25, { status: 'inProgress', userFraction: 0.25 }],
['completed', 1, { status: 'completed' }],
['draft', undefined, { status: 'draft' }],
['draft', 0, 'invalid'],
['draft', 0.25, 'invalid'],
['draft', 1, 'invalid'],
['halted', undefined, 'invalid'],
['halted', 0, 'invalid'],
['halted', 0.25, 'invalid'],
['halted', 1, 'invalid'],
['inProgress', undefined, 'invalid'],
['inProgress', 0, 'invalid'],
['inProgress', 0.25, { status: 'inProgress', userFraction: 0.25 }],
['inProgress', 1, { status: 'completed' }],
] as const)('validates and submits %s with rollout %s', async (status, rollout, expected) => {
const task = submission({
release_status: status,
...(rollout !== undefined ? { rollout } : {}),
});
if (expected === 'invalid') {
await expect(task.run()).rejects.toThrow(status === 'halted' ? /release_status/ : /rollout/);
expect(task.setters.every(set => set.mock.calls.length === 0)).toBe(true);
return;
}
upload();
api()
.put(`${editPath}/tracks/internal`, {
track: 'internal',
releases: [{ ...expected, versionCodes: ['145'] }],
})
.reply(200, { track: 'internal' });
api()
.post(`${editPath}:commit`)
.query({})
.reply(() => {
expect(task.setters.every(set => set.mock.calls.length === 0)).toBe(true);
return [200, { id: 'edit' }];
});
await task.run();
expect(task.setters.map(set => set.mock.calls)).toEqual([[['145']]]);
});
it('runs the step with a string rollout and validates its required output', async () => {
upload();
api()
.put(`${editPath}/tracks/internal`, {
track: 'internal',
releases: [{ status: 'inProgress', userFraction: 0.25, versionCodes: ['145'] }],
})
.reply(200, { track: 'internal' });
api().post(`${editPath}:commit`).query({}).reply(200, { id: 'edit' });
const { step } = submission({ rollout: '0.25' });
expect(step.__hookId).toBe('submit');
await step.executeAsync();
expect(step.outputs[0].value).toBe('145');
});
it.each(['upload', 'track', 'abort'] as const)(
'deletes the edit after %s failure and leaves outputs unset',
async failure => {
const controller = new AbortController();
const task = submission({}, controller.signal);
mockToken();
api().post(createPath).reply(200, { id: 'edit' });
api()
.post(`/upload${editPath}/bundles`)
.query({ uploadType: 'resumable' })
.reply(() => {
if (failure === 'abort') {
controller.abort(new Error('step timed out'));
}
return failure === 'upload'
? [400, { error: { message: 'rejected binary' } }]
: [200, '', { Location: `https://androidpublisher.googleapis.com${session}` }];
});
if (failure === 'track') {
nock('https://androidpublisher.googleapis.com').put(session).reply(200, { versionCode: 145 });
api()
.put(`${editPath}/tracks/internal`)
.reply(400, { error: { message: 'unknown track' } });
}
api().delete(editPath).reply(204);
await expect(task.run()).rejects.toThrow();
expect(task.setters.every(set => set.mock.calls.length === 0)).toBe(true);
}
);
it('preserves the original failure when cleanup fails', async () => {
upload();
api()
.put(`${editPath}/tracks/internal`)
.reply(400, { error: { message: 'unknown track' } });
api().delete(editPath).reply(500);
await expect(submission().run()).rejects.toMatchObject({
cause: expect.objectContaining({ apiMessage: 'unknown track' }),
});
});
it('does not delete the edit or publish outputs when commit outcome is unknown', async () => {
upload();
api().put(`${editPath}/tracks/internal`).reply(200, { track: 'internal' });
api().post(`${editPath}:commit`).query(true).reply(503);
let deleted = false;
api()
.delete(editPath)
.optionally()
.reply(() => {
deleted = true;
return [204];
});
const task = submission();
await expect(task.run()).rejects.toBeInstanceOf(SystemError);
expect(deleted).toBe(false);
expect(task.setters.every(set => set.mock.calls.length === 0)).toBe(true);
});
it('reports a missing service-account file with its path', async () => {
const missing = path.join(directory, 'missing.json');
await expect(submission({ service_account_key_path: missing }).run()).rejects.toThrow(
`Service-account key file not found at ${missing}`
);
});
it('does not expose invalid credential contents', async () => {
await fs.writeFile(keyPath, 'PRIVATE_SECRET_INVALID_JSON');
const error = await submission()
.run()
.catch(error => error);
expect(error).toBeInstanceOf(UserError);
expect(JSON.stringify(error) + String(error)).not.toContain('PRIVATE_SECRET');
});
it('preserves the cause when the service-account file cannot be read', async () => {
const cause = Object.assign(new Error('permission denied'), { code: 'EACCES' });
const read = jest.spyOn(fs, 'readFile').mockRejectedValueOnce(cause);
try {
await expect(submission().run()).rejects.toMatchObject({ cause });
} finally {
read.mockRestore();
}
});
@@ -118,17 +118,7 @@ export async function launchApplicationAsync({
logger.info(`Opening ${openUrl} in ${applicationIdentifier}.`);
await spawn(
'adb',
[
'shell',
'am',
'start',
'-a',
'android.intent.action.VIEW',
'-d',
openUrl,
'-n',
`${applicationIdentifier}/${activityName}`,
],
['shell', 'am', 'start', '-a', 'android.intent.action.VIEW', '-d', openUrl],
{ env, logger }
);
}
@@ -55,6 +55,9 @@ export const MIN_ARGENT_REMOTE_SESSION_VERSION = '0.16.0';
const ARGENT_ARTIFACTS_LIST_ENDPOINT_FLAG = 'artifacts-list-endpoint';
// Tells the tool-server to write its structured event log so we can collect session events.
const ARGENT_EVENT_LOG_FLAG = 'tool-server-event-log';
// On by default in Argent (since 0.17.0); we turn it off so recorded videos have no Argent
// watermark. Older versions that don't know the flag treat `disable` as a no-op.
const ARGENT_VIDEO_WATERMARK_FLAG = 'video-watermark';
const ARGENT_STATE_DIR = path.join(os.homedir(), '.argent');
// Pin the event log path explicitly and hand the same value to the tool-server (via
// ARGENT_EVENT_LOG) and the collector, so an ambient ARGENT_EVENT_LOG or a future change to
@@ -163,6 +166,22 @@ export function createStartArgentRemoteSessionBuildFunction(
]);
await spawn(enableEventLog.command, enableEventLog.args, { env, logger });
logger.info('Disabling the Argent video watermark flag.');
const disableVideoWatermark = argentExec([
`${ARGENT_PACKAGE_NAME}@${versionSpec}`,
'disable',
ARGENT_VIDEO_WATERMARK_FLAG,
]);
// The watermark is cosmetic, so a failure here must not fail the session.
try {
await spawn(disableVideoWatermark.command, disableVideoWatermark.args, { env, logger });
} catch (err) {
logger.warn(
{ err },
'Could not disable the Argent video watermark, so recorded videos may include it. Continuing the session.'
);
}
const startServer = argentExec([
`${ARGENT_PACKAGE_NAME}@${versionSpec}`,
'server',
@@ -0,0 +1,251 @@
import { UserError } from '@expo/eas-build-job';
import { bunyan } from '@expo/logger';
import {
BuildFunction,
BuildStepInput,
BuildStepInputValueTypeName,
BuildStepOutput,
} from '@expo/steps';
import path from 'node:path';
import { z } from 'zod';
import { GooglePlayAuthUtils } from '../utils/android/GooglePlayAuthUtils';
import { GooglePlayClient, ReleaseStatus, ReleaseStatusZ } from '../utils/android/GooglePlayClient';
import {
GooglePlayCommitOutcomeUnknownError,
GooglePlayUtils,
} from '../utils/android/GooglePlayUtils';
import { AndroidArtifactType } from '../utils/android/appArtifact';
const InputsZ = z
.object({
artifact_path: z.string().min(1),
artifact_type: z.enum(['apk', 'aab']),
package_name: z.string().regex(/^[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)+$/),
service_account_key_path: z.string().min(1),
track: z.string().trim().min(1).default('internal'),
release_status: ReleaseStatusZ.exclude(['halted']).default('completed'),
rollout: z.number().finite().gt(0).max(1).optional(),
changelog: z.string().optional(),
changes_not_sent_for_review: z.boolean().default(false),
})
.superRefine(({ release_status, rollout }, ctx) => {
if (release_status === 'draft' && rollout !== undefined) {
ctx.addIssue({
code: 'custom',
path: ['rollout'],
message: 'A draft release cannot have a rollout.',
});
}
if (release_status === 'inProgress' && rollout === undefined) {
ctx.addIssue({
code: 'custom',
path: ['rollout'],
message: 'An inProgress release requires a rollout greater than 0 and at most 1.',
});
}
});
// Does not inspect the binary. The caller must run eas/read_android_app_info and
// compare its package_name with the intended application ID before calling this.
export function createSubmitToGooglePlayBuildFunction(): BuildFunction {
return new BuildFunction({
namespace: 'eas',
id: 'submit_to_google_play',
name: 'Submit to Google Play',
__metricsId: 'eas/submit_to_google_play',
__hookId: 'submit',
inputProviders: [
BuildStepInput.createProvider({
id: 'artifact_path',
required: true,
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
}),
BuildStepInput.createProvider({
id: 'artifact_type',
required: true,
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
}),
BuildStepInput.createProvider({
id: 'package_name',
required: true,
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
}),
BuildStepInput.createProvider({
id: 'service_account_key_path',
required: true,
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
}),
BuildStepInput.createProvider({
id: 'track',
required: false,
defaultValue: 'internal',
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
}),
BuildStepInput.createProvider({
id: 'release_status',
required: false,
defaultValue: 'completed',
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
}),
BuildStepInput.createProvider({
id: 'rollout',
required: false,
allowedValueTypeName: BuildStepInputValueTypeName.NUMBER,
}),
BuildStepInput.createProvider({
id: 'changelog',
required: false,
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
}),
BuildStepInput.createProvider({
id: 'changes_not_sent_for_review',
required: false,
defaultValue: false,
allowedValueTypeName: BuildStepInputValueTypeName.BOOLEAN,
}),
],
outputProviders: [BuildStepOutput.createProvider({ id: 'version_code', required: true })],
fn: async (ctx, { inputs, outputs, signal }) => {
signal?.throwIfAborted();
const parsed = InputsZ.safeParse(
Object.fromEntries(Object.entries(inputs).map(([key, input]) => [key, input.value]))
);
if (!parsed.success) {
throw new UserError(
'EAS_GOOGLE_PLAY_INVALID_INPUT',
'Invalid Google Play submission inputs:\n' + z.prettifyError(parsed.error)
);
}
const submission = parsed.data;
const { release_status: requested, rollout } = submission;
// Match Fastlane: a partial rollout overrides the requested status to inProgress.
const release: {
status: ReleaseStatus;
userFraction?: number;
} =
rollout !== undefined && rollout < 1
? { status: 'inProgress', userFraction: rollout }
: { status: requested === 'inProgress' ? 'completed' : requested };
const credentials = await GooglePlayAuthUtils.loadGoogleServiceAccountAsync({
keyPath: path.resolve(ctx.workingDirectory, submission.service_account_key_path),
});
const artifactPath = path.resolve(ctx.workingDirectory, submission.artifact_path);
const client = new GooglePlayClient(credentials);
const versionCode = await submitToGooglePlayAsync({
artifactType: submission.artifact_type,
client,
submission: {
package_name: submission.package_name,
track: submission.track,
release_status: submission.release_status,
rollout: submission.rollout,
changelog: submission.changelog,
changes_not_sent_for_review: submission.changes_not_sent_for_review,
artifact_path: artifactPath,
},
release,
logger: ctx.logger,
signal,
});
outputs.version_code.set(String(versionCode));
},
});
}
async function submitToGooglePlayAsync({
artifactType,
client,
submission,
release,
logger,
signal,
}: {
artifactType: AndroidArtifactType;
client: GooglePlayClient;
submission: {
package_name: string;
track: string;
release_status: ReleaseStatus;
rollout?: number;
changelog?: string;
changes_not_sent_for_review: boolean;
artifact_path: string;
};
release: { status: ReleaseStatus; userFraction?: number };
logger: bunyan;
signal?: AbortSignal;
}): Promise<number> {
let editId: string | undefined;
let committed = false;
let commitOutcomeUnknown = false;
try {
const packageName = submission.package_name;
logger.info(
`Submitting ${packageName} (${artifactType}) to track ${JSON.stringify(submission.track)}.`
);
logger.info(
`Requested status: ${submission.release_status}; rollout: ${submission.rollout ?? 'none'}. Effective status: ${release.status}; rollout: ${release.userFraction ?? 'none'}. changes_not_sent_for_review: ${submission.changes_not_sent_for_review}.`
);
if (submission.changelog) {
logger.info(`Changelog (en-US): ${JSON.stringify(submission.changelog)}`);
}
editId = (await GooglePlayUtils.createEditAsync(client, { packageName, signal })).id;
let lastPercent: number | undefined;
const { versionCode } = await GooglePlayUtils.uploadApplicationAsync(client, {
packageName,
editId,
artifactPath: submission.artifact_path,
artifactType,
signal,
onProgress: (uploaded, total) => {
const percent = Math.floor((uploaded / total) * 100);
if (percent !== lastPercent) {
logger.info(`Upload: ${percent}% (${uploaded}/${total} bytes).`);
lastPercent = percent;
}
},
});
logger.info(`Uploaded version code: ${versionCode}.`);
await GooglePlayUtils.updateTrackAsync(client, {
packageName,
editId,
track: submission.track,
release,
versionCode,
changelog: submission.changelog ? { locale: 'en-US', text: submission.changelog } : undefined,
signal,
});
logger.info('Updated Google Play track ' + JSON.stringify(submission.track) + ' in the edit.');
// Commit also validates the edit.
await GooglePlayUtils.commitEditAsync(client, {
packageName,
editId,
changesNotSentForReview: submission.changes_not_sent_for_review,
logger,
signal,
});
committed = true;
logger.info(
`Submitted ${packageName}, version ${versionCode}, to ${JSON.stringify(submission.track)}.`
);
return versionCode;
} catch (error) {
commitOutcomeUnknown = error instanceof GooglePlayCommitOutcomeUnknownError;
throw GooglePlayUtils.mapGooglePlayError(error);
} finally {
if (editId && !committed && !commitOutcomeUnknown) {
try {
await GooglePlayUtils.deleteEditAsync(client, {
packageName: submission.package_name,
editId,
signal: AbortSignal.timeout(30_000),
});
} catch {
logger.warn(
'Could not delete the Google Play edit after failure. The original submission error is preserved.'
);
}
}
}
}
@@ -19,14 +19,22 @@ import { isProcessGroupRunning, killProcessGroup } from '../../utils/processes';
import { SERVE_SIM_STATE_DIR, readServeSimServersAsync } from './serveSimMetricsRecorder';
const IOS_SIMULATOR_RECORDING_POLL_INTERVAL_MS = 2_000;
// Once the poller stops, each recording stops in parallel within 60 + 130 + 5 + 30 = 225 s.
// Once the poller stops, each recording stops in parallel within 60 + 430 + 5 + 310 = 805 s.
const SERVE_SIM_START_TIMEOUT_MS = 60_000;
/** serve-sim finalizes an active recording within this grace period after SIGTERM. */
export const SERVE_SIM_STOP_GRACE_PERIOD_MS = 90_000;
const SERVE_SIM_LEASE_FINALIZE_TIMEOUT_MS = 30_000;
// serve-sim may be stopping at the same time: its grace period, the manifest wait, and 10 s.
// Match record-video's control request, recording lease, and finalization allowances.
const SERVE_SIM_CONTROL_REQUEST_TIMEOUT_MS = 120_000;
const SERVE_SIM_RECORDING_LEASE_MS = 180_000;
const SERVE_SIM_FINALIZATION_TIMEOUT_MS = 120_000;
const SERVE_SIM_SHUTDOWN_MARGIN_MS = 10_000;
/** Give the session host time to finalize its active writer before SIGKILL. */
export const SERVE_SIM_STOP_GRACE_PERIOD_MS =
SERVE_SIM_FINALIZATION_TIMEOUT_MS + SERVE_SIM_SHUTDOWN_MARGIN_MS;
// A recorder can exit before its lease expires and the host writes the manifest.
const SERVE_SIM_LEASE_FINALIZE_TIMEOUT_MS =
SERVE_SIM_RECORDING_LEASE_MS + SERVE_SIM_FINALIZATION_TIMEOUT_MS + SERVE_SIM_SHUTDOWN_MARGIN_MS;
// An ambiguous stop can use a full control request before lease/finalization reconciliation.
const SERVE_SIM_FINISH_TIMEOUT_MS =
SERVE_SIM_STOP_GRACE_PERIOD_MS + SERVE_SIM_LEASE_FINALIZE_TIMEOUT_MS + 10_000;
SERVE_SIM_CONTROL_REQUEST_TIMEOUT_MS + SERVE_SIM_LEASE_FINALIZE_TIMEOUT_MS;
const SERVE_SIM_FORCE_STOP_TIMEOUT_MS = 5_000;
const SERVE_SIM_RECORDING_STARTED = 'serve-sim:recording-started';
// The serve-sim package the session host started; every recorder runs `record-video` from it.
@@ -46,6 +54,7 @@ type IosSimulatorRecording = {
type ActiveIosSimulatorRecording = IosSimulatorRecording & {
recordingProcess: ChildProcess;
completionPromise: Promise<void>;
hasExited: () => boolean;
};
type IosSimulatorRecordingSession = {
@@ -128,6 +137,7 @@ export namespace IosSimulatorRecordingUtils {
logger.info(`Stopping screen recording for ${recording.deviceName}.`);
const startState = await waitForRecorderStartAsync(recording, SERVE_SIM_START_TIMEOUT_MS);
if (startState === 'exited') {
await recording.completionPromise;
return;
}
if (startState === 'timeout') {
@@ -357,6 +367,7 @@ async function startIosSimulatorRecordingAsync(
});
return true;
};
let processExited = false;
const completionPromise = (async () => {
let spawnError: unknown;
try {
@@ -367,6 +378,7 @@ async function startIosSimulatorRecordingAsync(
// A package-manager wrapper can exit while its record-video child still
// runs in the detached group. Keep this device active until the group exits.
await waitForRecordingProcessGroupExitAsync(recordingSpawn.child);
processExited = true;
// Host shutdown can end the recorder's lease after its video has been saved.
if ((hasStarted() || !spawnError) && (await saveFinalizedRecordingAsync())) {
return;
@@ -400,6 +412,7 @@ async function startIosSimulatorRecordingAsync(
outputDirectory,
recordingProcess: recordingSpawn.child,
completionPromise,
hasExited: () => processExited,
startedAt,
getOutput,
hasStarted,
@@ -428,6 +441,9 @@ async function waitForRecorderStartAsync(
): Promise<'started' | 'exited' | 'timeout'> {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
if (recording.hasExited()) {
return 'exited';
}
if (recording.hasStarted()) {
return 'started';
}
@@ -439,7 +455,7 @@ async function waitForRecorderStartAsync(
return 'exited';
}
}
return 'timeout';
return recording.hasExited() ? 'exited' : recording.hasStarted() ? 'started' : 'timeout';
}
function reportLostRecording(logger: bunyan, deviceName: string, recorderOutput: string): void {
@@ -0,0 +1,133 @@
import { type Env } from '@expo/eas-build-job';
import { type bunyan } from '@expo/logger';
import spawn from '@expo/turtle-spawn';
import { type ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
import { writeFile } from 'node:fs/promises';
import { PassThrough } from 'node:stream';
import { IosSimulatorUtils } from '../../../utils/IosSimulatorUtils';
import { IosSimulatorRecordingUtils } from '../IosSimulatorRecordingUtils';
import { readServeSimServersAsync } from '../serveSimMetricsRecorder';
jest.mock('@expo/turtle-spawn');
jest.mock('../serveSimMetricsRecorder');
jest.mock('../../../sentry');
jest.mock('node:timers/promises', () => ({
setTimeout: (ms: number, value?: unknown, options?: { signal?: AbortSignal }) =>
new Promise((resolve, reject) => {
const abort = (): void => {
clearTimeout(timer);
reject(Object.assign(new Error('Aborted'), { name: 'AbortError' }));
};
const timer = setTimeout(() => {
options?.signal?.removeEventListener('abort', abort);
resolve(value);
}, ms);
if (options?.signal?.aborted) {
abort();
} else {
options?.signal?.addEventListener('abort', abort, { once: true });
}
}),
}));
const logger = {
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
debug: jest.fn(),
} as unknown as bunyan;
const udid = '06B546AC-7B06-4BED-83DB-83603E8EB537';
let exit: () => void;
let child: ChildProcess;
let finishing: Promise<unknown> | undefined;
beforeEach(async () => {
jest.useFakeTimers({ doNotFake: ['nextTick', 'setImmediate'] });
IosSimulatorRecordingUtils.useServeSimPackage('@expo/serve-sim@next');
jest
.spyOn(IosSimulatorUtils, 'getAvailableDevicesAsync')
.mockResolvedValue([{ udid, name: 'iPhone 17 Pro', runtimeDisplayName: 'iOS 26.4' } as never]);
jest
.mocked(readServeSimServersAsync)
.mockResolvedValue([{ udid, url: 'http://127.0.0.1:43563', token: 'session-token' }]);
child = Object.assign(new EventEmitter(), {
stdout: new PassThrough(),
stderr: new PassThrough(),
kill: jest.fn(),
}) as unknown as ChildProcess;
const done = new Promise<void>(resolve => {
exit = resolve;
});
jest.mocked(spawn).mockReturnValue(Object.assign(done, { child }) as never);
await IosSimulatorRecordingUtils.startAsync({ env: {} as Env, logger });
for (let attempt = 0; attempt < 100 && jest.mocked(spawn).mock.calls.length === 0; attempt++) {
await new Promise<void>(resolve => setImmediate(resolve));
}
expect(spawn).toHaveBeenCalledTimes(1);
child.stderr?.emit('data', 'serve-sim:recording-started\n');
});
async function saveManifest(): Promise<void> {
const directory = jest.mocked(spawn).mock.calls[0][1][6];
await writeFile(`${directory}/session.json`, JSON.stringify({ recording: 'recording.mp4' }));
}
afterEach(async () => {
if (jest.mocked(spawn).mock.calls.length) {
await saveManifest();
}
exit();
finishing ??= IosSimulatorRecordingUtils.finishAsync({ logger });
await jest.advanceTimersByTimeAsync(1_000);
await finishing;
finishing = undefined;
jest.useRealTimers();
jest.restoreAllMocks();
jest.mocked(spawn).mockReset();
});
test('keeps the recorder alive through a 120-second stop request and 300-second reconciliation', async () => {
finishing = IosSimulatorRecordingUtils.finishAsync({ logger });
await jest.advanceTimersByTimeAsync(0);
expect(child.kill).toHaveBeenCalledWith('SIGINT');
await jest.advanceTimersByTimeAsync(420_000);
expect(child.kill).not.toHaveBeenCalledWith('SIGKILL');
await saveManifest();
exit();
await jest.advanceTimersByTimeAsync(0);
expect(await finishing).toHaveLength(1);
expect(child.kill).not.toHaveBeenCalledWith('SIGKILL');
});
test('force-kills an unresponsive started recorder after the bounded shutdown allowance', async () => {
jest.mocked(child.kill).mockImplementation(signal => {
if (signal === 'SIGKILL') {
exit();
}
return true;
});
finishing = IosSimulatorRecordingUtils.finishAsync({ logger });
await jest.advanceTimersByTimeAsync(429_999);
expect(child.kill).not.toHaveBeenCalledWith('SIGKILL');
await saveManifest();
await jest.advanceTimersByTimeAsync(1);
expect(child.kill).toHaveBeenCalledWith('SIGKILL');
expect(await finishing).toHaveLength(1);
expect(logger.warn).toHaveBeenCalledWith(
expect.anything(),
expect.stringContaining('did not finish within 430 seconds')
);
});
test('retains a manifest saved after a 180-second lease and 120-second finalization', async () => {
exit();
finishing = IosSimulatorRecordingUtils.finishAsync({ logger });
await jest.advanceTimersByTimeAsync(299_999);
await saveManifest();
await jest.advanceTimersByTimeAsync(1_001);
expect(await finishing).toHaveLength(1);
expect(child.kill).not.toHaveBeenCalledWith('SIGKILL');
});
@@ -186,7 +186,7 @@ test('reports a started recording that ends without a manifest to Sentry', async
child.stderr?.emit('data', 'GET http://127.0.0.1:43563/record?token=session-token failed\n');
exitRecorder();
await setTimeout(50);
currentTime += 31_000;
currentTime += 311_000;
await setTimeout(1_100);
expect(Sentry.capture).toHaveBeenCalledWith(
@@ -226,7 +226,7 @@ test('says when a recorder never reported its start before it is stopped', async
await setTimeout(50);
currentTime += 61_000;
await setTimeout(200);
currentTime += 31_000;
currentTime += 311_000;
expect(await finishing).toEqual([]);
expect(child.kill).toHaveBeenCalledWith('SIGINT');
@@ -377,7 +377,7 @@ test('does not signal a recorder that exits before it reports its start', async
recorder.exit();
await setTimeout(50);
// Past the manifest wait, so the recorder's completion settles.
currentTime += 31_000;
currentTime += 311_000;
expect(await finishing).toEqual([]);
expect(recorder.child.kill).not.toHaveBeenCalled();
@@ -435,7 +435,7 @@ test('reports a finalized recording whose manifest is gone at finish', async ()
await rm(manifest);
const finishing = IosSimulatorRecordingUtils.finishAsync({ logger });
await setTimeout(50);
currentTime += 31_000;
currentTime += 311_000;
expect(await finishing).toEqual([]);
expect(Sentry.capture).toHaveBeenCalledWith(
@@ -493,7 +493,7 @@ test('reports a started recorder that fails without a manifest', async () => {
recorder.child.stderr?.emit('data', 'serve-sim:recording-started\n');
recorder.fail(new Error('record-video exited with code 1'));
await setTimeout(50);
currentTime += 31_000;
currentTime += 311_000;
await setTimeout(1_100);
expect(logger.warn).toHaveBeenCalledWith(
@@ -534,6 +534,6 @@ test('records every booted device with the first serve-sim package', async () =>
recorder.exit();
await setTimeout(50);
currentTime += 31_000;
currentTime += 311_000;
await IosSimulatorRecordingUtils.finishAsync({ logger });
});
@@ -833,6 +833,7 @@ describe(startDeviceSessionHostAsync, () => {
expect(spawnDetachedSpy).toHaveBeenCalledWith(
expect.objectContaining({ stopGracePeriodMs: SERVE_SIM_STOP_GRACE_PERIOD_MS })
);
expect(spawnDetachedSpy.mock.calls[0][0].stopGracePeriodMs).toBeGreaterThanOrEqual(120_000);
await host.finishAsync();
});
@@ -3,6 +3,8 @@ import { asyncResult } from '@expo/results';
import fetch, { Response } from 'node-fetch';
import { z } from 'zod';
import { promiseRetryWithCondition } from '../../../utils/promiseRetryWithCondition';
const PostApi = {
'/token': {
request: z.object({
@@ -46,14 +48,22 @@ export class GooglePlayAuthClient {
signal?: AbortSignal
): Promise<z.output<(typeof PostApi)[TPath]['response']>> {
const schema = PostApi[path];
return await this.requestAsync({
method: 'POST',
path,
body,
requestSchema: schema.request,
responseSchema: schema.response,
signal,
});
return await promiseRetryWithCondition(
() =>
this.requestAsync({
method: 'POST',
path,
body,
requestSchema: schema.request,
responseSchema: schema.response,
signal,
}),
error =>
!signal?.aborted &&
error instanceof GooglePlayAuthRequestError &&
(error.status === 429 || error.status >= 500),
{ retries: 3, factor: 2, minTimeout: 1000, maxTimeout: 4000 }
)();
}
private async requestAsync({
@@ -1,5 +1,8 @@
import { UserError } from '@expo/eas-build-job';
import fs from 'node:fs/promises';
import { z } from 'zod';
import * as jose from 'jose';
import { KeyObject } from 'node:crypto';
import { KeyObject, createPrivateKey } from 'node:crypto';
import { GooglePlayAuthClient } from './GooglePlayAuthClient';
@@ -10,6 +13,46 @@ export type GoogleServiceAccount = {
};
export namespace GooglePlayAuthUtils {
export async function loadGoogleServiceAccountAsync({
keyPath,
}: {
keyPath: string;
}): Promise<GoogleServiceAccount> {
let contents: string;
try {
contents = await fs.readFile(keyPath, 'utf8');
} catch (error) {
throw new UserError(
'EAS_GOOGLE_PLAY_INVALID_CREDENTIALS',
(error as NodeJS.ErrnoException).code === 'ENOENT'
? `Service-account key file not found at ${keyPath}.`
: `Cannot read the service-account key file at ${keyPath}.`,
{ cause: error }
);
}
try {
const credentials = z
.object({
type: z.literal('service_account'),
client_email: z.email(),
private_key: z.string().min(1),
private_key_id: z.string().optional(),
})
.parse(JSON.parse(contents));
const privateKey = createPrivateKey(credentials.private_key);
if (privateKey.asymmetricKeyType !== 'rsa') {
throw new Error('Expected an RSA private key.');
}
return { ...credentials, private_key: privateKey };
} catch {
// Neither JSON parse errors nor validation errors may include credential content.
throw new UserError(
'EAS_GOOGLE_PLAY_INVALID_CREDENTIALS',
'Cannot read the Google service-account key. Provide a valid service-account JSON file.'
);
}
}
async function createAssertionAsync(serviceAccount: GoogleServiceAccount): Promise<string> {
return await new jose.SignJWT({
scope: 'https://www.googleapis.com/auth/androidpublisher',
@@ -1,5 +1,5 @@
import { SystemError } from '@expo/eas-build-job';
import fetch, { Response } from 'node-fetch';
import fetch, { RequestInit, Response } from 'node-fetch';
import { z } from 'zod';
import { GooglePlayAuthUtils, GoogleServiceAccount } from './GooglePlayAuthUtils';
@@ -12,9 +12,36 @@ export class GooglePlayApiError extends Error {
) {
super(`Google Play request failed (HTTP ${status})${apiMessage ? `: ${apiMessage}` : '.'}`);
}
static async fromResponseAsync(
response: Response,
signal?: AbortSignal
): Promise<GooglePlayApiError> {
let data: unknown;
try {
data = await response.json();
} catch {
signal?.throwIfAborted();
// Raw text or HTML can contain the request URL, including an upload secret.
}
const parsed = z
.object({
error: z.object({
message: z.string().optional(),
errors: z.array(z.object({ reason: z.string().optional() })).optional(),
}),
})
.safeParse(data);
return new GooglePlayApiError(
response.status,
parsed.data?.error.message ?? '',
parsed.data?.error.errors?.flatMap(error => (error.reason ? [error.reason] : [])) ?? []
);
}
}
const ReleaseStatusZ = z.enum(['draft', 'inProgress', 'halted', 'completed']);
export const ReleaseStatusZ = z.enum(['draft', 'inProgress', 'halted', 'completed']);
export type ReleaseStatus = z.output<typeof ReleaseStatusZ>;
const ReleaseNoteZ = z.object({
language: z.string(),
@@ -143,7 +170,10 @@ export class GooglePlayClient {
path: TPath,
body: z.input<(typeof PostApi)[TPath]['request']>,
params: z.input<(typeof PostApi)[TPath]['path']>,
options: { query?: z.input<(typeof PostApi)[TPath]['query']>; signal?: AbortSignal } = {}
options: {
query?: z.input<(typeof PostApi)[TPath]['query']>;
signal?: AbortSignal;
} = {}
): Promise<z.output<(typeof PostApi)[TPath]['response']>> {
return await this.sendJsonRequestAsync(
'POST',
@@ -210,7 +240,8 @@ export class GooglePlayClient {
method,
search.size ? `${path}?${search}` : path,
method === 'GET' ? undefined : JSON.stringify(parsedBody),
signal
signal,
{ 'Content-Type': 'application/json' }
);
let data: unknown;
@@ -233,11 +264,12 @@ export class GooglePlayClient {
return parsed.data;
}
private async requestAsync(
async requestAsync(
method: 'GET' | 'POST' | 'PUT' | 'DELETE',
path: string,
body?: string,
signal?: AbortSignal
signal?: AbortSignal,
headers?: RequestInit['headers']
): Promise<Response> {
const url = new URL(path, this.baseUrl);
const token = await this.getTokenAsync(signal);
@@ -248,36 +280,18 @@ export class GooglePlayClient {
method,
body,
signal,
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
headers: { ...headers, Authorization: `Bearer ${token}` },
redirect: 'manual',
});
} catch {
} catch (error) {
signal?.throwIfAborted();
throw new SystemError('Google Play request failed before a response was received.');
throw new SystemError('Google Play request failed before a response was received.', {
cause: error,
});
}
if (!response.ok) {
let data: unknown;
try {
data = await response.json();
} catch {
signal?.throwIfAborted();
}
const parsed = z
.object({
error: z.object({
message: z.string().optional(),
errors: z.array(z.object({ reason: z.string().optional() })).optional(),
}),
})
.safeParse(data);
throw new GooglePlayApiError(
response.status,
parsed.success ? (parsed.data.error.message ?? '') : '',
parsed.success
? (parsed.data.error.errors?.flatMap(error => (error.reason ? [error.reason] : [])) ?? [])
: []
);
throw await GooglePlayApiError.fromResponseAsync(response, signal);
}
return response;
@@ -0,0 +1,290 @@
import { SystemError } from '@expo/eas-build-job';
import fetch, { FetchError, Response } from 'node-fetch';
import promiseRetry from 'promise-retry';
import { FileHandle } from 'node:fs/promises';
import { z } from 'zod';
import { GooglePlayApiError, GooglePlayClient } from './GooglePlayClient';
import { AndroidArtifactType } from './appArtifact';
const UploadResponseZ = z.object({
versionCode: z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
});
const CHUNK_SIZE = 8 * 1024 * 1024;
// Google recommends a two-minute timeout for bundle uploads, including processing.
const REQUEST_TIMEOUT_MS = 120_000;
export namespace GooglePlayResumableUpload {
export async function createUploadSessionAsync({
client,
packageName,
editId,
artifactType,
signal,
size,
}: {
client: GooglePlayClient;
packageName: string;
editId: string;
artifactType: AndroidArtifactType;
signal?: AbortSignal;
size: number;
}): Promise<URL> {
const resource = artifactType === 'apk' ? 'apks' : 'bundles';
const response = await promiseRetry(
async retry => {
signal?.throwIfAborted();
const timeout = AbortSignal.timeout(REQUEST_TIMEOUT_MS);
const requestSignal = signal ? AbortSignal.any([signal, timeout]) : timeout;
try {
return await client.requestAsync(
'POST',
`/upload/androidpublisher/v3/applications/${encodeURIComponent(packageName)}/edits/${encodeURIComponent(editId)}/${resource}?uploadType=resumable`,
undefined,
requestSignal,
{
'Content-Length': '0',
'X-Upload-Content-Length': String(size),
'X-Upload-Content-Type': getContentTypeFromArtifactType(artifactType),
}
);
} catch (error) {
signal?.throwIfAborted();
if (
timeout.aborted ||
isNetworkRetryable(error) ||
(error instanceof GooglePlayApiError && (error.status === 429 || error.status >= 500))
) {
retry(
timeout.aborted
? new SystemError('Google Play upload session request timed out.')
: error
);
}
throw error;
}
},
{
retries: 5,
factor: 2,
minTimeout: 1000,
maxTimeout: 32_000,
randomize: true,
}
);
const location = response.headers.get('location');
if (!location) {
throw new SystemError('Google did not return an upload session.');
}
let session: URL;
try {
session = new URL(location);
} catch {
// Node's URL error retains the input, which can contain the upload secret.
throw new SystemError('Google returned an invalid upload URL.');
}
if (session.origin !== 'https://androidpublisher.googleapis.com') {
throw new SystemError(
`Google returned an unsafe upload URL: expected origin https://androidpublisher.googleapis.com, got ${session.origin}.`
);
}
if (session.username || session.password) {
throw new SystemError(
'Google returned an unsafe upload URL containing a username or password. Upload sessions must not send HTTP Basic credentials.'
);
}
return session;
}
export async function uploadSessionAsync({
file,
size,
session,
artifactType,
signal,
onProgress,
}: {
file: FileHandle;
size: number;
session: URL;
artifactType: AndroidArtifactType;
signal?: AbortSignal;
onProgress?: (uploadedBytes: number, totalBytes: number) => void;
}): Promise<z.output<typeof UploadResponseZ>> {
const contentType = getContentTypeFromArtifactType(artifactType);
let offset = 0;
onProgress?.(0, size);
while (offset < size) {
const result = await uploadChunkAsync({ file, size, session, contentType, offset, signal });
if (result.status === 'completed') {
onProgress?.(size, size);
return result.data;
}
offset = result.offset;
onProgress?.(offset, size);
}
throw new SystemError(`Google upload stopped at ${offset} of ${size} bytes.`);
}
async function uploadChunkAsync({
file,
size,
session,
contentType,
offset,
signal,
}: {
file: FileHandle;
size: number;
session: URL;
contentType: string;
offset: number;
signal?: AbortSignal;
}): Promise<
| { status: 'completed'; data: z.output<typeof UploadResponseZ> }
| { status: 'progress'; offset: number }
> {
let checkServerOffset = false;
// Confirmed progress starts a new retry budget. Retries first check the server offset.
return await promiseRetry(
async retry => {
while (true) {
signal?.throwIfAborted();
const end = Math.min(offset + CHUNK_SIZE, size);
let body: Buffer | undefined;
if (!checkServerOffset) {
// Only this chunk is held in memory, never the whole file.
body = Buffer.alloc(end - offset);
const { bytesRead } = await file.read(body, 0, body.length, offset);
if (bytesRead !== body.length) {
throw new SystemError(
`The Android binary changed during upload: expected ${body.length} bytes at offset ${offset}, got ${bytesRead}.`
);
}
}
const timeout = AbortSignal.timeout(REQUEST_TIMEOUT_MS);
const requestSignal = signal ? AbortSignal.any([signal, timeout]) : timeout;
let response: Response;
try {
response = await fetch(session.toString(), {
method: 'PUT',
redirect: 'manual',
headers: {
'Content-Length': String(body?.length ?? 0),
'Content-Range': checkServerOffset
? `bytes */${size}`
: `bytes ${offset}-${end - 1}/${size}`,
'Content-Type': contentType,
},
body,
signal: requestSignal,
});
} catch (error) {
signal?.throwIfAborted();
const failure = new SystemError(
'Google Play upload failed before a response was received.'
);
if (timeout.aborted || isNetworkRetryable(error)) {
checkServerOffset = true;
retry(failure);
}
throw failure;
}
if (!response.ok && response.status !== 308) {
const error = await GooglePlayApiError.fromResponseAsync(response, signal);
if (timeout.aborted) {
checkServerOffset = true;
return retry(new SystemError('Google Play upload response timed out.'));
}
if (response.status === 429 || response.status >= 500) {
checkServerOffset = true;
retry(error);
}
throw error;
}
if (response.status === 200 || response.status === 201) {
let data: unknown;
try {
data = await response.json();
} catch {
signal?.throwIfAborted();
checkServerOffset = true;
return retry(new SystemError('Could not read the Google Play upload response.'));
}
const parsed = UploadResponseZ.safeParse(data);
if (!parsed.success) {
throw new SystemError('Google completed the upload without a valid version code.');
}
return { status: 'completed', data: parsed.data };
}
if (response.status !== 308) {
throw new SystemError(`Unexpected Google upload status: ${response.status}.`);
}
const range = response.headers.get('range');
const match = range ? /^bytes=0-(\d+)$/.exec(range) : undefined;
const next = range ? (match ? Number(match[1]) + 1 : NaN) : 0;
if (
!Number.isSafeInteger(next) ||
next < offset ||
next > size ||
(!checkServerOffset && next > end)
) {
throw new SystemError('Google returned an invalid upload range.');
}
if (next === size) {
checkServerOffset = true;
// All bytes are stored, but only 200/201 confirms completion.
// Keep the current retry budget and send only status checks.
return retry(
new SystemError(`Google stored all ${size} bytes but has not completed the upload.`)
);
}
if (next > offset) {
return { status: 'progress', offset: next };
}
if (!checkServerOffset) {
checkServerOffset = true;
retry(
new SystemError(
`Google upload made no progress: confirmed ${offset} of ${size} bytes after sending bytes ${offset}-${end - 1}.`
)
);
}
// The status check confirmed no new bytes. Send the chunk again.
checkServerOffset = false;
}
},
{
retries: 5,
factor: 2,
minTimeout: 1000,
maxTimeout: 32_000,
randomize: true,
}
);
}
}
function getContentTypeFromArtifactType(artifactType: AndroidArtifactType): string {
return artifactType === 'apk'
? 'application/vnd.android.package-archive'
: 'application/octet-stream';
}
function isNetworkRetryable(error: unknown): boolean {
const visited = new Set<Error>();
while (error instanceof Error && !visited.has(error)) {
if (error instanceof FetchError && error.type === 'system') {
return true;
}
visited.add(error);
error = error.cause;
}
return false;
}
@@ -0,0 +1,279 @@
import { SystemError, UserError } from '@expo/eas-build-job';
import { bunyan } from '@expo/logger';
import fs from 'node:fs/promises';
import promiseRetry from 'promise-retry';
import { GooglePlayAuthRequestError } from './GooglePlayAuthClient';
import { GooglePlayApiError, GooglePlayClient, ReleaseStatus } from './GooglePlayClient';
import { GooglePlayResumableUpload } from './GooglePlayResumableUpload';
import { AndroidArtifactType } from './appArtifact';
export class GooglePlayCommitOutcomeUnknownError extends SystemError {}
export namespace GooglePlayUtils {
export async function uploadApplicationAsync(
client: GooglePlayClient,
options: {
packageName: string;
editId: string;
artifactPath: string;
artifactType: AndroidArtifactType;
signal?: AbortSignal;
onProgress?: (uploadedBytes: number, totalBytes: number) => void;
}
): Promise<{ versionCode: number }> {
options.signal?.throwIfAborted();
const file = await fs.open(options.artifactPath, 'r');
try {
const { size } = await file.stat();
if (!Number.isSafeInteger(size) || size <= 0) {
throw new UserError(
'EAS_GOOGLE_PLAY_INVALID_BINARY',
'Cannot upload an empty or invalid Android binary.'
);
}
return await promiseRetry(
async retry => {
const session = await GooglePlayResumableUpload.createUploadSessionAsync({
...options,
client,
size,
});
try {
return await GooglePlayResumableUpload.uploadSessionAsync({
...options,
file,
size,
session,
});
} catch (error) {
options.signal?.throwIfAborted();
// 404/410 from an existing session mean it is gone; other failures
// must not restart the whole file upload.
if (error instanceof GooglePlayApiError && [404, 410].includes(error.status)) {
retry(error);
}
throw error;
}
},
{ retries: 2, factor: 2, minTimeout: 1000, maxTimeout: 32_000, randomize: true }
);
} finally {
await file.close();
}
}
export async function createEditAsync(
client: GooglePlayClient,
{ packageName, signal }: { packageName: string; signal?: AbortSignal }
): Promise<{ id: string }> {
return await client.postAsync(
'/androidpublisher/v3/applications/:packageName/edits',
{},
{ packageName },
{ signal }
);
}
export async function updateTrackAsync(
client: GooglePlayClient,
{
packageName,
editId,
track,
release,
versionCode,
changelog,
signal,
}: {
packageName: string;
editId: string;
track: string;
release: { status: ReleaseStatus; userFraction?: number };
versionCode: number;
changelog?: { locale: string; text: string };
signal?: AbortSignal;
}
): Promise<void> {
await client.putAsync(
'/androidpublisher/v3/applications/:packageName/edits/:editId/tracks/:track',
{
track,
releases: [
{
...release,
versionCodes: [String(versionCode)],
...(changelog
? { releaseNotes: [{ language: changelog.locale, text: changelog.text }] }
: {}),
},
],
},
{ packageName, editId, track },
signal
);
}
export async function deleteEditAsync(
client: GooglePlayClient,
{ packageName, editId, signal }: { packageName: string; editId: string; signal?: AbortSignal }
): Promise<void> {
await client.deleteAsync(
'/androidpublisher/v3/applications/:packageName/edits/:editId',
{ packageName, editId },
signal
);
}
export async function commitEditAsync(
client: GooglePlayClient,
{
packageName,
editId,
changesNotSentForReview,
logger,
signal,
}: {
packageName: string;
editId: string;
changesNotSentForReview: boolean;
logger: bunyan;
signal?: AbortSignal;
}
): Promise<void> {
const commitOnceAsync = async ({
changesNotSentForReview,
}: {
changesNotSentForReview?: boolean;
}): Promise<void> => {
signal?.throwIfAborted();
try {
const committed = await client.postAsync(
'/androidpublisher/v3/applications/:packageName/edits/:editId:commit',
{},
{ packageName, editId },
{ query: { changesNotSentForReview }, signal }
);
if (committed?.id !== editId) {
throw new SystemError('Google did not confirm the committed edit.');
}
} catch (error) {
if (error instanceof GooglePlayAuthRequestError) {
throw error;
}
if (
!(error instanceof GooglePlayApiError) ||
error.status >= 500 ||
error.status === 408 ||
error.status === 429
) {
throw new GooglePlayCommitOutcomeUnknownError(
'Google Play commit outcome is unknown. Check the release in Play Console before you submit again. The commit was not retried.',
{ cause: error }
);
}
throw error;
}
};
try {
// Omit the optional parameter for normal review submission. Some app states
// reject its presence, even when false. True saves changes for review in Console.
await commitOnceAsync({ changesNotSentForReview: changesNotSentForReview || undefined });
} catch (error) {
if (!(error instanceof GooglePlayApiError) || error.status !== 400) {
throw error;
}
// Like Fastlane, retry only an explicit rejection of the review setting.
if (
changesNotSentForReview &&
error.apiMessage.includes('The query parameter changesNotSentForReview must not be set')
) {
logger.warn(
'Google does not allow changesNotSentForReview for this app right now. Retrying commit once without it. The changes will be sent for review.'
);
await commitOnceAsync({});
} else if (
!changesNotSentForReview &&
error.apiMessage.includes('Please set the query parameter changesNotSentForReview to true')
) {
logger.warn(
'Google requires changesNotSentForReview=true. Retrying commit once. Send the saved changes for review from Play Console.'
);
await commitOnceAsync({ changesNotSentForReview: true });
} else {
throw error;
}
}
}
export function mapGooglePlayError(error: unknown): unknown {
if (
(error instanceof GooglePlayApiError || error instanceof GooglePlayAuthRequestError) &&
(error.status === 408 || error.status === 429 || error.status >= 500)
) {
return new SystemError(
`Google Play is temporarily unavailable or rate limited (HTTP ${error.status}). Try again later.`,
{ cause: error }
);
}
if (
error instanceof GooglePlayAuthRequestError &&
error.status >= 400 &&
error.status < 500 &&
error.status !== 408 &&
error.status !== 429
) {
return new UserError(
'EAS_GOOGLE_PLAY_INVALID_CREDENTIALS',
`Google rejected the service-account key (${error.errorCode ?? `HTTP ${error.status}`}). Check that the key is valid and the service account is enabled.`,
{ cause: error }
);
}
if (!(error instanceof GooglePlayApiError)) {
return error;
}
const message = error.apiMessage;
const reasons = new Set(error.reasons);
let code = 'EAS_GOOGLE_PLAY_REQUEST_FAILED';
let detail = `Google Play rejected the request (HTTP ${error.status}; reasons: ${error.reasons.join(', ') || 'unspecified'}). Check the app and release settings in Play Console. Concurrent edits or Console changes can invalidate an edit.`;
if (message.includes('Package not found')) {
code = 'EAS_GOOGLE_PLAY_FIRST_UPLOAD';
detail =
'Google Play cannot find the app. Check the package name and upload the first version manually in Play Console.';
} else if (
/version code.*already (?:been )?used/i.test(message) ||
reasons.has('apkNotificationMessageKeyUpgradeVersionConflict') ||
message.includes('apkNotificationMessageKeyUpgradeVersionConflict')
) {
code = 'EAS_GOOGLE_PLAY_VERSION_CODE_USED';
detail =
'This version code was already uploaded. Increase the Android version code and build a new binary.';
} else if (
/privacy policy/i.test(message) ||
reasons.has('apkNotificationMessageKeyPermissionsRequirePrivacyPolicy') ||
message.includes('apkNotificationMessageKeyPermissionsRequirePrivacyPolicy')
) {
code = 'EAS_GOOGLE_PLAY_PRIVACY_POLICY_REQUIRED';
detail = 'This app requires a privacy policy. Add it in Play Console before you submit.';
} else if (message.includes('Only releases with status draft may be created on draft app')) {
code = 'EAS_GOOGLE_PLAY_DRAFT_APP';
detail =
'This app is a draft in Play Console. Complete its required metadata or submit with release_status: draft.';
} else if (error.status === 409 || /edit.*(?:expired|invalid|not found)/i.test(message)) {
code = 'EAS_GOOGLE_PLAY_EDIT_INVALID';
detail =
'The Google Play edit is no longer valid. A concurrent edit or Play Console change can invalidate it. Check the app in Play Console before you submit again.';
} else if (error.status === 401 || message.includes('The caller does not have permission')) {
code = 'EAS_GOOGLE_PLAY_PERMISSION_DENIED';
detail =
'The Google service account cannot submit this app. Check its key and app permissions in Play Console.';
} else if (error.status === 400) {
code = 'EAS_GOOGLE_PLAY_INVALID_RELEASE';
detail =
'Google Play rejected the release or review settings. Check the track, release status, rollout, and review settings in Play Console.';
}
return new UserError(code, message ? `${detail} Google Play said: ${message}` : detail, {
cause: error,
});
}
}
@@ -109,3 +109,19 @@ it.each(['network failure', 'malformed JSON'])('returns a system error for %s',
}
}
});
it.each([429, 503])('retries temporary OAuth HTTP %s responses', async status => {
nock('https://oauth2.googleapis.com')
.post('/token', request)
.reply(status)
.post('/token', request)
.reply(200, { access_token: 'recovered', expires_in: 3600, token_type: 'Bearer' });
await expect(client.postAsync('/token', request)).resolves.toMatchObject({
access_token: 'recovered',
});
});
it('stops after three OAuth retries', async () => {
nock('https://oauth2.googleapis.com').post('/token', request).times(4).reply(503);
await expect(client.postAsync('/token', request)).rejects.toMatchObject({ status: 503 });
}, 15000);
@@ -0,0 +1,122 @@
import { SystemError, UserError } from '@expo/eas-build-job';
import nock from 'nock';
import { api, editPath, mockToken, packageName, serviceAccount } from './googlePlayTestUtils';
import { createMockLogger } from '../../../../__tests__/utils/logger';
import { GooglePlayAuthRequestError } from '../GooglePlayAuthClient';
import { GooglePlayApiError, GooglePlayClient } from '../GooglePlayClient';
import { GooglePlayUtils } from '../GooglePlayUtils';
jest.unmock('node-fetch');
beforeEach(() => nock.disableNetConnect());
afterEach(() => {
const pending = nock.pendingMocks();
nock.cleanAll();
nock.enableNetConnect();
expect(pending).toEqual([]);
});
function commit({
signal,
changesNotSentForReview = false,
}: {
signal?: AbortSignal;
changesNotSentForReview?: boolean;
} = {}) {
return GooglePlayUtils.commitEditAsync(new GooglePlayClient(serviceAccount), {
packageName,
editId: 'edit',
changesNotSentForReview,
logger: createMockLogger(),
signal,
});
}
it.each([
[false, {}],
[true, { changesNotSentForReview: 'true' }],
] as const)(
'commits with changesNotSentForReview=%s without a failed first request',
async (changesNotSentForReview, query) => {
mockToken();
api().post(`${editPath}:commit`).query(query).reply(200, { id: 'edit' });
await expect(commit({ changesNotSentForReview })).resolves.toBeUndefined();
}
);
it.each([
[
true,
{ changesNotSentForReview: 'true' },
'The query parameter changesNotSentForReview must not be set',
{},
],
[
false,
{},
'Please set the query parameter changesNotSentForReview to true',
{ changesNotSentForReview: 'true' },
],
] as const)(
'retries the rejected review setting (requested=%s)',
async (changesNotSentForReview, initialQuery, message, retryQuery) => {
mockToken();
api().post(`${editPath}:commit`).query(initialQuery).reply(400, { error: { message } });
api().post(`${editPath}:commit`).query(retryQuery).reply(200, { id: 'edit' });
await expect(commit({ changesNotSentForReview })).resolves.toBeUndefined();
}
);
it.each([408, 429, 503])('does not retry an uncertain HTTP %s commit', async status => {
mockToken();
api().post(`${editPath}:commit`).query(true).reply(status);
await expect(commit()).rejects.toMatchObject({ cause: expect.objectContaining({ status }) });
});
it('preserves cancellation before commit is sent', async () => {
const controller = new AbortController();
const reason = new Error('cancelled before commit');
controller.abort(reason);
await expect(commit({ signal: controller.signal })).rejects.toBe(reason);
});
it('preserves OAuth rejection before commit is sent', async () => {
nock('https://oauth2.googleapis.com').post('/token').reply(400, { error: 'invalid_grant' });
await expect(commit()).rejects.toBeInstanceOf(GooglePlayAuthRequestError);
});
it.each([
[404, 'Package not found', 'EAS_GOOGLE_PLAY_FIRST_UPLOAD'],
[403, 'Version code 144 has already been used', 'EAS_GOOGLE_PLAY_VERSION_CODE_USED'],
[403, 'The caller does not have permission', 'EAS_GOOGLE_PLAY_PERMISSION_DENIED'],
[403, 'privacy policy required', 'EAS_GOOGLE_PLAY_PRIVACY_POLICY_REQUIRED'],
[403, 'wrong signing key', 'EAS_GOOGLE_PLAY_REQUEST_FAILED'],
[400, 'privacy policy required', 'EAS_GOOGLE_PLAY_PRIVACY_POLICY_REQUIRED'],
[400, 'Only releases with status draft may be created on draft app', 'EAS_GOOGLE_PLAY_DRAFT_APP'],
[409, 'edit invalid', 'EAS_GOOGLE_PLAY_EDIT_INVALID'],
[400, 'unknown track', 'EAS_GOOGLE_PLAY_INVALID_RELEASE'],
] as const)('keeps the Google error behind %s %s', (status, message, code) => {
const original = new GooglePlayApiError(status, message, []);
const mapped = GooglePlayUtils.mapGooglePlayError(original);
expect(mapped).toBeInstanceOf(UserError);
expect(mapped).toMatchObject({
errorCode: code,
message: expect.stringContaining(`Google Play said: ${message}`),
cause: original,
});
});
it('maps a rejected OAuth key to a credential error', () => {
const original = new GooglePlayAuthRequestError(400, 'invalid_grant');
expect(GooglePlayUtils.mapGooglePlayError(original)).toMatchObject({
errorCode: 'EAS_GOOGLE_PLAY_INVALID_CREDENTIALS',
cause: original,
});
});
it.each([408, 429, 500, 503])('classifies temporary HTTP %s errors as system errors', status => {
for (const original of [
new GooglePlayApiError(status, 'temporary failure', []),
new GooglePlayAuthRequestError(status, 'temporarily_unavailable'),
]) {
const mapped = GooglePlayUtils.mapGooglePlayError(original);
expect(mapped).toBeInstanceOf(SystemError);
expect(mapped).toMatchObject({ cause: original });
expect((mapped as Error).message).not.toContain('settings');
}
});
it('keeps non-Google errors unchanged', () => {
const error = new SystemError('file failure');
expect(GooglePlayUtils.mapGooglePlayError(error)).toBe(error);
});
@@ -0,0 +1,366 @@
import nock from 'nock';
import { truncateSync } from 'node:fs';
import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { api, editPath, mockToken, packageName, serviceAccount } from './googlePlayTestUtils';
import { GooglePlayClient } from '../GooglePlayClient';
import { GooglePlayUtils } from '../GooglePlayUtils';
jest.unmock('node-fetch');
jest.unmock('fs');
jest.unmock('node:fs');
jest.unmock('fs/promises');
jest.unmock('node:fs/promises');
jest.mock('promise-retry', () => {
const promiseRetry = jest.requireActual('promise-retry');
return (fn: Parameters<typeof promiseRetry>[0], options: object) =>
promiseRetry(fn, { ...options, minTimeout: 0, maxTimeout: 0 });
});
let directory: string;
let artifactPath: string;
let client: GooglePlayClient;
const session = '/upload/session';
const chunkSize = 8 * 1024 * 1024;
beforeEach(async () => {
nock.disableNetConnect();
directory = await fs.mkdtemp(path.join(os.tmpdir(), 'play-client-test-'));
artifactPath = path.join(directory, 'binary');
await fs.writeFile(artifactPath, Buffer.alloc(12));
client = new GooglePlayClient(serviceAccount);
});
afterEach(async () => {
const pending = nock.pendingMocks();
nock.cleanAll();
nock.enableNetConnect();
jest.restoreAllMocks();
await fs.rm(directory, { recursive: true, force: true });
expect(pending).toEqual([]);
});
function mockStart(location = `https://androidpublisher.googleapis.com${session}`): void {
api()
.post(`/upload${editPath}/apks`)
.query({ uploadType: 'resumable' })
.reply(200, '', { Location: location });
}
function upload(signal?: AbortSignal, onProgress = jest.fn()) {
return GooglePlayUtils.uploadApplicationAsync(client, {
packageName,
editId: 'edit',
artifactPath,
artifactType: 'apk',
signal,
onProgress,
}).then(result => result.versionCode);
}
function uploadApi(): nock.Scope {
return nock('https://androidpublisher.googleapis.com', { badheaders: ['authorization'] });
}
function status(total = 12): nock.Interceptor {
return uploadApi()
.put(session)
.matchHeader('content-length', '0')
.matchHeader('content-range', `bytes */${total}`);
}
it('uploads aligned chunks and reports server-confirmed progress', async () => {
await fs.writeFile(artifactPath, Buffer.alloc(chunkSize + 12));
mockToken();
mockStart();
uploadApi()
.put(session)
.matchHeader('content-length', String(chunkSize))
.matchHeader('content-range', `bytes 0-${chunkSize - 1}/${chunkSize + 12}`)
.reply(308, '', { Range: `bytes=0-${chunkSize - 1}` });
uploadApi()
.put(session)
.matchHeader('content-length', '12')
.matchHeader('content-range', `bytes ${chunkSize}-${chunkSize + 11}/${chunkSize + 12}`)
.reply(200, { versionCode: 42 });
const progress = jest.fn();
await expect(upload(undefined, progress)).resolves.toBe(42);
expect(progress.mock.calls).toEqual([
[0, chunkSize + 12],
[chunkSize, chunkSize + 12],
[chunkSize + 12, chunkSize + 12],
]);
});
it.each(['network', 429, 503])(
'recovers the accepted offset after a %s interruption',
async failure => {
mockToken();
mockStart();
const interrupted = uploadApi().put(session).matchHeader('content-range', 'bytes 0-11/12');
if (failure === 'network') {
interrupted.replyWithError('connection reset');
} else {
interrupted.reply(failure as number, { error: { message: 'retry' } });
}
status().reply(308, '', { Range: 'bytes=0-5' });
uploadApi()
.put(session)
.matchHeader('content-range', 'bytes 6-11/12')
.reply(200, { versionCode: 42 });
const progress = jest.fn();
await expect(upload(undefined, progress)).resolves.toBe(42);
expect(progress.mock.calls).toEqual([
[0, 12],
[6, 12],
[12, 12],
]);
}
);
it('recovers a completed upload when the final upload response is lost', async () => {
mockToken();
mockStart();
uploadApi()
.put(session)
.matchHeader('content-length', '12')
.replyWithError('lost final response');
status().reply(200, { versionCode: 42 });
await expect(upload()).resolves.toBe(42);
});
it('recovers completion after a damaged response body', async () => {
mockToken();
mockStart();
uploadApi().put(session).matchHeader('content-length', '12').reply(200, '{invalid JSON');
status().reply(200, { versionCode: 42 });
await expect(upload()).resolves.toBe(42);
});
it('sanitizes a malformed session URL', async () => {
mockToken();
mockStart('INVALID SECRET URL');
const error = await upload().catch(error => error);
expect(error).toBeInstanceOf(Error);
expect(String(error)).toContain('invalid upload URL');
expect(JSON.stringify(error)).not.toContain('SECRET');
expect(String(error)).not.toContain('SECRET');
});
it('retries status recovery after a transient Google error', async () => {
mockToken();
mockStart();
uploadApi().put(session).matchHeader('content-length', '12').reply(503);
status().reply(429);
status().reply(308);
uploadApi().put(session).matchHeader('content-length', '12').reply(200, { versionCode: 42 });
await expect(upload()).resolves.toBe(42);
});
it.each([404, 410])('restarts an expired %s upload session within the same edit', async expired => {
mockToken();
mockStart();
uploadApi().put(session).reply(expired);
mockStart();
uploadApi().put(session).reply(200, { versionCode: 42 });
const progress = jest.fn();
await expect(upload(undefined, progress)).resolves.toBe(42);
expect(progress.mock.calls).toEqual([
[0, 12],
[0, 12],
[12, 12],
]);
});
it('stops after the upload retry limit', async () => {
mockToken();
mockStart();
uploadApi().put(session).matchHeader('content-length', '12').reply(503);
status().times(5).reply(503);
await expect(upload()).rejects.toThrow('HTTP 503');
});
it('stops after the upload session restart limit', async () => {
mockToken();
for (let i = 0; i < 3; i++) {
mockStart();
uploadApi().put(session).reply(410);
}
await expect(upload()).rejects.toThrow('HTTP 410');
});
it('cancels before upload and does not request credentials', async () => {
const controller = new AbortController();
controller.abort();
await expect(upload(controller.signal)).rejects.toBe(controller.signal.reason);
});
it('cancels between chunks without sending the next chunk', async () => {
await fs.writeFile(artifactPath, Buffer.alloc(chunkSize + 12));
mockToken();
mockStart();
uploadApi()
.put(session)
.reply(308, '', { Range: `bytes=0-${chunkSize - 1}` });
const controller = new AbortController();
const reason = new Error('Upload cancelled');
await expect(
upload(
controller.signal,
jest.fn((bytes: number) => {
if (bytes > 0) {
controller.abort(reason);
}
})
)
).rejects.toBe(reason);
});
it.each([
'https://attacker.example/upload?secret=signed',
'http://androidpublisher.googleapis.com/upload',
'https://androidpublisher.googleapis.com.attacker.example/upload',
'https://user:[email protected]/upload',
])('rejects an unsafe session URL: %s', async location => {
mockToken();
mockStart(location);
await expect(upload()).rejects.toThrow('unsafe upload URL');
});
it('does not follow an upload redirect', async () => {
mockToken();
mockStart();
uploadApi().put(session).reply(302, '', { Location: 'https://attacker.example/upload' });
await expect(upload()).rejects.toThrow('HTTP 302');
});
it.each(['bytes=0-100', 'invalid', 'bytes=5-8'])(
'rejects an invalid acknowledged range: %s',
async range => {
mockToken();
mockStart();
uploadApi().put(session).reply(308, '', { Range: range });
await expect(upload()).rejects.toThrow('invalid upload range');
}
);
it('stops when uploads and status checks repeatedly confirm no progress', async () => {
mockToken();
mockStart();
uploadApi().put(session).matchHeader('content-length', '12').times(6).reply(308);
status().times(5).reply(308);
await expect(upload()).rejects.toThrow('confirmed 0 of 12 bytes');
});
it('preserves Google upload error details', async () => {
mockToken();
mockStart();
uploadApi()
.put(session)
.reply(403, {
error: {
message: 'Version code has already been used.',
errors: [{ reason: 'apkNotificationMessageKeyUpgradeVersionConflict' }],
},
});
await expect(upload()).rejects.toMatchObject({
status: 403,
apiMessage: 'Version code has already been used.',
reasons: ['apkNotificationMessageKeyUpgradeVersionConflict'],
});
});
it('resets the retry budget after confirmed progress', async () => {
mockToken();
mockStart();
for (let offset = 0; offset < 6; offset++) {
uploadApi().put(session).matchHeader('content-range', `bytes ${offset}-11/12`).reply(503);
status().reply(308, '', { Range: `bytes=0-${offset}` });
}
uploadApi()
.put(session)
.matchHeader('content-range', 'bytes 6-11/12')
.reply(200, { versionCode: 42 });
await expect(upload()).resolves.toBe(42);
});
it('retries a network failure during session creation', async () => {
mockToken();
api()
.post(`/upload${editPath}/apks`)
.query({ uploadType: 'resumable' })
.replyWithError('connection reset');
mockStart();
uploadApi().put(session).reply(200, { versionCode: 42 });
await expect(upload()).resolves.toBe(42);
});
it.each(['session', 'chunk', 'body', 'status'])('recovers a stalled %s request', async stalled => {
const timeout = AbortSignal.timeout.bind(AbortSignal);
const guard = timeout(1500);
jest.spyOn(AbortSignal, 'timeout').mockImplementation(() => timeout(100));
mockToken();
if (stalled === 'session') {
api()
.post(`/upload${editPath}/apks`)
.query({ uploadType: 'resumable' })
.delayConnection(300)
.reply(200, '', { Location: `https://androidpublisher.googleapis.com${session}` });
mockStart();
uploadApi().put(session).reply(200, { versionCode: 42 });
} else if (stalled === 'status') {
mockStart();
uploadApi().put(session).matchHeader('content-length', '12').reply(503);
status().delayConnection(300).reply(308);
status().reply(200, { versionCode: 42 });
} else {
mockStart();
const request = uploadApi().put(session).matchHeader('content-length', '12');
if (stalled === 'chunk') {
request.delayConnection(300);
} else {
request.delayBody(300);
}
request.reply(200, { versionCode: 42 });
status().reply(200, { versionCode: 42 });
}
await expect(upload(guard)).resolves.toBe(42);
});
it('stops when the binary becomes shorter during upload', async () => {
mockToken();
mockStart();
await expect(
upload(
undefined,
jest.fn(() => truncateSync(artifactPath, 0))
)
).rejects.toThrow('expected 12 bytes at offset 0, got 0');
});
it.each([
{ completes: true, finalResponse: 'lost' },
{ completes: false, finalResponse: 'lost' },
{ completes: true, finalResponse: 'stored' },
{ completes: false, finalResponse: 'stored' },
])(
'bounds completion checks (completes: $completes, final response: $finalResponse)',
async ({ completes, finalResponse }) => {
mockToken();
mockStart();
const finalChunk = uploadApi().put(session).matchHeader('content-length', '12');
if (finalResponse === 'lost') {
finalChunk.replyWithError('lost final response');
} else {
finalChunk.reply(308, '', { Range: 'bytes=0-11' });
}
status()
.times(completes ? 1 : 5)
.reply(308, '', { Range: 'bytes=0-11' });
if (completes) {
status().reply(200, { versionCode: 42 });
await expect(upload()).resolves.toBe(42);
} else {
await expect(upload()).rejects.toThrow(
'Google stored all 12 bytes but has not completed the upload.'
);
}
}
);
@@ -0,0 +1,21 @@
import nock from 'nock';
import { generateKeyPairSync } from 'node:crypto';
export const packageName = 'dev.expo.submitfixture';
export const editPath = `/androidpublisher/v3/applications/${packageName}/edits/edit`;
export const serviceAccount = {
client_email: '[email protected]',
private_key_id: 'test-key',
private_key: generateKeyPairSync('rsa', { modulusLength: 2048 }).privateKey,
};
export const api = (): nock.Scope =>
nock('https://androidpublisher.googleapis.com', {
reqheaders: { authorization: 'Bearer test-access-token' },
});
export function mockToken(times = 1): nock.Scope {
return nock('https://oauth2.googleapis.com').post('/token').times(times).reply(200, {
access_token: 'test-access-token',
expires_in: 3600,
token_type: 'Bearer',
});
}
@@ -293,6 +293,63 @@ describe(startUptermHostAsync, () => {
);
});
it('downloads through the cache proxy when one is configured', async () => {
uptermOnPath = false;
await startUptermHostAsync(
makeCtx({ EAS_BUILD_COCOAPODS_CACHE_URL: 'http://10.0.0.1:8081/repository/proxy' }),
{
relayServerUrl: 'wss://relay.expo.dev',
}
);
expect(mockedDownloadFile).toHaveBeenCalledTimes(1);
expect(mockedDownloadFile).toHaveBeenCalledWith(
expect.stringMatching(
/^http:\/\/10\.0\.0\.1:8081\/repository\/proxy\/storage\.googleapis\.com\/turtle-v2\/upterm\/upterm-/
),
expect.stringContaining('/tmp/eas-upterm-1'),
expect.objectContaining({ retry: 3 })
);
});
it('falls back to the direct URL when the proxied download fails', async () => {
uptermOnPath = false;
mockedDownloadFile.mockRejectedValueOnce(new Error('502 Bad Gateway') as never);
const host = await startUptermHostAsync(
makeCtx({ EAS_BUILD_COCOAPODS_CACHE_URL: 'http://10.0.0.1:8081/repository/proxy' }),
{ relayServerUrl: 'wss://relay.expo.dev' }
);
expect(host.connectionConfig.secret).toBe('TOKENx');
expect(mockedDownloadFile).toHaveBeenCalledTimes(2);
expect(mockedDownloadFile).toHaveBeenLastCalledWith(
expect.stringMatching(/^https:\/\/storage\.googleapis\.com\/turtle-v2\/upterm\/upterm-/),
expect.stringContaining('/tmp/eas-upterm-1'),
expect.objectContaining({ retry: 3 })
);
expect(mockedSpawn).toHaveBeenCalledWith(
expect.stringContaining('/tmp/eas-upterm-1'),
expect.arrayContaining(['host']),
expect.anything()
);
});
it('names the direct URL when both the proxied and the direct download fail', async () => {
uptermOnPath = false;
mockedDownloadFile.mockRejectedValue(new Error('403 Forbidden') as never);
await expect(
startUptermHostAsync(
makeCtx({ EAS_BUILD_COCOAPODS_CACHE_URL: 'http://10.0.0.1:8081/repository/proxy' }),
{
relayServerUrl: 'wss://r',
}
)
).rejects.toThrow(/could not be downloaded from https:\/\/storage\.googleapis\.com/);
});
it('throws when upterm is missing from PATH and the GCS download fails', async () => {
uptermOnPath = false;
mockedDownloadFile.mockRejectedValue(new Error('403 Forbidden') as never);
+29 -5
View File
@@ -1,11 +1,13 @@
import { Env, SystemError } from '@expo/eas-build-job';
import downloadFile from '@expo/downloader';
import { bunyan } from '@expo/logger';
import spawn, { SpawnPromise, SpawnResult } from '@expo/turtle-spawn';
import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { z } from 'zod';
import { getProxiedDownloadUrl } from './download';
import { isChildProcessAlive, killProcessGroup } from './processes';
import { sleepAsync } from './retry';
import { BuildContext } from '../context';
@@ -112,7 +114,7 @@ export function redactSpawnErrorForLog(err: unknown): unknown {
};
}
export async function resolveUptermPathAsync(env: Env): Promise<string> {
export async function resolveUptermPathAsync(env: Env, logger: bunyan): Promise<string> {
try {
await spawn('upterm', ['version'], { stdio: 'pipe', env });
return 'upterm';
@@ -121,14 +123,36 @@ export async function resolveUptermPathAsync(env: Env): Promise<string> {
const objectName = resolveUptermGcsObjectName();
const downloadDir = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-upterm-'));
const uptermPath = path.join(downloadDir, objectName);
const url = `${UPTERM_GCS_BASE_URL}/${objectName}`;
try {
const directUrl = `${UPTERM_GCS_BASE_URL}/${objectName}`;
const proxiedUrl = getProxiedDownloadUrl({
directUrl,
proxyBaseUrl: env.EAS_BUILD_COCOAPODS_CACHE_URL,
});
const downloadAsync = async (url: string): Promise<void> => {
await downloadFile(url, uptermPath, { retry: 3, timeout: UPTERM_DOWNLOAD_TIMEOUT_MS });
await fs.chmod(uptermPath, 0o755);
};
if (proxiedUrl) {
try {
await downloadAsync(proxiedUrl);
return uptermPath;
} catch (err) {
logger.debug(
{ err },
'Failed to download upterm through the cache proxy; falling back to the direct URL.'
);
await fs.rm(uptermPath, { force: true }).catch(() => {});
}
}
try {
await downloadAsync(directUrl);
} catch (err) {
await fs.rm(downloadDir, { recursive: true, force: true }).catch(() => {});
throw new SystemError(
`The upterm SSH client was not on PATH and could not be downloaded from ${url}. ${
`The upterm SSH client was not on PATH and could not be downloaded from ${directUrl}. ${
err instanceof Error ? err.message : String(err)
}`
);
@@ -193,7 +217,7 @@ export async function startUptermHostAsync(
ctx: BuildContext,
{ relayServerUrl }: { relayServerUrl: string }
): Promise<UptermHost> {
const uptermPath = await resolveUptermPathAsync(ctx.env);
const uptermPath = await resolveUptermPathAsync(ctx.env, ctx.logger);
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), 'eas-ssh-'));
const hostKeyPath = path.join(stateDir, 'id_host');
+152 -150
View File
File diff suppressed because it is too large. Load diff
+590 -5
View File
@@ -17348,7 +17348,7 @@
},
{
"name": "exceptionStacktrace",
"description": null,
"description": "Symbolicated when a build or update with a matching source map exists; otherwise as reported.",
"args": [],
"type": {
"kind": "SCALAR",
@@ -17496,7 +17496,7 @@
},
{
"name": "symbolicationBuild",
"description": "Build whose uploaded source map symbolicated exceptionStacktrace; null when the stack trace is shown as reported.",
"description": "Build whose uploaded source map symbolicated exceptionStacktrace; null when the stack trace is shown as reported or was symbolicated from an update.",
"args": [],
"type": {
"kind": "OBJECT",
@@ -17506,6 +17506,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "symbolicationUpdate",
"description": "Update whose uploaded source map symbolicated exceptionStacktrace; null when the stack trace is shown as reported or was symbolicated from a build.",
"args": [],
"type": {
"kind": "OBJECT",
"name": "Update",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "timestamp",
"description": null,
@@ -18879,7 +18891,7 @@
},
{
"name": "stacktrace",
"description": "Symbolicated when a build with a matching source map exists; otherwise as reported.",
"description": "Symbolicated when a build or update with a matching source map exists; otherwise as reported.",
"args": [],
"type": {
"kind": "SCALAR",
@@ -18891,7 +18903,7 @@
},
{
"name": "symbolicationBuild",
"description": "Build whose uploaded source map symbolicated stacktrace; null when the stack trace is shown as reported.",
"description": "Build whose uploaded source map symbolicated stacktrace; null when the stack trace is shown as reported or was symbolicated from an update.",
"args": [],
"type": {
"kind": "OBJECT",
@@ -18901,6 +18913,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "symbolicationUpdate",
"description": "Update whose uploaded source map symbolicated stacktrace; null when the stack trace is shown as reported or was symbolicated from a build.",
"args": [],
"type": {
"kind": "OBJECT",
"name": "Update",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "timestamp",
"description": null,
@@ -47800,6 +47824,108 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "CreateSandboxArtifactUploadSessionInput",
"description": null,
"fields": null,
"inputFields": [
{
"name": "filename",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "name",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "size",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ByteSize",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "CreateSandboxArtifactUploadSessionResult",
"description": null,
"fields": [
{
"name": "artifact",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "SandboxArtifact",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "uploadSession",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "SandboxArtifactUploadSession",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "CreateSandboxInput",
@@ -77308,6 +77434,22 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "sandboxArtifacts",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "SandboxArtifactQuery",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "sandboxes",
"description": null,
@@ -79222,6 +79364,30 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "artifacts",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "SandboxArtifact",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createdAt",
"description": null,
@@ -79348,6 +79514,224 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "SandboxArtifact",
"description": null,
"fields": [
{
"name": "createdAt",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "DateTime",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "downloadUrl",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "fileSizeBytes",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "ByteSize",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "filename",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "id",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "name",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "sandbox",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "Sandbox",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "updatedAt",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "DateTime",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "SandboxArtifactQuery",
"description": null,
"fields": [
{
"name": "byId",
"description": null,
"args": [
{
"name": "sandboxArtifactId",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "SandboxArtifact",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "SandboxArtifactUploadSession",
"description": null,
"fields": [
{
"name": "headers",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "JSONObject",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "url",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "SandboxConnection",
@@ -79478,6 +79862,55 @@
"name": "SandboxMutation",
"description": null,
"fields": [
{
"name": "createArtifactUploadSession",
"description": null,
"args": [
{
"name": "input",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "CreateSandboxArtifactUploadSessionInput",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "sandboxId",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "CreateSandboxArtifactUploadSessionResult",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createSandbox",
"description": null,
@@ -79511,6 +79944,39 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "finalizeArtifact",
"description": null,
"args": [
{
"name": "artifactId",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "SandboxArtifact",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "markSandboxReady",
"description": null,
@@ -101688,6 +102154,26 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "platforms",
"description": "Runs whose platform is unknown match no platforms filter.",
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "AppPlatform",
"ofType": null
}
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "workflowIds",
"description": null,
@@ -102062,6 +102548,26 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "platforms",
"description": "Runs whose platform is unknown match no platforms filter.",
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "AppPlatform",
"ofType": null
}
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "statuses",
"description": null,
@@ -102280,7 +102786,7 @@
{
"kind": "OBJECT",
"name": "WorkflowDeviceTestCaseInsightsTotals",
"description": "Raw counts only (paired with previous-window values). Pass rate, flake rate,\nand trends are computed in the frontend from the (currentValue, previousValue)\npair on each metric.\n\ntotalRuns = passedCleanCount + flakyCount + failedCount (over is_final_attempt=1 rows).\ndistinctFlakyTestCount cannot be derived in the frontend from per-test rows\nbecause pagination means the frontend doesn't see all test paths.",
"description": "Raw counts only (paired with previous-window values). Pass rate, flake rate,\nand trends are computed in the frontend from the (currentValue, previousValue)\npair on each metric.\n\ntotalRuns = passedCleanCount + flakyCount + failedCount (over is_final_attempt=1 rows).\nplatforms splits totalRuns by platform.\ndistinctFlakyTestCount cannot be derived in the frontend from per-test rows\nbecause pagination means the frontend doesn't see all test paths.",
"fields": [
{
"name": "avgDurationMs",
@@ -102378,6 +102884,85 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "platforms",
"description": "One entry per platform with runs in the current or previous window, in the order iOS,\nAndroid, unknown.",
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "WorkflowDeviceTestCasePlatformTotals",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "totalRuns",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "WorkflowDeviceTestCaseInsightsMetric",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "WorkflowDeviceTestCasePlatformTotals",
"description": null,
"fields": [
{
"name": "distinctTestCount",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "WorkflowDeviceTestCaseInsightsMetric",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "platform",
"description": "Null for runs whose platform could not be derived: Maestro runs in custom jobs, and\nruns ingested before the platform was recorded.",
"args": [],
"type": {
"kind": "ENUM",
"name": "AppPlatform",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "totalRuns",
"description": null,
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "eas-cli",
"version": "24.13.0",
"version": "24.14.0",
"description": "EAS command line tool",
"keywords": [
"cli",
@@ -13,7 +13,8 @@ import Log from '../../log';
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
export default class ChannelProtect extends EasCommand {
static override description = 'protect a channel so only account admins can publish to it';
static override description =
'protect a channel so only Release Managers, Admins, and Owners can publish to it';
static override args = {
name: Args.string({
@@ -14,7 +14,7 @@ import { toggleConfirmAsync } from '../../prompts';
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
export default class ChannelUnprotect extends EasCommand {
static override description = "remove a channel's admin-only publishing restriction";
static override description = "remove a channel's protected publishing restriction";
static override args = {
name: Args.string({
@@ -42,6 +42,13 @@ const totals: any = {
distinctFlakyTestCount: metric(3, 2),
avgDurationMs: { currentValue: 42100, previousValue: 45000 },
p90DurationMs: { currentValue: 72000, previousValue: null },
platforms: [
{
platform: 'IOS',
totalRuns: metric(120, 100),
distinctTestCount: metric(8, 8),
},
],
};
const timeSeries: any[] = [
@@ -175,6 +182,8 @@ describe(WorkflowInsightsMaestro, () => {
'FLAKY',
'--tag',
'smoke',
'--platform',
'ios',
'--git-ref',
'main',
'--search',
@@ -196,6 +205,7 @@ describe(WorkflowInsightsMaestro, () => {
workflowIds: ['id-of-e2e.yml'],
statuses: ['PASSED_CLEAN', 'FLAKY'],
tags: ['smoke'],
platforms: ['IOS'],
gitRefs: ['refs/heads/main'],
},
search: 'login',
@@ -206,7 +216,7 @@ describe(WorkflowInsightsMaestro, () => {
);
});
it('queries one flow history with --flow, keeping only the workflow and git ref filters', async () => {
it('queries one flow history with --flow, keeping the workflow, git ref, and platform filters', async () => {
const { command } = createCommand([
'--flow',
'flows/login.yaml',
@@ -214,6 +224,8 @@ describe(WorkflowInsightsMaestro, () => {
'e2e.yml',
'--git-ref',
'main',
'--platform',
'android',
]);
await command.runAsync();
@@ -222,7 +234,11 @@ describe(WorkflowInsightsMaestro, () => {
path: 'flows/login.yaml',
startTime: '2026-09-01T00:00:00.000Z',
endTime: '2026-09-09T00:00:00.000Z',
filters: { workflowIds: ['id-of-e2e.yml'], gitRefs: ['refs/heads/main'] },
filters: {
workflowIds: ['id-of-e2e.yml'],
gitRefs: ['refs/heads/main'],
platforms: ['ANDROID'],
},
granularity: 'DAY',
errorPatternsFirst: 5,
recentRunsFirst: 50,
@@ -241,6 +257,11 @@ describe(WorkflowInsightsMaestro, () => {
await expect(command.runAsync()).rejects.toThrow();
});
it('rejects unknown platforms', async () => {
const { command } = createCommand(['--platform', 'web']);
await expect(command.runAsync()).rejects.toThrow();
});
it('skips the project directory when --project-id is given', async () => {
const { command, getContextAsync } = createCommand(['--project-id', 'other-app']);
await command.runAsync();
@@ -264,6 +285,13 @@ describe(WorkflowInsightsMaestro, () => {
expect(json.project).toBe('@acme/app');
expect(json.totals.passRatePercent).toEqual({ current: 90, previous: 90 });
expect(json.totals.avgDurationMs).toEqual({ current: 42100, previous: 45000 });
expect(json.totals.platforms).toEqual([
{
platform: 'IOS',
totalRuns: { current: 120, previous: 100 },
distinctFlows: { current: 8, previous: 8 },
},
]);
expect(json.flows[0].path).toBe('flows/login.yaml');
expect(json.sort).toEqual({ field: 'fails', direction: 'desc' });
});
@@ -1,3 +1,4 @@
import { Platform } from '@expo/eas-build-job';
import { Flags } from '@oclif/core';
import EasCommand from '../../../commandUtils/EasCommand';
@@ -48,6 +49,11 @@ export default class WorkflowInsightsMaestro extends EasCommand {
static override flags = {
...WorkflowsInsightsSharedFilterFlags,
platform: Flags.option({
description: 'Only include flow runs on this platform (can be specified multiple times).',
options: [Platform.IOS, Platform.ANDROID] as const,
multiple: true,
})(),
status: Flags.option({
description:
'Only include flow runs with this status (can be specified multiple times). PASSED means passed on the first attempt.',
+85 -4
View File
@@ -2702,6 +2702,7 @@ export type AppObserveCustomEvent = {
errorSource?: Maybe<Scalars['String']['output']>;
eventName: Scalars['String']['output'];
exceptionMessage?: Maybe<Scalars['String']['output']>;
/** Symbolicated when a build or update with a matching source map exists; otherwise as reported. */
exceptionStacktrace?: Maybe<Scalars['String']['output']>;
/** Error fields below are populated only for exception events (eventName: exception). */
exceptionType?: Maybe<Scalars['String']['output']>;
@@ -2714,8 +2715,10 @@ export type AppObserveCustomEvent = {
sessionId?: Maybe<Scalars['String']['output']>;
severityNumber?: Maybe<Scalars['Int']['output']>;
severityText?: Maybe<Scalars['String']['output']>;
/** Build whose uploaded source map symbolicated exceptionStacktrace; null when the stack trace is shown as reported. */
/** Build whose uploaded source map symbolicated exceptionStacktrace; null when the stack trace is shown as reported or was symbolicated from an update. */
symbolicationBuild?: Maybe<Build>;
/** Update whose uploaded source map symbolicated exceptionStacktrace; null when the stack trace is shown as reported or was symbolicated from a build. */
symbolicationUpdate?: Maybe<Update>;
timestamp: Scalars['DateTime']['output'];
};
@@ -2870,10 +2873,12 @@ export type AppObserveError = AppObserveLog & {
severityNumber?: Maybe<Scalars['Int']['output']>;
severityText?: Maybe<Scalars['String']['output']>;
source?: Maybe<Scalars['String']['output']>;
/** Symbolicated when a build with a matching source map exists; otherwise as reported. */
/** Symbolicated when a build or update with a matching source map exists; otherwise as reported. */
stacktrace?: Maybe<Scalars['String']['output']>;
/** Build whose uploaded source map symbolicated stacktrace; null when the stack trace is shown as reported. */
/** Build whose uploaded source map symbolicated stacktrace; null when the stack trace is shown as reported or was symbolicated from an update. */
symbolicationBuild?: Maybe<Build>;
/** Update whose uploaded source map symbolicated stacktrace; null when the stack trace is shown as reported or was symbolicated from a build. */
symbolicationUpdate?: Maybe<Update>;
timestamp: Scalars['DateTime']['output'];
type?: Maybe<Scalars['String']['output']>;
};
@@ -6729,6 +6734,18 @@ export type CreatePostHogDeepLinkInput = {
purpose?: InputMaybe<PostHogDeepLinkPurpose>;
};
export type CreateSandboxArtifactUploadSessionInput = {
filename: Scalars['String']['input'];
name: Scalars['String']['input'];
size: Scalars['ByteSize']['input'];
};
export type CreateSandboxArtifactUploadSessionResult = {
__typename?: 'CreateSandboxArtifactUploadSessionResult';
artifact: SandboxArtifact;
uploadSession: SandboxArtifactUploadSession;
};
export type CreateSandboxInput = {
agentRunId?: InputMaybe<Scalars['ID']['input']>;
appId: Scalars['ID']['input'];
@@ -11030,6 +11047,7 @@ export type RootQuery = {
posthogIntegration: PostHogIntegrationQuery;
/** Top-level query object for querying Runtimes. */
runtimes: RuntimeQuery;
sandboxArtifacts: SandboxArtifactQuery;
sandboxes: SandboxQuery;
snack: SnackQuery;
/** Top-level query object for querying Expo status page services. */
@@ -11279,6 +11297,7 @@ export type SsoUserDataInput = {
export type Sandbox = {
__typename?: 'Sandbox';
app: App;
artifacts: Array<SandboxArtifact>;
createdAt: Scalars['DateTime']['output'];
finishedAt?: Maybe<Scalars['DateTime']['output']>;
id: Scalars['ID']['output'];
@@ -11289,6 +11308,34 @@ export type Sandbox = {
updatedAt: Scalars['DateTime']['output'];
};
export type SandboxArtifact = {
__typename?: 'SandboxArtifact';
createdAt: Scalars['DateTime']['output'];
downloadUrl?: Maybe<Scalars['String']['output']>;
fileSizeBytes?: Maybe<Scalars['ByteSize']['output']>;
filename: Scalars['String']['output'];
id: Scalars['ID']['output'];
name: Scalars['String']['output'];
sandbox: Sandbox;
updatedAt: Scalars['DateTime']['output'];
};
export type SandboxArtifactQuery = {
__typename?: 'SandboxArtifactQuery';
byId: SandboxArtifact;
};
export type SandboxArtifactQuery_ByIdArgs = {
sandboxArtifactId: Scalars['ID']['input'];
};
export type SandboxArtifactUploadSession = {
__typename?: 'SandboxArtifactUploadSession';
headers: Scalars['JSONObject']['output'];
url: Scalars['String']['output'];
};
export type SandboxConnection = {
__typename?: 'SandboxConnection';
edges: Array<SandboxEdge>;
@@ -11307,18 +11354,31 @@ export type SandboxFilterInput = {
export type SandboxMutation = {
__typename?: 'SandboxMutation';
createArtifactUploadSession: CreateSandboxArtifactUploadSessionResult;
createSandbox: Sandbox;
finalizeArtifact: SandboxArtifact;
markSandboxReady: Sandbox;
stopSandbox: Sandbox;
touchSandbox: Sandbox;
};
export type SandboxMutation_CreateArtifactUploadSessionArgs = {
input: CreateSandboxArtifactUploadSessionInput;
sandboxId: Scalars['ID']['input'];
};
export type SandboxMutation_CreateSandboxArgs = {
input: CreateSandboxInput;
};
export type SandboxMutation_FinalizeArtifactArgs = {
artifactId: Scalars['ID']['input'];
};
export type SandboxMutation_MarkSandboxReadyArgs = {
sandboxId: Scalars['ID']['input'];
};
@@ -14434,6 +14494,8 @@ export type WorkflowDeviceTestCaseHistory_TimeSeriesArgs = {
export type WorkflowDeviceTestCaseHistoryFiltersInput = {
gitRefs?: InputMaybe<Array<Scalars['String']['input']>>;
/** Runs whose platform is unknown match no platforms filter. */
platforms?: InputMaybe<Array<AppPlatform>>;
workflowIds?: InputMaybe<Array<Scalars['ID']['input']>>;
};
@@ -14482,6 +14544,8 @@ export type WorkflowDeviceTestCaseInsightsFacets = {
export type WorkflowDeviceTestCaseInsightsFiltersInput = {
gitRefs?: InputMaybe<Array<Scalars['String']['input']>>;
/** Runs whose platform is unknown match no platforms filter. */
platforms?: InputMaybe<Array<AppPlatform>>;
statuses?: InputMaybe<Array<WorkflowDeviceTestCaseStatusFilter>>;
tags?: InputMaybe<Array<Scalars['String']['input']>>;
workflowIds?: InputMaybe<Array<Scalars['ID']['input']>>;
@@ -14531,6 +14595,7 @@ export type WorkflowDeviceTestCaseInsightsTimespanInput = {
* pair on each metric.
*
* totalRuns = passedCleanCount + flakyCount + failedCount (over is_final_attempt=1 rows).
* platforms splits totalRuns by platform.
* distinctFlakyTestCount cannot be derived in the frontend from per-test rows
* because pagination means the frontend doesn't see all test paths.
*/
@@ -14542,6 +14607,22 @@ export type WorkflowDeviceTestCaseInsightsTotals = {
flakyCount: WorkflowDeviceTestCaseInsightsMetric;
p90DurationMs: WorkflowDeviceTestCaseInsightsNullableMetric;
passedCleanCount: WorkflowDeviceTestCaseInsightsMetric;
/**
* One entry per platform with runs in the current or previous window, in the order iOS,
* Android, unknown.
*/
platforms: Array<WorkflowDeviceTestCasePlatformTotals>;
totalRuns: WorkflowDeviceTestCaseInsightsMetric;
};
export type WorkflowDeviceTestCasePlatformTotals = {
__typename?: 'WorkflowDeviceTestCasePlatformTotals';
distinctTestCount: WorkflowDeviceTestCaseInsightsMetric;
/**
* Null for runs whose platform could not be derived: Maestro runs in custom jobs, and
* runs ingested before the platform was recorded.
*/
platform?: Maybe<AppPlatform>;
totalRuns: WorkflowDeviceTestCaseInsightsMetric;
};
@@ -17308,7 +17389,7 @@ export type WorkflowDeviceTestCaseInsightsByAppIdQueryVariables = Exact<{
}>;
export type WorkflowDeviceTestCaseInsightsByAppIdQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, fullName: string, workflowDeviceTestCaseInsights: { __typename?: 'WorkflowDeviceTestCaseInsights', totals: { __typename?: 'WorkflowDeviceTestCaseInsightsTotals', totalRuns: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, passedCleanCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, flakyCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, distinctFlakyTestCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, avgDurationMs: { __typename?: 'WorkflowDeviceTestCaseInsightsNullableMetric', currentValue?: number | null, previousValue?: number | null } }, timeSeries: Array<{ __typename?: 'WorkflowDeviceTestCaseInsightsBucket', bucketStartAt: any, passedClean: number, flaky: number, failed: number }>, tests: { __typename?: 'WorkflowDeviceTestCaseStatConnection', totalCount: number, edges: Array<{ __typename?: 'WorkflowDeviceTestCaseStatEdge', node: { __typename?: 'WorkflowDeviceTestCaseStat', path: string, name: string, totalRuns: number, passedCleanCount: number, flakyCount: number, failedCount: number, p90DurationMs?: number | null, lastRunAt: any, lastRunStatus: WorkflowDeviceTestCaseStatus, lastRunIsFlaky: boolean } }>, pageInfo: { __typename?: 'PageInfo', hasNextPage: boolean } } } } } };
export type WorkflowDeviceTestCaseInsightsByAppIdQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, fullName: string, workflowDeviceTestCaseInsights: { __typename?: 'WorkflowDeviceTestCaseInsights', totals: { __typename?: 'WorkflowDeviceTestCaseInsightsTotals', totalRuns: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, passedCleanCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, flakyCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, distinctFlakyTestCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, avgDurationMs: { __typename?: 'WorkflowDeviceTestCaseInsightsNullableMetric', currentValue?: number | null, previousValue?: number | null }, platforms: Array<{ __typename?: 'WorkflowDeviceTestCasePlatformTotals', platform?: AppPlatform | null, totalRuns: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number }, distinctTestCount: { __typename?: 'WorkflowDeviceTestCaseInsightsMetric', currentValue: number, previousValue: number } }> }, timeSeries: Array<{ __typename?: 'WorkflowDeviceTestCaseInsightsBucket', bucketStartAt: any, passedClean: number, flaky: number, failed: number }>, tests: { __typename?: 'WorkflowDeviceTestCaseStatConnection', totalCount: number, edges: Array<{ __typename?: 'WorkflowDeviceTestCaseStatEdge', node: { __typename?: 'WorkflowDeviceTestCaseStat', path: string, name: string, totalRuns: number, passedCleanCount: number, flakyCount: number, failedCount: number, p90DurationMs?: number | null, lastRunAt: any, lastRunStatus: WorkflowDeviceTestCaseStatus, lastRunIsFlaky: boolean } }>, pageInfo: { __typename?: 'PageInfo', hasNextPage: boolean } } } } } };
export type WorkflowDeviceTestCaseHistoryByAppIdQueryVariables = Exact<{
appId: Scalars['String']['input'];
@@ -89,6 +89,17 @@ export const WorkflowDeviceTestCaseInsightsQuery = {
currentValue
previousValue
}
platforms {
platform
totalRuns {
currentValue
previousValue
}
distinctTestCount {
currentValue
previousValue
}
}
}
timeSeries(granularity: $granularity) {
bucketStartAt
@@ -1,4 +1,5 @@
import {
AppPlatform,
WorkflowDeviceTestCaseInsightsTimeSeriesGranularity,
WorkflowDeviceTestCaseStatus,
} from '../../../graphql/generated';
@@ -39,8 +40,34 @@ const timeSeries = [
},
];
const platformTotals = [
{
__typename: 'WorkflowDeviceTestCasePlatformTotals' as const,
platform: AppPlatform.Ios,
totalRuns: metric(120, 100),
distinctTestCount: metric(8, 8),
},
{
__typename: 'WorkflowDeviceTestCasePlatformTotals' as const,
platform: AppPlatform.Android,
totalRuns: metric(70, 60),
distinctTestCount: metric(6, 5),
},
{
__typename: 'WorkflowDeviceTestCasePlatformTotals' as const,
platform: null,
totalRuns: metric(10, 0),
distinctTestCount: metric(2, 0),
},
];
function makeApp(
overrides: { flows?: any[]; hasNextPage?: boolean; timeSeries?: typeof timeSeries } = {}
overrides: {
flows?: any[];
hasNextPage?: boolean;
timeSeries?: typeof timeSeries;
platformTotals?: typeof platformTotals;
} = {}
): AppWithMaestroInsightsObject {
return {
__typename: 'App',
@@ -59,6 +86,7 @@ function makeApp(
currentValue: 42100,
previousValue: null,
},
platforms: overrides.platformTotals ?? platformTotals,
},
timeSeries: overrides.timeSeries ?? timeSeries,
tests: {
@@ -206,6 +234,23 @@ describe(toMaestroInsightsSummary, () => {
passRatePercent: { current: 90, previous: 90 },
distinctFlakyFlows: { current: 3, previous: 2 },
avgDurationMs: { current: 42100, previous: null },
platforms: [
{
platform: 'IOS',
totalRuns: { current: 120, previous: 100 },
distinctFlows: { current: 8, previous: 8 },
},
{
platform: 'ANDROID',
totalRuns: { current: 70, previous: 60 },
distinctFlows: { current: 6, previous: 5 },
},
{
platform: null,
totalRuns: { current: 10, previous: 0 },
distinctFlows: { current: 2, previous: 0 },
},
],
});
});
@@ -256,6 +301,7 @@ describe(buildMaestroInsightsJson, () => {
'passRatePercent',
'distinctFlakyFlows',
'avgDurationMs',
'platforms',
]);
expect(json.runsOverTime.granularity).toBe('DAY');
expect(json.flows).toHaveLength(2);
@@ -291,6 +337,25 @@ describe(buildMaestroInsightsTable, () => {
expect(table).toContain('FLAKY');
});
it('lists runs and flows per platform', () => {
const table = stripAnsi(buildMaestroInsightsTable(makeSummary()));
expect(table).toContain('By platform (compared with the previous period):');
expect(table).toMatch(/iOS runs\s+120 \(\+20\.0%\)/);
expect(table).toMatch(/iOS flows\s+8 \(0\.0%\)/);
expect(table).toMatch(/Android runs\s+70 \(\+16\.7%\)/);
expect(table).toMatch(/Android flows\s+6 \(\+20\.0%\)/);
expect(table).toMatch(/Unknown runs\s+10 \(n\/a\)/);
expect(table).toMatch(/Unknown flows\s+2 \(n\/a\)/);
expect(table.indexOf('By platform')).toBeLessThan(table.indexOf('Runs over time'));
});
it('skips the platform section when there are no platform entries', () => {
const table = buildMaestroInsightsTable(makeSummary({ platformTotals: [] }));
expect(table).not.toContain('By platform');
});
it('omits buckets with no runs and says so in the heading', () => {
const bucket = (day: string, passedClean: number): (typeof timeSeries)[number] => ({
__typename: 'WorkflowDeviceTestCaseInsightsBucket',
@@ -1,3 +1,5 @@
import { Platform } from '@expo/eas-build-job';
import { ExpoGraphqlClient } from '../../../commandUtils/context/contextUtils/createGraphqlClient';
import { AppQuery } from '../../../graphql/queries/AppQuery';
import {
@@ -31,6 +33,7 @@ describe(resolveMaestroInsightsFiltersInputAsync, () => {
workflow: ['e2e.yml'],
status: ['PASSED', 'FLAKY', 'FAILED'],
tag: ['smoke'],
platform: [Platform.IOS, Platform.ANDROID],
'git-ref': 'main',
});
@@ -38,6 +41,7 @@ describe(resolveMaestroInsightsFiltersInputAsync, () => {
workflowIds: ['id-of-e2e.yml'],
statuses: ['PASSED_CLEAN', 'FLAKY', 'FAILED'],
tags: ['smoke'],
platforms: ['IOS', 'ANDROID'],
gitRefs: ['refs/heads/main'],
});
});
@@ -51,16 +55,21 @@ describe(resolveMaestroHistoryFiltersInputAsync, () => {
]);
});
it('resolves only the workflow and git ref filters', async () => {
it('resolves the workflow, git ref, and platform filters', async () => {
await expect(
resolveMaestroHistoryFiltersInputAsync(graphqlClient, 'app-1', {
workflow: ['e2e.yml'],
'git-ref': 'main',
platform: [Platform.ANDROID],
})
).resolves.toEqual({ workflowIds: ['id-of-e2e.yml'], gitRefs: ['refs/heads/main'] });
).resolves.toEqual({
workflowIds: ['id-of-e2e.yml'],
gitRefs: ['refs/heads/main'],
platforms: ['ANDROID'],
});
});
it('is undefined when neither is set', async () => {
it('is undefined when no filter is set', async () => {
await expect(
resolveMaestroHistoryFiltersInputAsync(graphqlClient, 'app-1', {})
).resolves.toBeUndefined();
@@ -74,7 +83,17 @@ describe(getAppliedMaestroInsightsFilters, () => {
it('keeps the values as given, with the git ref normalized', () => {
expect(
getAppliedMaestroInsightsFilters({ status: ['PASSED'], tag: ['smoke'], 'git-ref': 'main' })
).toEqual({ statuses: ['PASSED'], tags: ['smoke'], gitRef: 'refs/heads/main' });
getAppliedMaestroInsightsFilters({
status: ['PASSED'],
tag: ['smoke'],
platform: [Platform.IOS],
'git-ref': 'main',
})
).toEqual({
statuses: ['PASSED'],
tags: ['smoke'],
platforms: ['IOS'],
gitRef: 'refs/heads/main',
});
});
});
@@ -2,6 +2,7 @@ import chalk from 'chalk';
import indentString from 'indent-string';
import {
AppPlatform,
WorkflowDeviceTestCaseInsightsTimeSeriesGranularity,
WorkflowDeviceTestCaseStatus,
} from '../../graphql/generated';
@@ -17,6 +18,7 @@ import {
toTimespanJson,
} from '../../insights/formatTimespan';
import { formatAppliedFilters } from '../../insights/formatFilters';
import { appPlatformDisplayNames } from '../../platform';
import formatFields, { FormatFieldsItem } from '../../utils/formatFields';
import renderTextTable from '../../utils/renderTextTable';
import { sanitizeTerminalText, truncate } from '../../utils/terminalText';
@@ -34,12 +36,20 @@ import {
toNullableMetricSummary,
} from '../../insights/metrics';
/** Runs on one platform; `platform` is null for runs whose platform is not recorded. */
export interface MaestroPlatformTotals {
platform: AppPlatform | null;
totalRuns: InsightsMetricSummary;
distinctFlows: InsightsMetricSummary;
}
/** The Maestro tab's overview tiles. */
export interface MaestroInsightsTotals {
totalRuns: InsightsMetricSummary;
passRatePercent: InsightsMetricSummary;
distinctFlakyFlows: InsightsMetricSummary;
avgDurationMs: NullableMetricSummary;
platforms: MaestroPlatformTotals[];
}
/** The tiles of one flow's detail view, which shows no previous-period comparison. */
@@ -103,7 +113,7 @@ export interface MaestroFlowHistorySummary extends InsightsTimespanFields {
appFullName: string;
flowPath: string;
granularity: WorkflowDeviceTestCaseInsightsTimeSeriesGranularity;
filters?: Pick<AppliedMaestroInsightsFilters, 'workflows' | 'gitRef'>;
filters?: Pick<AppliedMaestroInsightsFilters, 'workflows' | 'gitRef' | 'platforms'>;
totals: MaestroFlowTotals;
runsOverTime: MaestroInsightsBucket[];
errorPatterns: MaestroErrorPatternSummary[];
@@ -213,6 +223,11 @@ function toOverviewTotals(totals: OverviewTotalsObject): MaestroInsightsTotals {
},
distinctFlakyFlows: toMetricSummary(totals.distinctFlakyTestCount),
avgDurationMs: toNullableMetricSummary(totals.avgDurationMs),
platforms: totals.platforms.map(entry => ({
platform: entry.platform ?? null,
totalRuns: toMetricSummary(entry.totalRuns),
distinctFlows: toMetricSummary(entry.distinctTestCount),
})),
};
}
@@ -281,6 +296,8 @@ export function buildMaestroInsightsTable(summary: MaestroInsightsSummary): stri
sections.push(chalk.bold('Overview (compared with the previous period):'));
sections.push(formatFields(buildOverviewTotalsFields(summary.totals)));
sections.push(...buildPlatformTotalsSection(summary.totals.platforms));
sections.push(...buildMaestroRunsOverTimeSection(summary.runsOverTime, summary.granularity));
sections.push('');
@@ -365,6 +382,25 @@ function buildOverviewTotalsFields(totals: MaestroInsightsTotals): FormatFieldsI
];
}
function buildPlatformTotalsSection(platforms: MaestroPlatformTotals[]): string[] {
if (platforms.length === 0) {
return [];
}
return [
'',
chalk.bold('By platform (compared with the previous period):'),
formatFields(
platforms.flatMap(entry => {
const name = entry.platform === null ? 'Unknown' : appPlatformDisplayNames[entry.platform];
return [
{ label: `${name} runs`, value: formatCountWithTrend(entry.totalRuns) },
{ label: `${name} flows`, value: formatCountWithTrend(entry.distinctFlows) },
];
})
),
];
}
function buildFlowTotalsFields(totals: MaestroFlowTotals): FormatFieldsItem[] {
return [
{ label: 'Maestro runs', value: totals.totalRuns.toLocaleString() },
@@ -446,6 +482,7 @@ function formatFilters(filters: AppliedMaestroInsightsFilters): string {
['workflows', filters.workflows],
['statuses', filters.statuses],
['tags', filters.tags],
['platforms', filters.platforms?.map(platform => appPlatformDisplayNames[platform])],
['search', filters.search],
['git ref', filters.gitRef],
]);
@@ -1,9 +1,13 @@
import { Platform } from '@expo/eas-build-job';
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
import {
AppPlatform,
WorkflowDeviceTestCaseHistoryFiltersInput,
WorkflowDeviceTestCaseInsightsFiltersInput,
WorkflowDeviceTestCaseStatusFilter,
} from '../../graphql/generated';
import { toAppPlatform } from '../../graphql/types/AppPlatform';
import { normalizeGitRef, resolveWorkflowIdsAsync } from './filters';
/** Statuses as the dashboard names them; `PASSED` means passed on the first attempt. */
@@ -20,15 +24,16 @@ export interface MaestroInsightsFilterFlags {
workflow?: string[];
status?: MaestroStatusOption[];
tag?: string[];
platform?: Platform[];
search?: string;
'git-ref'?: string;
}
/** The filters as the user typed them, before workflow file names are resolved to IDs. */
export interface AppliedMaestroInsightsFilters {
workflows?: string[];
statuses?: MaestroStatusOption[];
tags?: string[];
platforms?: AppPlatform[];
search?: string;
gitRef?: string;
}
@@ -36,7 +41,7 @@ export interface AppliedMaestroInsightsFilters {
export async function resolveMaestroHistoryFiltersInputAsync(
graphqlClient: ExpoGraphqlClient,
appId: string,
flags: Pick<MaestroInsightsFilterFlags, 'workflow' | 'git-ref'>
flags: Pick<MaestroInsightsFilterFlags, 'workflow' | 'git-ref' | 'platform'>
): Promise<WorkflowDeviceTestCaseHistoryFiltersInput | undefined> {
const input: WorkflowDeviceTestCaseHistoryFiltersInput = {};
if (flags.workflow?.length) {
@@ -45,6 +50,9 @@ export async function resolveMaestroHistoryFiltersInputAsync(
if (flags['git-ref']) {
input.gitRefs = [normalizeGitRef(flags['git-ref'])];
}
if (flags.platform?.length) {
input.platforms = flags.platform.map(toAppPlatform);
}
return Object.keys(input).length === 0 ? undefined : input;
}
@@ -72,6 +80,7 @@ export function getAppliedMaestroInsightsFilters(
...(flags.workflow?.length ? { workflows: flags.workflow } : {}),
...(flags.status?.length ? { statuses: flags.status } : {}),
...(flags.tag?.length ? { tags: flags.tag } : {}),
...(flags.platform?.length ? { platforms: flags.platform.map(toAppPlatform) } : {}),
...(flags.search ? { search: flags.search } : {}),
...(flags['git-ref'] ? { gitRef: normalizeGitRef(flags['git-ref']) } : {}),
};
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "eas-cli-local-build-plugin",
"version": "24.13.0",
"version": "24.14.0",
"description": "Tool for running EAS compatible builds on a local machine.",
"bugs": "https://github.com/expo/eas-cli/issues",
"license": "BUSL-1.1",
@@ -26,7 +26,7 @@
"clean": "rimraf node_modules dist coverage \"*.tsbuildinfo\""
},
"dependencies": {
"@expo/build-tools": "24.13.0",
"@expo/build-tools": "24.14.0",
"@expo/bunyan": "^4.0.1",
"@expo/eas-build-job": "24.13.0",
"@expo/logger": "24.13.0",
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@expo/worker",
"version": "24.13.0",
"version": "24.14.0",
"private": true,
"scripts": {
"start": "yarn watch",
@@ -19,7 +19,7 @@
},
"dependencies": {
"@babel/core": "7.24.7",
"@expo/build-tools": "24.13.0",
"@expo/build-tools": "24.14.0",
"@expo/config-plugins": "55.0.7",
"@expo/config-types": "55.0.5",
"@expo/eas-build-job": "24.13.0",
Generated
+3 -3
View File
@@ -2303,7 +2303,7 @@ __metadata:
languageName: node
linkType: hard
"@expo/build-tools@npm:24.13.0, @expo/build-tools@workspace:packages/build-tools":
"@expo/build-tools@npm:24.14.0, @expo/build-tools@workspace:packages/build-tools":
version: 0.0.0-use.local
resolution: "@expo/build-tools@workspace:packages/build-tools"
dependencies:
@@ -2984,7 +2984,7 @@ __metadata:
resolution: "@expo/worker@workspace:packages/worker"
dependencies:
"@babel/core": "npm:7.24.7"
"@expo/build-tools": "npm:24.13.0"
"@expo/build-tools": "npm:24.14.0"
"@expo/config-plugins": "npm:55.0.7"
"@expo/config-types": "npm:55.0.5"
"@expo/eas-build-job": "npm:24.13.0"
@@ -10418,7 +10418,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "eas-cli-local-build-plugin@workspace:packages/local-build-plugin"
dependencies:
"@expo/build-tools": "npm:24.13.0"
"@expo/build-tools": "npm:24.14.0"
"@expo/bunyan": "npm:^4.0.1"
"@expo/eas-build-job": "npm:24.13.0"
"@expo/logger": "npm:24.13.0"