Skip to content

Commit 4e7ff25

Browse files
committed
Fix CI simulator destination selection
1 parent 808b85d commit 4e7ff25

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,39 @@ jobs:
3131
SCHEME=$(swift package dump-package | python3 -c "import json,sys; print(json.load(sys.stdin)['name'])")
3232
echo "SCHEME=$SCHEME" >> "$GITHUB_ENV"
3333
34-
# Find the latest available iPhone simulator name (name-based, more robust than UDID)
35-
SIM_NAME=$(xcrun simctl list devices available --json | python3 -c "
34+
# Find the latest available iPhone simulator and use its UDID so the
35+
# destination cannot resolve to a different runtime with the same name.
36+
SIM_INFO=$(xcrun simctl list devices available --json | python3 -c "
3637
import json, sys
3738
devs = json.load(sys.stdin)['devices']
3839
iphones = [
39-
(rt, d['name'])
40+
(rt, d['name'], d['udid'])
4041
for rt, dl in devs.items()
4142
for d in dl
4243
if 'iOS' in rt and 'iPhone' in d['name'] and d.get('isAvailable', True)
4344
]
4445
iphones.sort(reverse=True)
45-
print(iphones[0][1] if iphones else 'iPhone 16')
46+
if not iphones:
47+
raise SystemExit('No available iPhone simulator found')
48+
rt, name, udid = iphones[0]
49+
print(f'{udid}|{name}|{rt}')
4650
")
51+
SIM_ID="${SIM_INFO%%|*}"
52+
SIM_REST="${SIM_INFO#*|}"
53+
SIM_NAME="${SIM_REST%%|*}"
54+
SIM_RUNTIME="${SIM_REST#*|}"
55+
echo "SIM_ID=$SIM_ID" >> "$GITHUB_ENV"
4756
echo "SIM_NAME=$SIM_NAME" >> "$GITHUB_ENV"
57+
echo "SIM_RUNTIME=$SIM_RUNTIME" >> "$GITHUB_ENV"
4858
echo "Detected scheme: $SCHEME"
49-
echo "Detected simulator: $SIM_NAME"
59+
echo "Detected simulator: $SIM_NAME ($SIM_RUNTIME, $SIM_ID)"
5060
5161
- name: Build
5262
id: build
5363
run: |
5464
xcodebuild build \
5565
-scheme "$SCHEME" \
56-
-destination "platform=iOS Simulator,name=$SIM_NAME" \
66+
-destination "platform=iOS Simulator,id=$SIM_ID" \
5767
-sdk iphonesimulator \
5868
2>&1 | tee build_output.txt; exit "${PIPESTATUS[0]}"
5969
continue-on-error: true
@@ -64,7 +74,7 @@ jobs:
6474
run: |
6575
xcodebuild test \
6676
-scheme "$SCHEME" \
67-
-destination "platform=iOS Simulator,name=$SIM_NAME" \
77+
-destination "platform=iOS Simulator,id=$SIM_ID" \
6878
-sdk iphonesimulator \
6979
-configuration Debug \
7080
-enableCodeCoverage YES \

0 commit comments

Comments
 (0)