Skip to content

Commit 3a9ea09

Browse files
authored
Merge pull request #352 from immutable/feature/sdk-3435-ios-build
[SDK-3435] build and test ios
2 parents b459f61 + 28b115b commit 3a9ea09

File tree

4 files changed

+102
-4
lines changed

4 files changed

+102
-4
lines changed

.github/workflows/ui-tests.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ jobs:
4747
with:
4848
targetPlatform: ${{ matrix.targetPlatform }}
4949
projectPath: sample
50+
buildMethod: ${{ matrix.buildMethod }}
51+
customParameters: -logFile logFile.log -quit -batchmode
5052
- name: List build directory
5153
run: ls -R ./
5254
- name: Upload artifact
@@ -70,9 +72,6 @@ jobs:
7072
- targetPlatform: Android
7173
runs-on: [ self-hosted, macOS ]
7274
test_script: browserstack-sdk pytest -s ./test/test_android.py --browserstack.config "browserstack.android.yml"
73-
- targetPlatform: iOS
74-
runs-on: [ self-hosted, macOS ]
75-
test_script: browserstack-sdk pytest -s ./test/test_ios.py --browserstack.config "browserstack.ios.yml"
7675
concurrency:
7776
group: test-${{ matrix.targetPlatform }}
7877
runs-on: ${{ matrix.runs-on }}
@@ -98,4 +97,26 @@ jobs:
9897
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
9998
working-directory: sample/Tests
10099
run: ${{ matrix.test_script }}
100+
test-ios:
101+
name: Run iOS UI tests 🧪
102+
runs-on: [ self-hosted, macOS ]
103+
steps:
104+
- uses: actions/checkout@v3
105+
with:
106+
lfs: true
107+
- name: build iOS app
108+
working-directory: sample
109+
run: ./build_ios.sh
110+
- uses: actions/setup-python@v4
111+
with:
112+
python-version: "3.10"
113+
- name: Install dependencies
114+
run: pip install -r "sample/Tests/requirements.txt"
115+
- name: Run UI tests
116+
env:
117+
MAILSLURP_API_KEY: ${{ secrets.MAILSLURP_API_KEY }}
118+
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
119+
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
120+
working-directory: sample/Tests
121+
run: browserstack-sdk pytest -s ./test/test_ios.py --browserstack.config "browserstack.ios.yml"
101122

sample/Tests/Payload.ipa

-34.5 MB
Binary file not shown.

sample/Tests/browserstack.ios.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ source: pytest-browserstack:sample-sdk:v1.0
2626
# Set `app` to define the app that is to be used for testing.
2727
# It can either take the id of any uploaded app or the path of the app directly.
2828
#app: ./WikipediaSample.apk
29-
app: ./Payload.ipa #For running local tests
29+
app: ../build/output/iOS/IPA/Payload.ipa #For running local tests
3030

3131
# =======================================
3232
# Platforms (Browsers / Devices to test)

sample/build_ios.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
PATH_UNITY="/Applications/Unity/Unity.app/Contents/MacOS/Unity"
4+
PATH_TO_UNITY_SDK_SAMPLE_APP="./"
5+
BUILD_METHOD="MobileBuilder.BuildForAltTester"
6+
APPLE_TEAM_ID=""
7+
8+
# Define the build paths
9+
BUILD_XCODE_PATH="$(pwd)/build/output/iOS/Xcode"
10+
BUILD_ARCHIVE_PATH="$(pwd)/build/output/iOS/Archive"
11+
BUILD_IPA_PATH="$(pwd)/build/output/iOS/IPA"
12+
13+
# Function to clear a directory
14+
clear_directory() {
15+
local dir_path=$1
16+
if [ -d "$dir_path" ]; then
17+
echo "Clearing contents of $dir_path."
18+
rm -rf "$dir_path"/*
19+
else
20+
echo "Directory not found at $dir_path"
21+
fi
22+
}
23+
24+
# Clear all specified directories
25+
clear_directory "$BUILD_XCODE_PATH"
26+
clear_directory "$BUILD_ARCHIVE_PATH"
27+
clear_directory "$BUILD_IPA_PATH"
28+
29+
# Unity build command
30+
UNITY_COMMAND="$PATH_UNITY -projectPath \"$PATH_TO_UNITY_SDK_SAMPLE_APP\" -executeMethod $BUILD_METHOD -logFile logFile.log -quit -batchmode --buildPath \"$BUILD_XCODE_PATH\" --platform iOS"
31+
echo "Running command: $UNITY_COMMAND"
32+
33+
# Execute the Unity build command
34+
eval "$UNITY_COMMAND"
35+
36+
# Check if the Unity build command was successful
37+
if [ $? -ne 0 ]; then
38+
echo "Unity build failed. Exiting script."
39+
exit 1
40+
fi
41+
42+
# Build and archive project
43+
xcodebuild -project "$(pwd)/build/output/iOS/Xcode/Unity-iPhone.xcodeproj" \
44+
-scheme Unity-iPhone \
45+
-archivePath "$(pwd)/build/output/iOS/Archive/Unity-iPhone.xcarchive" \
46+
-configuration Release \
47+
DEVELOPMENT_TEAM="$APPLE_TEAM_ID" \
48+
CODE_SIGN_STYLE=Automatic \
49+
archive
50+
51+
# Create ExportOptions.plist with the correct APPLE_TEAM_ID
52+
EXPORT_OPTIONS_PATH="$(pwd)/build/output/iOS/Archive/ExportOptions.plist"
53+
54+
cat <<EOF > "$EXPORT_OPTIONS_PATH"
55+
<?xml version="1.0" encoding="UTF-8"?>
56+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
57+
<plist version="1.0">
58+
<dict>
59+
<key>method</key>
60+
<string>development</string> <!-- Use 'ad-hoc' or 'app-store' as needed -->
61+
<key>teamID</key>
62+
<string>$APPLE_TEAM_ID</string>
63+
<key>signingStyle</key>
64+
<string>automatic</string> <!-- Use automatic signing -->
65+
<key>compileBitcode</key>
66+
<false/>
67+
<key>thinning</key>
68+
<string>&lt;none&gt;</string>
69+
</dict>
70+
</plist>
71+
EOF
72+
73+
# Generate .ipa file
74+
xcodebuild -exportArchive \
75+
-archivePath "$(pwd)/build/output/iOS/Archive/Unity-iPhone.xcarchive" \
76+
-exportPath "$(pwd)/build/output/iOS/IPA" \
77+
-exportOptionsPlist "$EXPORT_OPTIONS_PATH"

0 commit comments

Comments
 (0)