@@ -29,46 +29,17 @@ jobs:
2929 set -euo pipefail
3030
3131 # iPhone 기기들만 모은 뒤, OS 버전(마이너 포함) 오름차순으로 가장 낮은 버전 선택
32- RESULT=$(python3 - <<'PY'
33- import json, re, subprocess, sys
34-
35- data = json.loads(subprocess.check_output(["xcrun", "simctl", "list", "devices", "-j"], text=True))
36- devices = data.get("devices", {})
37-
38- def is_available(d):
39- return d.get("isAvailable") or d.get("availability") == "(available)"
40-
41- def runtime_to_version(runtime_key):
42- # runtime 키가 아니라, 내부에서 OS 버전 문자열을 찾기 위해 fallback 사용
43- # e.g., com.apple.CoreSimulator.SimRuntime.iOS-17-2 -> 17.2
44- m = re.search(r'iOS-([0-9]+(?:-[0-9]+)*)', runtime_key)
45- if not m:
46- return None
47- return m.group(1).replace('-', '.')
48-
49- def ver_key(v):
50- return [int(x) for x in v.split('.')]
51-
52- candidates = []
53- for runtime_key, devs in devices.items():
54- for d in devs:
55- if not is_available(d):
56- continue
57- if "iPhone" not in d.get("name", ""):
58- continue
59- ver = runtime_to_version(runtime_key)
60- if not ver:
61- continue
62- candidates.append((ver_key(ver), ver, d["name"]))
63-
64- if not candidates:
65- sys.exit(1)
66-
67- candidates.sort(key=lambda x: x[0])
68- _, ver, name = candidates[0]
69- print(f"{ver}|{name}")
70- PY
71- )
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)
7243
7344 if [ -z "${RESULT:-}" ]; then
7445 echo "No iPhone simulator devices detected." >&2
0 commit comments