From c7022cc139d10fc52c5b20bab09fad9e642e72bb Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 14 Dec 2025 03:39:28 +0000 Subject: [PATCH] ci: pick iOS simulator via simctl json --- .github/workflows/ci.yml | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a7dab7415..360093b51 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -137,12 +137,37 @@ jobs: set -euo pipefail RESULT_BUNDLE_PATH="$RUNNER_TEMP/Clawdis-iOS.xcresult" DEST_ID="$( - ( - xcrun simctl list devices available | - grep -m 1 -E 'iPhone 16 .*\\([0-9A-Fa-f-]{36}\\)' || - xcrun simctl list devices available | - grep -m 1 -E 'iPhone.*\\([0-9A-Fa-f-]{36}\\)' - ) | sed -E 's/.*\\(([0-9A-Fa-f-]{36})\\).*/\\1/' + python3 - <<'PY' + import json + import re + import subprocess + import sys + + data = json.loads(subprocess.check_output(["xcrun", "simctl", "list", "devices", "available", "-j"], text=True)) + runtimes = [] + for runtime in data.get("devices", {}).keys(): + m = re.search(r"\\.iOS-(\\d+)-(\\d+)$", runtime) + if m: + runtimes.append((int(m.group(1)), int(m.group(2)), runtime)) + + runtimes.sort(reverse=True) + + def pick_device(devices): + iphones = [d for d in devices if d.get("isAvailable") and d.get("name", "").startswith("iPhone")] + if not iphones: + return None + prefer = [d for d in iphones if "iPhone 16" in d.get("name", "")] + return (prefer[0] if prefer else iphones[0]).get("udid") + + for _, __, runtime in runtimes: + udid = pick_device(data["devices"].get(runtime, [])) + if udid: + print(udid) + sys.exit(0) + + print("No available iPhone simulators found.", file=sys.stderr) + sys.exit(1) + PY )" echo "Using iOS Simulator id: $DEST_ID" xcodebuild test \