@@ -28,18 +28,43 @@ jobs:
2828 run : |
2929 set -euo pipefail
3030
31- # iPhone 기기들만 모은 뒤, OS 버전(마이너 포함) 오름차순으로 가장 낮은 버전 선택
32- # 런타임 키를 쓰지 않고 simctl 텍스트 출력에서 버전/기기명 파싱
33- RESULT=$(xcrun simctl list devices | awk '
34- /^== iOS / {ver=$3; next}
35- /\(unavailable\)/ {next}
36- ver && $0 ~ /iPhone/ {
37- line=$0
38- sub(/^[[:space:]]+/, "", line)
39- sub(/ \(.*/, "", line)
40- print ver "|" line
41- }
42- ' | sort -t'|' -k1,1V | head -n 1)
31+ # 런타임 키를 오름차순으로 정렬하고, iPhone 시뮬레이터가 있으면 선택
32+ RESULT=$(python3 - <<'PY'
33+ import json, subprocess, sys
34+
35+ devices = json.loads(subprocess.check_output(["xcrun", "simctl", "list", "devices", "-j"], text=True)).get("devices", {})
36+
37+ def is_available(d):
38+ return d.get("isAvailable") or d.get("availability") == "(available)"
39+
40+ def parse_runtime(runtime_key):
41+ # com.apple.CoreSimulator.SimRuntime.iOS-17-2 -> ([17, 2], "17.2")
42+ if "iOS-" not in runtime_key:
43+ return None
44+ parts = runtime_key.split("iOS-")[-1].split("-")
45+ try:
46+ nums = [int(p) for p in parts]
47+ except ValueError:
48+ return None
49+ return nums, ".".join(str(n) for n in nums)
50+
51+ runtimes = []
52+ for key in devices.keys():
53+ parsed = parse_runtime(key)
54+ if parsed is None:
55+ continue
56+ nums, ver = parsed
57+ runtimes.append((nums, ver, key))
58+
59+ for _, ver, key in sorted(runtimes, key=lambda x: x[0]):
60+ for d in devices.get(key, []):
61+ if is_available(d) and "iPhone" in d.get("name", ""):
62+ print(f"{ver}|{d['name']}")
63+ sys.exit(0)
64+
65+ sys.exit(1)
66+ PY
67+ )
4368
4469 if [ -z "${RESULT:-}" ]; then
4570 echo "No iPhone simulator devices detected." >&2
0 commit comments