ci: fix iOS simulator selection indentation
This commit is contained in:
145
.github/workflows/ci.yml
vendored
145
.github/workflows/ci.yml
vendored
@@ -132,84 +132,89 @@ jobs:
|
|||||||
cd apps/ios
|
cd apps/ios
|
||||||
xcodegen generate
|
xcodegen generate
|
||||||
|
|
||||||
- name: iOS tests
|
- name: iOS tests
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
RESULT_BUNDLE_PATH="$RUNNER_TEMP/Clawdis-iOS.xcresult"
|
RESULT_BUNDLE_PATH="$RUNNER_TEMP/Clawdis-iOS.xcresult"
|
||||||
DEST_ID="$(
|
DEST_ID="$(
|
||||||
python3 - <<'PY'
|
python3 - <<'PY'
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
def sh(args: list[str]) -> str:
|
|
||||||
return subprocess.check_output(args, text=True).strip()
|
|
||||||
|
|
||||||
# Prefer an already-created iPhone simulator if it exists.
|
def sh(args: list[str]) -> str:
|
||||||
devices = json.loads(sh(["xcrun", "simctl", "list", "devices", "-j"]))
|
return subprocess.check_output(args, text=True).strip()
|
||||||
candidates: list[tuple[str, str]] = []
|
|
||||||
for runtime, devs in (devices.get("devices") or {}).items():
|
|
||||||
for dev in devs or []:
|
|
||||||
if not dev.get("isAvailable"):
|
|
||||||
continue
|
|
||||||
name = str(dev.get("name") or "")
|
|
||||||
udid = str(dev.get("udid") or "")
|
|
||||||
if not udid or not name.startswith("iPhone"):
|
|
||||||
continue
|
|
||||||
candidates.append((name, udid))
|
|
||||||
|
|
||||||
candidates.sort(key=lambda it: (0 if "iPhone 16" in it[0] else 1, it[0]))
|
# Prefer an already-created iPhone simulator if it exists.
|
||||||
if candidates:
|
devices = json.loads(sh(["xcrun", "simctl", "list", "devices", "-j"]))
|
||||||
print(candidates[0][1])
|
candidates: list[tuple[str, str]] = []
|
||||||
sys.exit(0)
|
for runtime, devs in (devices.get("devices") or {}).items():
|
||||||
|
for dev in devs or []:
|
||||||
|
if not dev.get("isAvailable"):
|
||||||
|
continue
|
||||||
|
name = str(dev.get("name") or "")
|
||||||
|
udid = str(dev.get("udid") or "")
|
||||||
|
if not udid or not name.startswith("iPhone"):
|
||||||
|
continue
|
||||||
|
candidates.append((name, udid))
|
||||||
|
|
||||||
# Otherwise, create one from the newest available iOS runtime.
|
candidates.sort(key=lambda it: (0 if "iPhone 16" in it[0] else 1, it[0]))
|
||||||
runtimes = json.loads(sh(["xcrun", "simctl", "list", "runtimes", "-j"])).get("runtimes") or []
|
if candidates:
|
||||||
ios = [rt for rt in runtimes if rt.get("platform") == "iOS" and rt.get("isAvailable")]
|
print(candidates[0][1])
|
||||||
if not ios:
|
sys.exit(0)
|
||||||
print("No available iOS runtimes found.", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def version_key(rt: dict) -> tuple[int, ...]:
|
# Otherwise, create one from the newest available iOS runtime.
|
||||||
parts = []
|
runtimes = json.loads(sh(["xcrun", "simctl", "list", "runtimes", "-j"])).get("runtimes") or []
|
||||||
for p in str(rt.get("version") or "0").split("."):
|
ios = [rt for rt in runtimes if rt.get("platform") == "iOS" and rt.get("isAvailable")]
|
||||||
try:
|
if not ios:
|
||||||
parts.append(int(p))
|
print("No available iOS runtimes found.", file=sys.stderr)
|
||||||
except ValueError:
|
sys.exit(1)
|
||||||
parts.append(0)
|
|
||||||
return tuple(parts)
|
|
||||||
|
|
||||||
ios.sort(key=version_key, reverse=True)
|
def version_key(rt: dict) -> tuple[int, ...]:
|
||||||
runtime = ios[0]
|
parts: list[int] = []
|
||||||
runtime_id = str(runtime.get("identifier") or "")
|
for p in str(rt.get("version") or "0").split("."):
|
||||||
if not runtime_id:
|
try:
|
||||||
print("Missing iOS runtime identifier.", file=sys.stderr)
|
parts.append(int(p))
|
||||||
sys.exit(1)
|
except ValueError:
|
||||||
|
parts.append(0)
|
||||||
|
return tuple(parts)
|
||||||
|
|
||||||
supported = runtime.get("supportedDeviceTypes") or []
|
ios.sort(key=version_key, reverse=True)
|
||||||
iphones = [dt for dt in supported if dt.get("productFamily") == "iPhone"]
|
runtime = ios[0]
|
||||||
if not iphones:
|
runtime_id = str(runtime.get("identifier") or "")
|
||||||
print("No iPhone device types for iOS runtime.", file=sys.stderr)
|
if not runtime_id:
|
||||||
sys.exit(1)
|
print("Missing iOS runtime identifier.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
iphones.sort(key=lambda dt: (0 if "iPhone 16" in str(dt.get("name") or "") else 1, str(dt.get("name") or "")))
|
supported = runtime.get("supportedDeviceTypes") or []
|
||||||
device_type_id = str(iphones[0].get("identifier") or "")
|
iphones = [dt for dt in supported if dt.get("productFamily") == "iPhone"]
|
||||||
if not device_type_id:
|
if not iphones:
|
||||||
print("Missing iPhone device type identifier.", file=sys.stderr)
|
print("No iPhone device types for iOS runtime.", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
sim_name = f"CI iPhone {uuid.uuid4().hex[:8]}"
|
iphones.sort(
|
||||||
udid = sh(["xcrun", "simctl", "create", sim_name, device_type_id, runtime_id])
|
key=lambda dt: (
|
||||||
if not udid:
|
0 if "iPhone 16" in str(dt.get("name") or "") else 1,
|
||||||
print("Failed to create iPhone simulator.", file=sys.stderr)
|
str(dt.get("name") or ""),
|
||||||
sys.exit(1)
|
)
|
||||||
print(udid)
|
)
|
||||||
PY
|
device_type_id = str(iphones[0].get("identifier") or "")
|
||||||
)"
|
if not device_type_id:
|
||||||
echo "Using iOS Simulator id: $DEST_ID"
|
print("Missing iPhone device type identifier.", file=sys.stderr)
|
||||||
xcodebuild test \
|
sys.exit(1)
|
||||||
-project apps/ios/Clawdis.xcodeproj \
|
|
||||||
|
sim_name = f"CI iPhone {uuid.uuid4().hex[:8]}"
|
||||||
|
udid = sh(["xcrun", "simctl", "create", sim_name, device_type_id, runtime_id])
|
||||||
|
if not udid:
|
||||||
|
print("Failed to create iPhone simulator.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
print(udid)
|
||||||
|
PY
|
||||||
|
)"
|
||||||
|
echo "Using iOS Simulator id: $DEST_ID"
|
||||||
|
xcodebuild test \
|
||||||
|
-project apps/ios/Clawdis.xcodeproj \
|
||||||
-scheme Clawdis \
|
-scheme Clawdis \
|
||||||
-destination "platform=iOS Simulator,id=$DEST_ID" \
|
-destination "platform=iOS Simulator,id=$DEST_ID" \
|
||||||
-resultBundlePath "$RESULT_BUNDLE_PATH" \
|
-resultBundlePath "$RESULT_BUNDLE_PATH" \
|
||||||
|
|||||||
Reference in New Issue
Block a user