Skip to content

Commit 5036b50

Browse files
Espresso and XCUITest: same CI/CD metadata as Maestro
--branch, --pr-url, -m/--metadata and CI environment detection, built by one shared ciRunMetadata() for all three run commands. One RunMetadata type.
1 parent 2ac6edb commit 5036b50

6 files changed

Lines changed: 119 additions & 56 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to `@testingbot/cli` are documented here. Releases are publi
77
### Added
88

99
- `testingbot maestro` detects the repository URL, branch, commit and pull request in GitHub Actions, GitLab CI, Bitbucket Pipelines, Azure Pipelines and CircleCI and sends them as run metadata (`repoUrl` is new), so the dashboard can link to the commit and PR on any Git host. On a GitHub pull request the PR's head commit is used, not the merge commit. Explicit flags win.
10+
- `testingbot espresso` and `testingbot xcuitest` take the same CI/CD metadata as `maestro`: `--branch`, `--pr-url`, `-m/--metadata` and the CI environment detection, through one shared code path.
1011

1112
## 1.4.3 - 2026-10-27
1213

‎README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,6 @@ testingbot maestro --app-url "$URL" ./flows --device "Pixel 9"
405405
testingbot maestro build.tar.gz ./flows
406406
```
407407

408-
Inside GitHub Actions, GitLab CI, Bitbucket Pipelines, Azure Pipelines or CircleCI, `testingbot maestro` reads the repository URL, branch, commit and pull request from the CI environment, so the dashboard links the run to them on whichever host the repository lives (GitHub, GitLab, Bitbucket, Azure Repos or self-hosted). Any of `--branch`, `--commit-sha`, `--pull-request-id`, `--pr-url`, `--repo-owner` and `--repo-name` overrides what was detected.
409-
410408
Inside an EAS Build or EAS Workflows job, the run is tagged automatically with the EAS build id, profile and platform, and `EAS_BUILD_GIT_COMMIT_HASH` is used as the commit SHA unless `--commit-sha` is given. `testingbot upload <url>` accepts URLs as well.
411409

412410
### Status, artifacts and list
@@ -687,6 +685,10 @@ testingbot xcuitest app.ipa app-test.zip \
687685

688686
## Common Features
689687

688+
### CI/CD Metadata
689+
690+
`maestro`, `espresso` and `xcuitest` all take `--branch`, `--commit-sha`, `--pull-request-id`, `--pr-url`, `--repo-owner`, `--repo-name` and `-m, --metadata <KEY=VALUE>` (repeatable). Inside GitHub Actions, GitLab CI, Bitbucket Pipelines, Azure Pipelines or CircleCI, the repository URL, branch, commit and pull request are read from the CI environment, so the dashboard links the run to them on whichever host the repository lives (GitHub, GitLab, Bitbucket, Azure Repos or self-hosted). Any flag overrides what was detected.
691+
690692
### Real-time Progress
691693

692694
By default, the CLI shows real-time progress updates including:

‎src/cli.ts‎

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,49 @@ function buildRunMetadata(fields: RunMetadata): RunMetadata | undefined {
220220
: undefined;
221221
}
222222

223+
interface CiMetadataArgs {
224+
branch?: string;
225+
commitSha?: string;
226+
pullRequestId?: string;
227+
prUrl?: string;
228+
repoName?: string;
229+
repoOwner?: string;
230+
metadata?: string[];
231+
checkName?: string;
232+
}
233+
234+
/**
235+
* The run metadata every run command sends: the CI/CD flags, merged over what
236+
* was detected from the CI environment (and EAS Build, for Maestro), plus the
237+
* free-form --metadata pairs. Flags win over anything detected.
238+
*/
239+
function ciRunMetadata(
240+
args: CiMetadataArgs,
241+
detected: { commitSha?: string; custom?: Record<string, string> } = {},
242+
): RunMetadata | undefined {
243+
const ci = ciRepoMetadata(process.env);
244+
// The repository is one unit: an explicit --repo-owner / --repo-name
245+
// replaces everything detected about it, and an explicit PR id drops
246+
// the detected PR URL, which would point at a different PR.
247+
const explicitRepo = !!(args.repoOwner || args.repoName);
248+
const custom = {
249+
...detected.custom,
250+
...(parseKeyValues(args.metadata, '--metadata') ?? {}),
251+
...(args.checkName?.trim() && { checkName: args.checkName.trim() }),
252+
};
253+
return buildRunMetadata({
254+
commitSha: args.commitSha ?? detected.commitSha ?? ci.commitSha,
255+
pullRequestId: args.pullRequestId ?? ci.pullRequestId,
256+
pullRequestUrl:
257+
args.prUrl ?? (args.pullRequestId ? undefined : ci.pullRequestUrl),
258+
repoUrl: explicitRepo ? undefined : ci.repoUrl,
259+
repoName: explicitRepo ? args.repoName : ci.repoName,
260+
repoOwner: explicitRepo ? args.repoOwner : ci.repoOwner,
261+
branch: args.branch ?? ci.branch,
262+
custom: Object.keys(custom).length > 0 ? custom : undefined,
263+
});
264+
}
265+
223266
/** Android API level → OS version, for `--device-os android-34`. */
224267
const ANDROID_API_TO_VERSION: Record<string, string> = {
225268
'26': '8.0',
@@ -470,8 +513,18 @@ program
470513
'--report-output-dir <path>',
471514
'Directory to save test reports (required when --report is used).',
472515
)
473-
// CI/CD metadata
516+
// CI/CD metadata (also detected from the CI environment)
517+
.option('--branch <name>', 'Git branch this upload was built from.')
474518
.option('--commit-sha <sha>', 'The commit SHA of this upload.')
519+
.option(
520+
'--pr-url <url>',
521+
'URL of the pull request this upload originated from.',
522+
)
523+
.option(
524+
'-m, --metadata <KEY=VALUE>',
525+
'Arbitrary metadata to attach to the run, shown in the dashboard (repeatable).',
526+
collectRepeatable,
527+
)
475528
.option(
476529
'--pull-request-id <id>',
477530
'The ID of the pull request this upload originated from.',
@@ -529,15 +582,7 @@ program
529582
);
530583
}
531584

532-
const metadata =
533-
args.commitSha || args.pullRequestId || args.repoName || args.repoOwner
534-
? {
535-
commitSha: args.commitSha,
536-
pullRequestId: args.pullRequestId,
537-
repoName: args.repoName,
538-
repoOwner: args.repoOwner,
539-
}
540-
: undefined;
585+
const metadata = ciRunMetadata(args);
541586

542587
const options = new EspressoOptions(app, testApp, args.device, {
543588
version: args.platformVersion,
@@ -931,28 +976,7 @@ program
931976
if (Array.isArray(args.env)) args.env.length = 0;
932977
if (Array.isArray(args.secretEnv)) args.secretEnv.length = 0;
933978

934-
const eas = easBuildMetadata(process.env);
935-
const ci = ciRepoMetadata(process.env);
936-
// The repository is one unit: an explicit --repo-owner / --repo-name
937-
// replaces everything detected about it, and an explicit PR id drops
938-
// the detected PR URL, which would point at a different PR.
939-
const explicitRepo = !!(args.repoOwner || args.repoName);
940-
const custom = {
941-
...eas.custom,
942-
...(parseKeyValues(args.metadata, '--metadata') ?? {}),
943-
...(args.checkName?.trim() && { checkName: args.checkName.trim() }),
944-
};
945-
const metadata = buildRunMetadata({
946-
commitSha: args.commitSha ?? eas.commitSha ?? ci.commitSha,
947-
pullRequestId: args.pullRequestId ?? ci.pullRequestId,
948-
pullRequestUrl:
949-
args.prUrl ?? (args.pullRequestId ? undefined : ci.pullRequestUrl),
950-
repoUrl: explicitRepo ? undefined : ci.repoUrl,
951-
repoName: explicitRepo ? args.repoName : ci.repoName,
952-
repoOwner: explicitRepo ? args.repoOwner : ci.repoOwner,
953-
branch: args.branch ?? ci.branch,
954-
custom: Object.keys(custom).length > 0 ? custom : undefined,
955-
});
979+
const metadata = ciRunMetadata(args, easBuildMetadata(process.env));
956980

957981
const options = new MaestroOptions(app, flows, args.device, {
958982
includeTags: args.includeTags,
@@ -1080,8 +1104,18 @@ program
10801104
'--report-output-dir <path>',
10811105
'Directory to save test reports (required when --report is used).',
10821106
)
1083-
// CI/CD metadata
1107+
// CI/CD metadata (also detected from the CI environment)
1108+
.option('--branch <name>', 'Git branch this upload was built from.')
10841109
.option('--commit-sha <sha>', 'The commit SHA of this upload.')
1110+
.option(
1111+
'--pr-url <url>',
1112+
'URL of the pull request this upload originated from.',
1113+
)
1114+
.option(
1115+
'-m, --metadata <KEY=VALUE>',
1116+
'Arbitrary metadata to attach to the run, shown in the dashboard (repeatable).',
1117+
collectRepeatable,
1118+
)
10851119
.option(
10861120
'--pull-request-id <id>',
10871121
'The ID of the pull request this upload originated from.',
@@ -1139,15 +1173,7 @@ program
11391173
);
11401174
}
11411175

1142-
const metadata =
1143-
args.commitSha || args.pullRequestId || args.repoName || args.repoOwner
1144-
? {
1145-
commitSha: args.commitSha,
1146-
pullRequestId: args.pullRequestId,
1147-
repoName: args.repoName,
1148-
repoOwner: args.repoOwner,
1149-
}
1150-
: undefined;
1176+
const metadata = ciRunMetadata(args);
11511177

11521178
const options = new XCUITestOptions(app, testApp, args.device, {
11531179
version: args.platformVersion,

‎src/models/espresso_options.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { randomUUID } from 'node:crypto';
22
import TestingBotError from './testingbot_error';
3+
import type { RunMetadata } from './maestro_options';
34

45
export type TestSize = 'small' | 'medium' | 'large';
56
export type ReportFormat = 'html' | 'junit';
67
export type ThrottleNetwork = '4G' | '3G' | 'Edge' | 'airplane';
78

8-
export interface RunMetadata {
9-
commitSha?: string;
10-
pullRequestId?: string;
11-
repoName?: string;
12-
repoOwner?: string;
13-
}
9+
// One metadata shape for every run command (CI fields + --metadata pairs).
10+
export type { RunMetadata };
1411

1512
export interface CustomNetworkProfile {
1613
uploadSpeed: number; // kbps

‎src/models/xcuitest_options.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { randomUUID } from 'node:crypto';
22
import TestingBotError from './testingbot_error';
3+
import type { RunMetadata } from './maestro_options';
34

45
export type Orientation = 'PORTRAIT' | 'LANDSCAPE';
56
export type ReportFormat = 'html' | 'junit';
67
export type ThrottleNetwork = '4G' | '3G' | 'Edge' | 'airplane';
78

8-
export interface RunMetadata {
9-
commitSha?: string;
10-
pullRequestId?: string;
11-
repoName?: string;
12-
repoOwner?: string;
13-
}
9+
// One metadata shape for every run command (CI fields + --metadata pairs).
10+
export type { RunMetadata };
1411

1512
export interface CustomNetworkProfile {
1613
uploadSpeed: number; // kbps

‎tests/cli.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,46 @@ describe('TestingBotCTL CLI', () => {
717717
});
718718
});
719719

720+
test.each([
721+
['espresso', ['app.apk', 'test.apk'], Espresso],
722+
['xcuitest', ['app.ipa', 'test.zip'], XCUITest],
723+
])(
724+
'%s takes --branch, --pr-url, --metadata and the detected CI repository',
725+
async (command, files, provider) => {
726+
mockGetCredentials.mockResolvedValue({ apiKey: 'test-api-key' });
727+
(ciRepoMetadata as jest.Mock).mockReturnValueOnce({
728+
repoUrl: 'https://dev.azure.com/acme/mobile/_git/app',
729+
commitSha: 'b'.repeat(40),
730+
branch: 'develop',
731+
});
732+
733+
await program.parseAsync([
734+
'node',
735+
'cli',
736+
command,
737+
...files,
738+
'--branch',
739+
'release',
740+
'--pr-url',
741+
'https://dev.azure.com/acme/mobile/_git/app/pullrequest/7',
742+
'-m',
743+
'team=mobile',
744+
]);
745+
746+
expect(
747+
lastConstructorOptions<{ metadata?: Record<string, unknown> }>(provider)
748+
.metadata,
749+
).toEqual({
750+
repoUrl: 'https://dev.azure.com/acme/mobile/_git/app',
751+
commitSha: 'b'.repeat(40),
752+
branch: 'release',
753+
pullRequestUrl:
754+
'https://dev.azure.com/acme/mobile/_git/app/pullrequest/7',
755+
custom: { team: 'mobile' },
756+
});
757+
},
758+
);
759+
720760
test('xcuitest command should call xcuitest.run() with valid options', async () => {
721761
mockGetCredentials.mockResolvedValue({ apiKey: 'test-api-key' });
722762

0 commit comments

Comments
 (0)