Skip to content

Commit 714434d

Browse files
Refactor: Unify build & test scripts / workflows (#311)
* feat: add shared build and test script * feat: add xcode_run script to wrap test/build * refactor: rename test-samples -> build-samples * feat: make xcode_run more permissive on actions * feat: use xcode_run in other scripts * refactor: rename test-sdk -> test-package * feat: add xcbeautify to dev.yml * feat: add dev commands for building & testing * refactor: remove test_package script * fix: cleanup reference to test_package
1 parent 9e66dce commit 714434d

File tree

8 files changed

+93
-22
lines changed

8 files changed

+93
-22
lines changed

.github/workflows/test-samples.yml renamed to .github/workflows/build-samples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ jobs:
1111
call-workflow-passing-data:
1212
uses: ./.github/workflows/test-workflow.yml
1313
with:
14-
test-path: ./Scripts/test_samples
14+
test-path: ./Scripts/build_samples

.github/workflows/test-sdk.yml renamed to .github/workflows/test-package.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run SDK Tests
1+
name: Run Package Tests
22

33
on:
44
push:
@@ -11,4 +11,4 @@ jobs:
1111
call-workflow-passing-data:
1212
uses: ./.github/workflows/test-workflow.yml
1313
with:
14-
test-path: ./Scripts/test_package
14+
test-path: ./scripts/xcode_run test ShopifyCheckoutSheetKit

.github/workflows/test-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
xcrun simctl list runtimes
2121
xcrun simctl list devicetypes
2222
xcrun simctl delete all
23-
CURRENT_SIMULATOR_UUID=$(xcrun simctl create TestDevice "iPhone 14")
23+
CURRENT_SIMULATOR_UUID=$(xcrun simctl create TestDevice "iPhone 16")
2424
echo "CURRENT_SIMULATOR_UUID=$CURRENT_SIMULATOR_UUID" >> $GITHUB_ENV
2525
2626
- name: Run Tests

Scripts/test_samples renamed to Scripts/build_samples

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
set -ex
44
set -eo pipefail
55

6-
if [[ -n $CURRENT_SIMULATOR_UUID ]]; then
7-
dest="id=$CURRENT_SIMULATOR_UUID"
8-
else
9-
dest="platform=iOS Simulator,name=iPhone 14"
10-
fi
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
117

128
cd Samples/
139

@@ -29,7 +25,7 @@ build_app() {
2925
echo "Entitlements file already exists for $1 project."
3026
fi
3127

32-
xcodebuild clean build -scheme $1 -sdk iphonesimulator -destination "$dest" -skipPackagePluginValidation | xcpretty -c
28+
$SCRIPT_DIR/xcode_run "clean build" $1
3329
}
3430

3531
build_app MobileBuyIntegration

Scripts/get_device_id

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# Check if device type was provided
4+
if [ $# -lt 1 ]; then
5+
echo "Usage: $0 <device_type> [model_keywords...]"
6+
echo "Example: $0 iPhone 16"
7+
echo "Example: $0 iPad Pro"
8+
echo "Example: $0 iPad Pro 11-inch"
9+
exit 1
10+
fi
11+
12+
DEVICE_TYPE="$1"
13+
shift
14+
15+
# Join the remaining arguments to build a search pattern
16+
SEARCH=""
17+
if [ $# -gt 0 ]; then
18+
SEARCH="$*"
19+
fi
20+
21+
# List all devices and filter
22+
if [ -n "$SEARCH" ]; then
23+
# Create a search string with spaces to match exact model (case insensitive)
24+
DEVICES=$(xcrun simctl list devices | grep -i "$DEVICE_TYPE")
25+
26+
# Use grep to find lines containing all search terms (case insensitive)
27+
for term in $SEARCH; do
28+
DEVICES=$(echo "$DEVICES" | grep -i "$term")
29+
done
30+
31+
# Get the first matching device
32+
DEVICE_ID=$(echo "$DEVICES" | head -1 | sed -E 's/.*\(([A-Z0-9-]+)\).*/\1/')
33+
else
34+
# If no model specified, get the first device of the type (case insensitive)
35+
DEVICE_ID=$(xcrun simctl list devices | grep -i "$DEVICE_TYPE" | head -1 | sed -E 's/.*\(([A-Z0-9-]+)\).*/\1/')
36+
fi
37+
38+
# Check if identifier was found
39+
if [ -z "$DEVICE_ID" ]; then
40+
echo "Device not found: $DEVICE_TYPE $SEARCH"
41+
exit 1
42+
fi
43+
44+
echo "$DEVICE_ID"

Scripts/test_package

Lines changed: 0 additions & 12 deletions
This file was deleted.

Scripts/xcode_run

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
set -e
3+
set -eo pipefail
4+
5+
# Get action from first argument, default to build
6+
ACTION="${1:-build}"
7+
8+
# Get scheme name from second argument, default to ShopifyCheckoutSheetKit
9+
SCHEME="${2:-ShopifyCheckoutSheetKit}"
10+
11+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
13+
# Validate action contains at least one of: build, test, or clean
14+
if [[ "$ACTION" != *"build"* && "$ACTION" != *"test"* && "$ACTION" != *"clean"* ]]; then
15+
echo "Error: ACTION must contain 'build', 'test', or 'clean', got '$ACTION'"
16+
exit 1
17+
fi
18+
19+
if [[ -n $CURRENT_SIMULATOR_UUID ]]; then
20+
dest="id=$CURRENT_SIMULATOR_UUID"
21+
else
22+
# Get a valid iPhone simulator ID using get_device_id.sh
23+
DEVICE_ID=$("$SCRIPT_DIR/get_device_id" "iPhone 16")
24+
dest="id=$DEVICE_ID"
25+
fi
26+
27+
xcodebuild_cmd="xcodebuild $ACTION -scheme $SCHEME -sdk iphonesimulator -destination \"$dest\" -skipPackagePluginValidation"
28+
29+
if command -v xcbeautify >/dev/null 2>&1; then
30+
eval "$xcodebuild_cmd" | xcbeautify
31+
else
32+
eval "$xcodebuild_cmd"
33+
fi

dev.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ packages:
2020
- homebrew:
2121
- swiftlint
2222
- swiftformat
23+
- xcbeautify
2324

2425
commands:
2526
lint:
@@ -29,3 +30,12 @@ commands:
2930
fix:
3031
desc: Autofix Format & Lint issues
3132
run: scripts/lint fix
33+
build_package:
34+
desc: Build the Package
35+
run: ./scripts/xcode_run build ShopifyCheckoutSheetKit
36+
build_samples:
37+
desc: Build the Samples
38+
run: ./scripts/build_samples
39+
test_package:
40+
desc: Test the Package
41+
run: ./scripts/xcode_run test ShopifyCheckoutSheetKit

0 commit comments

Comments
 (0)