Skip to content

Commit 055e6b9

Browse files
committed
build: resolve iOS runner from xctestrun metadata
1 parent 00597a9 commit 055e6b9

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

scripts/package-ios-simulator-runner.sh

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ OUTPUT_DIR="$3"
1212

1313
DERIVED_PATH="${AGENT_DEVICE_IOS_RUNNER_DERIVED_PATH:-$HOME/.agent-device/ios-runner/derived}"
1414
PRODUCTS_DIR="$DERIVED_PATH/Build/Products"
15-
EXPECTED_RUNNER_BUNDLE_ID="${AGENT_DEVICE_IOS_RUNNER_RELEASE_BUNDLE_ID:-com.callstack.agentdevice.runner.uitests.xctrunner}"
15+
EXPECTED_RUNNER_BUNDLE_ID="${AGENT_DEVICE_IOS_RUNNER_RELEASE_BUNDLE_ID:-}"
1616
ARCHIVE_BASENAME="agent-device-ios-runner-$VERSION.app.tar.gz"
1717
CHECKSUM_BASENAME="$ARCHIVE_BASENAME.sha256"
1818
MANIFEST_BASENAME="agent-device-ios-runner-$VERSION.manifest.json"
@@ -36,19 +36,36 @@ write_github_output() {
3636
fi
3737
}
3838

39-
resolve_runner_app_path() {
40-
find "$PRODUCTS_DIR" -type d -name '*.app' | sort | while IFS= read -r app_path; do
41-
bundle_id="$(read_plist_value "$app_path/Info.plist" CFBundleIdentifier)"
42-
if [ "$bundle_id" = "$EXPECTED_RUNNER_BUNDLE_ID" ]; then
43-
printf '%s\n' "$app_path"
44-
exit 0
45-
fi
46-
done
39+
resolve_runner_xctestrun_path() {
40+
find "$PRODUCTS_DIR" -maxdepth 1 -name '*iphonesimulator*.xctestrun' | sort | head -n 1
4741
}
4842

49-
RUNNER_APP_PATH="$(resolve_runner_app_path)"
50-
if [ -z "$RUNNER_APP_PATH" ]; then
51-
echo "Unable to locate simulator runner app with bundle id $EXPECTED_RUNNER_BUNDLE_ID under $PRODUCTS_DIR" >&2
43+
resolve_xctestrun_runner_app_path() {
44+
xctestrun_path="$1"
45+
test_host_path="$(
46+
read_plist_value "$xctestrun_path" \
47+
'TestConfigurations:0:TestTargets:0:TestHostPath'
48+
)"
49+
50+
case "$test_host_path" in
51+
__TESTROOT__/*)
52+
printf '%s\n' "$PRODUCTS_DIR/${test_host_path#__TESTROOT__/}"
53+
;;
54+
*)
55+
printf '%s\n' "$test_host_path"
56+
;;
57+
esac
58+
}
59+
60+
RUNNER_XCTESTRUN_PATH="$(resolve_runner_xctestrun_path)"
61+
if [ -z "$RUNNER_XCTESTRUN_PATH" ]; then
62+
echo "Unable to locate iphonesimulator xctestrun under $PRODUCTS_DIR" >&2
63+
exit 1
64+
fi
65+
66+
RUNNER_APP_PATH="$(resolve_xctestrun_runner_app_path "$RUNNER_XCTESTRUN_PATH")"
67+
if [ ! -d "$RUNNER_APP_PATH" ]; then
68+
echo "Unable to locate simulator runner app referenced by $RUNNER_XCTESTRUN_PATH" >&2
5269
exit 1
5370
fi
5471

@@ -69,6 +86,10 @@ APP_NAME="$(read_plist_value "$RUNNER_APP_PATH/Info.plist" CFBundleName)"
6986
if [ -z "$APP_NAME" ]; then
7087
APP_NAME="$(basename "$RUNNER_APP_PATH" .app)"
7188
fi
89+
if [ -n "$EXPECTED_RUNNER_BUNDLE_ID" ] && [ "$RUNNER_BUNDLE_ID" != "$EXPECTED_RUNNER_BUNDLE_ID" ]; then
90+
echo "Runner bundle id $RUNNER_BUNDLE_ID did not match expected $EXPECTED_RUNNER_BUNDLE_ID" >&2
91+
exit 1
92+
fi
7293

7394
ditto "$RUNNER_APP_PATH" "$STAGED_APP_PATH"
7495
rm -f "$ARCHIVE_PATH"
@@ -106,6 +127,7 @@ fi
106127
} > "$MANIFEST_PATH"
107128

108129
write_github_output "runner_app_path=$RUNNER_APP_PATH"
130+
write_github_output "xctestrun_path=$RUNNER_XCTESTRUN_PATH"
109131
write_github_output "archive_path=$ARCHIVE_PATH"
110132
write_github_output "checksum_path=$CHECKSUM_PATH"
111133
write_github_output "manifest_path=$MANIFEST_PATH"

0 commit comments

Comments
 (0)