@@ -13,7 +13,7 @@ permissions:
1313
1414jobs :
1515 build :
16- runs-on : macos-14 # iOS 17 시뮬레이터 런타임 포함
16+ runs-on : macos-latest
1717 steps :
1818 - uses : actions/checkout@v4
1919
@@ -28,87 +28,43 @@ jobs:
2828 run : |
2929 set -euo pipefail
3030
31- # iPhone 시뮬레이터가 존재하는 런타임 중 가장 낮은 버전 선택 (패치 버전 포함)
32- chosen=$(python3 - <<'PY'
33- import json, re, subprocess
34-
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)
40-
41- devices = json.loads(subprocess.check_output(["xcrun", "simctl", "list", "devices", "available", "-j"], text=True)).get("devices", {})
42-
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
52-
53- for v in versions:
54- if has_iphone(v):
55- print(v)
56- raise SystemExit(0)
57-
58- raise SystemExit(1)
59- PY
60- )
61-
62- if [ -z "${chosen:-}" ]; then
63- echo "No iPhone simulator runtimes detected." >&2
31+ # simctl 텍스트 헤더 버전 기준으로 최신 iOS 버전의 iPhone 선택
32+ RESULT=$(xcrun simctl list devices | awk '
33+ /^== iOS / {ver=$3; next}
34+ /\(unavailable\)/ {next}
35+ ver && $0 ~ /iPhone/ {
36+ line=$0
37+ sub(/^[[:space:]]+/, "", line)
38+ sub(/ \(.*/, "", line)
39+ print ver "|" line
40+ }
41+ ' | sort -t'|' -k1,1Vr | head -n 1)
42+
43+ if [ -z "${RESULT:-}" ]; then
44+ echo "No iPhone simulator devices detected." >&2
6445 exit 1
6546 fi
6647
67- echo "Chosen iOS runtime version (iPhone): $chosen "
48+ IFS='|' read -r IOS_VER DEVICE_NAME <<< "$RESULT "
6849
69- echo "ios_version=$chosen" >> "$GITHUB_OUTPUT"
50+ echo "Chosen iOS runtime version (iPhone): $IOS_VER"
51+ echo "Chosen simulator: $DEVICE_NAME"
52+
53+ echo "ios_version=$IOS_VER" >> "$GITHUB_OUTPUT"
54+ echo "device_name=$DEVICE_NAME" >> "$GITHUB_OUTPUT"
7055
7156 - name : Build
7257 shell : bash
7358 run : |
7459 set -euo pipefail
7560 set -x
7661 IOS_VER="${{ steps.pick_ios.outputs.ios_version }}"
77- export IOS_VER
62+ DEVICE_NAME="${{ steps.pick_ios.outputs.device_name }}"
7863
7964 xcodebuild -version
8065
8166 echo "Using scheme: $SCHEME"
8267
83- # 선택된 iOS 런타임에서 'iPhone'이 포함된 첫 번째 시뮬레이터 이름 선택 (JSON 파싱)
84- DEVICE_INFO=$(python3 - <<'PY'
85- import json, os, subprocess, sys
86-
87- ios_ver = os.environ['IOS_VER']
88- prefix = f"com.apple.CoreSimulator.SimRuntime.iOS-{ios_ver.replace('.', '-') }"
89- data = subprocess.check_output(["xcrun", "simctl", "list", "devices", "available", "-j"], text=True)
90- j = json.loads(data)
91- for runtime, devices in j.get("devices", {}).items():
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)
99- sys.exit(1)
100- PY
101- )
102-
103- IFS='|' read -r DEVICE_NAME DEVICE_OS <<< "$DEVICE_INFO"
104- IOS_VER="$DEVICE_OS"
105- export IOS_VER
106-
107- if [ -z "${DEVICE_NAME:-}" ] || [ -z "${IOS_VER:-}" ]; then
108- echo "No available simulator device found for iOS ${IOS_VER}." >&2
109- exit 1
110- fi
111-
11268 echo "Using simulator: $DEVICE_NAME (iOS ${IOS_VER})"
11369
11470 # 예시: 시뮬레이터 대상으로 빌드/테스트 시 destination에서 OS 지정
0 commit comments