@@ -28,32 +28,36 @@ jobs:
2828 run : |
2929 set -euo pipefail
3030
31- # iPhone 시뮬레이터가 존재하는 런타임 중 가장 낮은 버전 선택
32- chosen=$(python3 - <<'PY'
33- import json, subprocess
31+ # iPhone 시뮬레이터가 존재하는 런타임 중 가장 낮은 버전 선택 (패치 버전 포함)
32+ chosen=$(python3 - <<'PY'
33+ import json, re, subprocess
3434
35- data = subprocess.check_output(["xcrun", "simctl", "list", "devices", "available", "-j"], text=True)
36- j = json.loads(data)
35+ runtime_text = subprocess.check_output(["xcrun", "simctl", "runtime", "list"], text=True, stderr=subprocess.DEVNULL)
36+ versions = re.findall(r'iOS ([0-9]+(?:\.[0-9]+)*)', runtime_text)
37+ def ver_key(v):
38+ return [int(x) for x in v.split(".")]
39+ versions = sorted(set(versions), key=ver_key)
3740
38- versions = []
39- for runtime, devices in j.get("devices", {}).items():
40- if "iOS-" not in runtime:
41- continue
42- # iPhone 디바이스가 있는 런타임만
43- if not any(d.get("isAvailable") and "iPhone" in d.get("name", "") for d in devices):
44- continue
45- ver = runtime.split("iOS-")[-1].replace("-", ".")
46- versions.append(ver)
41+ devices = json.loads(subprocess.check_output(["xcrun", "simctl", "list", "devices", "available", "-j"], text=True)).get("devices", {})
4742
48- def ver_key(v):
49- return [int(x) for x in v.split(".")]
43+ def has_iphone(version):
44+ prefix = f"com.apple.CoreSimulator.SimRuntime.iOS-{version.replace('.', '-') }"
45+ for runtime, devs in devices.items():
46+ if not runtime.startswith(prefix):
47+ continue
48+ for d in devs:
49+ if d.get("isAvailable") and "iPhone" in d.get("name", ""):
50+ return True
51+ return False
5052
51- versions = sorted(set(versions), key=ver_key)
52- if not versions:
53- raise SystemExit(1)
54- print(versions[0])
53+ for v in versions:
54+ if has_iphone(v):
55+ print(v)
56+ raise SystemExit(0)
57+
58+ raise SystemExit(1)
5559 PY
56- )
60+ )
5761
5862 if [ -z "${chosen:-}" ]; then
5963 echo "No iPhone simulator runtimes detected." >&2
@@ -79,18 +83,19 @@ jobs:
7983 # 선택된 iOS 런타임에서 'iPhone'이 포함된 첫 번째 시뮬레이터 이름 선택 (JSON 파싱)
8084 DEVICE_INFO=$(python3 - <<'PY'
8185 import json, os, subprocess, sys
86+
8287 ios_ver = os.environ['IOS_VER']
8388 prefix = f"com.apple.CoreSimulator.SimRuntime.iOS-{ios_ver.replace('.', '-') }"
8489 data = subprocess.check_output(["xcrun", "simctl", "list", "devices", "available", "-j"], text=True)
8590 j = json.loads(data)
8691 for runtime, devices in j.get("devices", {}).items():
87- if not runtime.startswith(prefix):
88- continue
89- for d in devices:
90- if d.get("isAvailable") and "iPhone" in d.get("name", ""):
91- os_ver = runtime.split("iOS-")[-1].replace("-", ".")
92- print(f"{d['name']}|{os_ver}")
93- sys.exit(0)
92+ if not runtime.startswith(prefix):
93+ continue
94+ for d in devices:
95+ if d.get("isAvailable") and "iPhone" in d.get("name", ""):
96+ os_ver = runtime.split("iOS-")[-1].replace("-", ".")
97+ print(f"{d['name']}|{os_ver}")
98+ sys.exit(0)
9499 sys.exit(1)
95100 PY
96101 )
0 commit comments