Skip to content

Commit 4da8dd0

Browse files
committed
ci(ios): keep tests platform-based and stabilize simulator selection
1 parent 3525a3f commit 4da8dd0

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

.github/workflows/ios.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,38 @@ jobs:
6868
-destination "platform=iOS Simulator,name=iPhone 17 Pro,OS=${IOS_RUNTIME_VERSION}" \
6969
-derivedDataPath "$DERIVED_DATA_PATH"
7070
71+
- name: Resolve and boot iOS test simulator
72+
run: |
73+
set -euo pipefail
74+
RUNTIME_TOKEN="SimRuntime.iOS-${IOS_RUNTIME_VERSION//./-}"
75+
export RUNTIME_TOKEN
76+
UDID="$(
77+
xcrun simctl list devices -j | node -e '
78+
const fs = require("node:fs");
79+
const runtimeToken = process.env.RUNTIME_TOKEN;
80+
const payload = JSON.parse(fs.readFileSync(0, "utf8"));
81+
const entries = Object.entries(payload.devices ?? {});
82+
const iosRuntimes = entries.filter(([runtime]) => runtime.includes("SimRuntime.iOS-"));
83+
const runtimeMatches = iosRuntimes.filter(([runtime]) => runtime.includes(runtimeToken));
84+
const pool = runtimeMatches.length > 0 ? runtimeMatches : iosRuntimes;
85+
const available = pool.flatMap(([runtime, devices]) =>
86+
(devices ?? [])
87+
.filter((device) => device.isAvailable)
88+
.map((device) => ({ ...device, runtime })),
89+
);
90+
const preferred =
91+
available.find((device) => device.state === "Booted" && device.name === "iPhone 17 Pro") ??
92+
available.find((device) => device.name === "iPhone 17 Pro") ??
93+
available.find((device) => device.state === "Booted") ??
94+
available[0];
95+
if (!preferred?.udid) process.exit(1);
96+
process.stdout.write(preferred.udid);
97+
'
98+
)"
99+
xcrun simctl shutdown all || true
100+
xcrun simctl boot "$UDID" || true
101+
xcrun simctl bootstatus "$UDID" -b
102+
71103
- name: Run iOS integration test
72104
run: node --test test/integration/ios.test.ts
73105

test/integration/ios.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import path from 'node:path';
44
import { createIntegrationTestContext, runCliJson } from './test-helpers.ts';
55

66
const session = ['--session', 'ios-test'];
7-
const iosTarget = process.env.AGENT_DEVICE_IOS_TEST_UDID
8-
? ['--udid', process.env.AGENT_DEVICE_IOS_TEST_UDID]
9-
: ['--platform', 'ios'];
7+
const iosTarget = ['--platform', 'ios'];
108

119
test.after(() => {
1210
runCliJson(['close', ...iosTarget, '--json', ...session]);

0 commit comments

Comments
 (0)