@@ -28,39 +28,55 @@ jobs:
2828 run : |
2929 set -euo pipefail
3030
31- # simctl 텍스트 헤더 버전 기준으로 최신 iOS 버전의 iPhone 선택
32- RESULT=$(python3 - <<'PY'
33- import re, subprocess, sys
34-
35- text = subprocess.check_output(["xcrun", "simctl", "list", "devices"], text=True)
36-
37- current_ver = None
38- candidates = [] # (version_tuple, version_str, device_name)
39-
40- def ver_key(v):
41- return tuple(int(x) for x in v.split('.'))
42-
43- for line in text.splitlines():
44- header = re.match(r"^-- iOS ([0-9]+(?:\.[0-9]+)*) --$", line.strip())
45- if header:
46- current_ver = header.group(1)
47- continue
48- if "(unavailable)" in line:
49- continue
50- if current_ver and "iPhone" in line:
51- name = line.strip()
52- name = re.sub(r" \(.*", "", name)
53- candidates.append((ver_key(current_ver), current_ver, name))
54-
55- if not candidates:
56- print("No iPhone candidates found", file=sys.stderr)
31+ # macOS 메인 버전에 맞는 iOS 버전 중 최신 버전의 iPhone 선택
32+ RESULT=$(python3 - <<'PY'
33+ import re, subprocess, sys
34+
35+ mac_ver = subprocess.check_output(["sw_vers", "-productVersion"], text=True).strip()
36+ mac_major = mac_ver.split('.')[0]
37+
38+ text = subprocess.check_output(["xcrun", "simctl", "list", "devices"], text=True)
39+ lines = text.splitlines()
40+
41+ def ver_key(v):
42+ return tuple(int(x) for x in v.split('.'))
43+
44+ # 1) 최신 iOS 버전(해당 mac 메이저) 찾기
45+ latest_ver = None
46+ for line in lines:
47+ header = re.match(r"^-- iOS ([0-9]+(?:\.[0-9]+)*) --$", line.strip())
48+ if not header:
49+ continue
50+ ver = header.group(1)
51+ if not ver.startswith(f"{mac_major}."):
52+ continue
53+ if latest_ver is None or ver_key(ver) > ver_key(latest_ver):
54+ latest_ver = ver
55+
56+ if latest_ver is None:
57+ print(f"No iOS versions found for macOS major {mac_major}", file=sys.stderr)
58+ sys.exit(1)
59+
60+ # 2) 해당 버전 섹션에서 첫 iPhone 찾고 즉시 종료
61+ current_ver = None
62+ for line in lines:
63+ header = re.match(r"^-- iOS ([0-9]+(?:\.[0-9]+)*) --$", line.strip())
64+ if header:
65+ current_ver = header.group(1)
66+ continue
67+ if current_ver != latest_ver:
68+ continue
69+ if "(unavailable)" in line:
70+ continue
71+ if "iPhone" in line:
72+ name = line.strip()
73+ print(f"{latest_ver}|{name}")
74+ sys.exit(0)
75+
76+ print(f"No iPhone candidates found for iOS {latest_ver}", file=sys.stderr)
5777 sys.exit(1)
58-
59- candidates.sort(reverse=True)
60- _, ver, name = candidates[0]
61- print(f"{ver}|{name}")
6278 PY
63- )
79+ )
6480
6581 if [ -z "${RESULT:-}" ]; then
6682 echo "No iPhone simulator devices detected." >&2
0 commit comments