mirror of
https://github.com/callstack/agent-device.git
synced 2026-09-14 20:06:34 +08:00
73 lines
2.9 KiB
YAML
73 lines
2.9 KiB
YAML
name: "Boot iOS Test Simulator"
|
|
description: "Resolve and boot the preferred iOS simulator for replay tests"
|
|
|
|
inputs:
|
|
runtime-version:
|
|
description: "Preferred iOS runtime version"
|
|
required: true
|
|
preferred-device-name:
|
|
description: "Preferred simulator device name"
|
|
required: false
|
|
default: "iPhone 17 Pro"
|
|
boot-timeout-seconds:
|
|
description: "Maximum time to wait for simulator bootstatus"
|
|
required: false
|
|
default: "300"
|
|
|
|
outputs:
|
|
simulator-udid:
|
|
description: "UDID of the booted iOS simulator"
|
|
value: ${{ steps.boot.outputs.simulator-udid }}
|
|
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Resolve and boot iOS test simulator
|
|
id: boot
|
|
run: |
|
|
set -euo pipefail
|
|
RUNTIME_VERSION="${{ inputs.runtime-version }}"
|
|
RUNTIME_TOKEN="SimRuntime.iOS-${RUNTIME_VERSION//./-}"
|
|
export RUNTIME_TOKEN
|
|
export PREFERRED_DEVICE_NAME="${{ inputs.preferred-device-name }}"
|
|
UDID="$(
|
|
xcrun simctl list devices -j | node -e '
|
|
const fs = require("node:fs");
|
|
const runtimeToken = process.env.RUNTIME_TOKEN;
|
|
const preferredDeviceName = process.env.PREFERRED_DEVICE_NAME;
|
|
const payload = JSON.parse(fs.readFileSync(0, "utf8"));
|
|
const entries = Object.entries(payload.devices ?? {});
|
|
const iosRuntimes = entries.filter(([runtime]) => runtime.includes("SimRuntime.iOS-"));
|
|
const runtimeMatches = iosRuntimes.filter(([runtime]) => runtime.includes(runtimeToken));
|
|
const pool = runtimeMatches.length > 0 ? runtimeMatches : iosRuntimes;
|
|
const available = pool.flatMap(([runtime, devices]) =>
|
|
(devices ?? [])
|
|
.filter((device) => device.isAvailable)
|
|
.map((device) => ({ ...device, runtime })),
|
|
);
|
|
const preferred =
|
|
available.find((device) => device.state === "Booted" && device.name === preferredDeviceName) ??
|
|
available.find((device) => device.name === preferredDeviceName) ??
|
|
available.find((device) => device.state === "Booted") ??
|
|
available[0];
|
|
if (!preferred?.udid) process.exit(1);
|
|
console.error(`Selected ${preferred.name} (${preferred.udid}) from ${preferred.runtime}`);
|
|
process.stdout.write(preferred.udid);
|
|
'
|
|
)"
|
|
echo "simulator-udid=$UDID" >> "$GITHUB_OUTPUT"
|
|
xcrun simctl shutdown all || true
|
|
xcrun simctl boot "$UDID" || true
|
|
TIMEOUT_SECONDS="${{ inputs.boot-timeout-seconds }}"
|
|
set +e
|
|
perl -e 'alarm shift; exec @ARGV' "$TIMEOUT_SECONDS" xcrun simctl bootstatus "$UDID" -b
|
|
BOOTSTATUS_EXIT="$?"
|
|
set -e
|
|
if [ "$BOOTSTATUS_EXIT" -eq 142 ]; then
|
|
echo "Timed out waiting ${TIMEOUT_SECONDS}s for simulator $UDID to boot" >&2
|
|
xcrun simctl list devices || true
|
|
exit 1
|
|
fi
|
|
exit "$BOOTSTATUS_EXIT"
|
|
shell: bash
|