Skip to content

Commit 07bab81

Browse files
committed
ci: allow arbitrary loads when building ios for alttester, fix bundle identifier issue
1 parent 641d3a0 commit 07bab81

File tree

5 files changed

+280
-129
lines changed

5 files changed

+280
-129
lines changed

.github/workflows/ui-tests.yml

Lines changed: 155 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -12,145 +12,174 @@ concurrency:
1212
cancel-in-progress: true
1313

1414
jobs:
15-
build:
16-
name: Build ${{ matrix.targetPlatform }} for AltTester 🛠️
17-
runs-on: ubuntu-latest-8-cores
18-
strategy:
19-
fail-fast: false
20-
matrix:
21-
include:
22-
- targetPlatform: StandaloneOSX
23-
buildMethod: MacBuilder.BuildForAltTester
24-
buildPath: sample/Builds/MacOS
25-
- targetPlatform: StandaloneWindows64
26-
buildMethod: WindowsBuilder.BuildForAltTester
27-
buildPath: sample/Builds/Windows64
28-
- targetPlatform: Android
29-
buildMethod: MobileBuilder.BuildForAltTester
30-
buildPath: sample/Builds/Android
15+
# build:
16+
# name: Build ${{ matrix.targetPlatform }} for AltTester 🛠️
17+
# runs-on: ubuntu-latest-8-cores
18+
# strategy:
19+
# fail-fast: false
20+
# matrix:
21+
# include:
22+
# - targetPlatform: StandaloneOSX
23+
# buildMethod: MacBuilder.BuildForAltTester
24+
# buildPath: sample/Builds/MacOS
25+
# - targetPlatform: StandaloneWindows64
26+
# buildMethod: WindowsBuilder.BuildForAltTester
27+
# buildPath: sample/Builds/Windows64
28+
# - targetPlatform: Android
29+
# buildMethod: MobileBuilder.BuildForAltTester
30+
# buildPath: sample/Builds/Android
31+
# steps:
32+
# - uses: actions/checkout@v3
33+
# with:
34+
# lfs: true
35+
# - uses: actions/cache@v3
36+
# with:
37+
# path: Library
38+
# key: Library-${{ matrix.targetPlatform }}-${{ hashFiles('sample/Assets/**', 'sample/Packages/**', 'sample/ProjectSettings/**') }}
39+
# restore-keys: |
40+
# Library-${{ matrix.targetPlatform }}
41+
# Library-
42+
# - name: Build project
43+
# uses: game-ci/unity-builder@v4
44+
# env:
45+
# UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
46+
# UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
47+
# UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
48+
# with:
49+
# targetPlatform: ${{ matrix.targetPlatform }}
50+
# projectPath: sample
51+
# buildMethod: ${{ matrix.buildMethod }}
52+
# customParameters: -logFile logFile.log -quit -batchmode
53+
# artifactsPath: ${{ matrix.buildPath }}
54+
# - name: List build directory
55+
# run: ls -R ./
56+
# - name: Ensure build path exists
57+
# run: mkdir -p ${{ matrix.buildPath }}
58+
# - name: Upload artifact
59+
# uses: actions/upload-artifact@v4
60+
# if: always()
61+
# with:
62+
# name: Build-${{ matrix.targetPlatform }}
63+
# path: ${{ matrix.buildPath }}
64+
# test:
65+
# name: Run ${{ matrix.targetPlatform }} UI tests 🧪
66+
# needs: build
67+
# strategy:
68+
# matrix:
69+
# include:
70+
# - targetPlatform: StandaloneOSX
71+
# runs-on: [self-hosted, macOS]
72+
# test_script: pytest -xs test/test_mac.py::MacTest
73+
# - targetPlatform: StandaloneWindows64
74+
# runs-on: [self-hosted, windows]
75+
# test_script: pytest -xs test/test_windows.py::WindowsTest
76+
# - targetPlatform: Android
77+
# runs-on: [ self-hosted, macOS ]
78+
# test_script: browserstack-sdk pytest -s ./test/test_android.py --browserstack.config "browserstack.android.yml"
79+
# concurrency:
80+
# group: test-${{ matrix.targetPlatform }}
81+
# runs-on: ${{ matrix.runs-on }}
82+
# steps:
83+
# - uses: actions/checkout@v3
84+
# with:
85+
# lfs: true
86+
# - name: Create temporary keychain
87+
# if: ${{ matrix.targetPlatform == 'StandaloneOSX' }}
88+
# run: |
89+
# security list-keychains
90+
# security delete-keychain temporary || true
91+
# security list-keychains
92+
# security create-keychain -p "" temporary
93+
# security default-keychain -s temporary
94+
# security unlock-keychain -p "" temporary
95+
# security set-keychain-settings -lut 600 temporary
96+
# - uses: actions/download-artifact@v4
97+
# with:
98+
# name: Build-${{ matrix.targetPlatform }}
99+
# path: sample/Tests
100+
# - name: Make macOS artifact executable
101+
# if: ${{ matrix.targetPlatform == 'StandaloneOSX' }}
102+
# run: chmod +x sample/Tests/SampleApp.app/Contents/MacOS/*
103+
# - uses: actions/setup-python@v4
104+
# with:
105+
# python-version: "3.10"
106+
# - name: Install dependencies (Windows)
107+
# if: ${{ matrix.targetPlatform == 'StandaloneWindows64' }}
108+
# run: pip install -r "sample/Tests/requirements-desktop.txt"
109+
# - name: Install dependencies (Mac)
110+
# if: ${{ matrix.targetPlatform != 'StandaloneWindows64' }}
111+
# run: |
112+
# if [[ "${{ matrix.targetPlatform }}" == "StandaloneOSX" ]]; then
113+
# pip uninstall -y browserstack-sdk || true
114+
# pip install -r "sample/Tests/requirements-desktop.txt"
115+
# else
116+
# pip install -r "sample/Tests/requirements-mobile.txt"
117+
# fi
118+
# - name: Run UI tests
119+
# env:
120+
# UNITY_APP_PATH: SampleApp.app
121+
# UNITY_APP_NAME: SampleApp
122+
# MAILSLURP_API_KEY: ${{ secrets.MAILSLURP_API_KEY }}
123+
# BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
124+
# BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
125+
# working-directory: sample/Tests
126+
# run: ${{ matrix.test_script }}
127+
# - name: Remove temporary keychain
128+
# if: ${{ matrix.targetPlatform == 'StandaloneOSX' }}
129+
# run: |
130+
# security list-keychains
131+
# security default-keychain -s ~/Library/Keychains/login.keychain-db
132+
# security delete-keychain temporary
133+
# security list-keychains
134+
test-ios:
135+
name: Run iOS UI tests 🧪
136+
runs-on: [ self-hosted, macOS ]
31137
steps:
32138
- uses: actions/checkout@v3
33139
with:
34140
lfs: true
35-
- uses: actions/cache@v3
36-
with:
37-
path: Library
38-
key: Library-${{ matrix.targetPlatform }}-${{ hashFiles('sample/Assets/**', 'sample/Packages/**', 'sample/ProjectSettings/**') }}
39-
restore-keys: |
40-
Library-${{ matrix.targetPlatform }}
41-
Library-
42-
- name: Build project
43-
uses: game-ci/unity-builder@v4
141+
- name: Build iOS app
142+
working-directory: sample
143+
run: ./build_ios.sh
144+
- name: Install jq (if not installed)
145+
run: |
146+
if ! command -v jq &> /dev/null; then
147+
echo "jq not found, installing..."
148+
brew install jq
149+
else
150+
echo "jq is already installed"
151+
fi
152+
- name: Upload iOS app to BrowserStack
153+
working-directory: sample/Tests
44154
env:
45-
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
46-
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
47-
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
48-
with:
49-
targetPlatform: ${{ matrix.targetPlatform }}
50-
projectPath: sample
51-
buildMethod: ${{ matrix.buildMethod }}
52-
customParameters: -logFile logFile.log -quit -batchmode
53-
artifactsPath: ${{ matrix.buildPath }}
54-
- name: List build directory
55-
run: ls -R ./
56-
- name: Ensure build path exists
57-
run: mkdir -p ${{ matrix.buildPath }}
58-
- name: Upload artifact
59-
uses: actions/upload-artifact@v4
60-
if: always()
61-
with:
62-
name: Build-${{ matrix.targetPlatform }}
63-
path: ${{ matrix.buildPath }}
64-
test:
65-
name: Run ${{ matrix.targetPlatform }} UI tests 🧪
66-
needs: build
67-
strategy:
68-
matrix:
69-
include:
70-
- targetPlatform: StandaloneOSX
71-
runs-on: [self-hosted, macOS]
72-
test_script: pytest -xs test/test_mac.py::MacTest
73-
- targetPlatform: StandaloneWindows64
74-
runs-on: [self-hosted, windows]
75-
test_script: pytest -xs test/test_windows.py::WindowsTest
76-
- targetPlatform: Android
77-
runs-on: [ self-hosted, macOS ]
78-
test_script: browserstack-sdk pytest -s ./test/test_android.py --browserstack.config "browserstack.android.yml"
79-
concurrency:
80-
group: test-${{ matrix.targetPlatform }}
81-
runs-on: ${{ matrix.runs-on }}
82-
steps:
83-
- uses: actions/checkout@v3
84-
with:
85-
lfs: true
86-
- name: Create temporary keychain
87-
if: ${{ matrix.targetPlatform == 'StandaloneOSX' }}
155+
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
156+
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
88157
run: |
89-
security list-keychains
90-
security delete-keychain temporary || true
91-
security list-keychains
92-
security create-keychain -p "" temporary
93-
security default-keychain -s temporary
94-
security unlock-keychain -p "" temporary
95-
security set-keychain-settings -lut 600 temporary
96-
- uses: actions/download-artifact@v4
97-
with:
98-
name: Build-${{ matrix.targetPlatform }}
99-
path: sample/Tests
100-
- name: Make macOS artifact executable
101-
if: ${{ matrix.targetPlatform == 'StandaloneOSX' }}
102-
run: chmod +x sample/Tests/SampleApp.app/Contents/MacOS/*
158+
curl -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
159+
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
160+
161+
162+
# Extract app_url from the response using jq
163+
app_url=$(echo "$response" | jq -r '.app_url')
164+
165+
if [ -z "$app_url" ]; then
166+
echo "Error: app_url is not found in the response"
167+
exit 1 # Fail the workflow if app_url is not present
168+
fi
169+
170+
echo "app_url: $app_url"
171+
172+
echo "APP_URL=$app_url" >> $GITHUB_ENV
103173
- uses: actions/setup-python@v4
104174
with:
105175
python-version: "3.10"
106-
- name: Install dependencies (Windows)
107-
if: ${{ matrix.targetPlatform == 'StandaloneWindows64' }}
108-
run: pip install -r "sample/Tests/requirements-desktop.txt"
109-
- name: Install dependencies (Mac)
110-
if: ${{ matrix.targetPlatform != 'StandaloneWindows64' }}
111-
run: |
112-
if [[ "${{ matrix.targetPlatform }}" == "StandaloneOSX" ]]; then
113-
pip uninstall -y browserstack-sdk || true
114-
pip install -r "sample/Tests/requirements-desktop.txt"
115-
else
116-
pip install -r "sample/Tests/requirements-mobile.txt"
117-
fi
176+
- name: Install dependencies
177+
run: pip install -r "sample/Tests/requirements-mobile.txt"
118178
- name: Run UI tests
119179
env:
120-
UNITY_APP_PATH: SampleApp.app
121-
UNITY_APP_NAME: SampleApp
122180
MAILSLURP_API_KEY: ${{ secrets.MAILSLURP_API_KEY }}
123181
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
124182
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
125183
working-directory: sample/Tests
126-
run: ${{ matrix.test_script }}
127-
- name: Remove temporary keychain
128-
if: ${{ matrix.targetPlatform == 'StandaloneOSX' }}
129-
run: |
130-
security list-keychains
131-
security default-keychain -s ~/Library/Keychains/login.keychain-db
132-
security delete-keychain temporary
133-
security list-keychains
134-
# test-ios:
135-
# name: Run iOS UI tests 🧪
136-
# runs-on: [ self-hosted, macOS ]
137-
# steps:
138-
# - uses: actions/checkout@v3
139-
# with:
140-
# lfs: true
141-
# - name: Build iOS app
142-
# working-directory: sample
143-
# run: ./build_ios.sh
144-
# - uses: actions/setup-python@v4
145-
# with:
146-
# python-version: "3.10"
147-
# - name: Install dependencies
148-
# run: pip install -r "sample/Tests/requirements-mobile.txt"
149-
# - name: Run UI tests
150-
# env:
151-
# MAILSLURP_API_KEY: ${{ secrets.MAILSLURP_API_KEY }}
152-
# BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
153-
# BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
154-
# working-directory: sample/Tests
155-
# run: browserstack-sdk pytest -s ./test/test_ios.py --browserstack.config "browserstack.ios.yml"
184+
run: browserstack-sdk pytest -s ./test/test_ios.py --browserstack.config "browserstack.ios.yml"
156185

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using UnityEditor.Callbacks;
4+
using System.IO;
5+
using System.Linq;
6+
using UnityEditor.iOS.Xcode;
7+
8+
public class iOSPostBuildProcessor
9+
{
10+
[PostProcessBuild]
11+
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
12+
{
13+
if (target == BuildTarget.iOS && IsCommandLineBuild())
14+
{
15+
Debug.Log("Command-line iOS build detected. Modifying Info.plist and Xcode project...");
16+
ModifyInfoPlist(pathToBuiltProject);
17+
ModifyXcodeProject(pathToBuiltProject, GetBundleIdentifierFromArgs());
18+
}
19+
else
20+
{
21+
Debug.Log("Skipping Info.plist modification (not an iOS command-line build).");
22+
}
23+
}
24+
25+
private static bool IsCommandLineBuild()
26+
{
27+
string[] args = System.Environment.GetCommandLineArgs();
28+
return args.Contains("--ciBuild"); // Check for the --ciBuild flag
29+
}
30+
31+
private static void ModifyInfoPlist(string pathToBuiltProject)
32+
{
33+
string plistPath = Path.Combine(pathToBuiltProject, "Info.plist");
34+
35+
if (!File.Exists(plistPath))
36+
{
37+
Debug.LogError("Info.plist not found!");
38+
return;
39+
}
40+
41+
// Load the Info.plist
42+
PlistDocument plist = new PlistDocument();
43+
plist.ReadFromFile(plistPath);
44+
45+
// Get the root dictionary
46+
PlistElementDict rootDict = plist.root;
47+
48+
// Add App Transport Security Settings
49+
PlistElementDict atsDict = rootDict.CreateDict("NSAppTransportSecurity");
50+
atsDict.SetBoolean("NSAllowsArbitraryLoads", true);
51+
52+
// Save the modified Info.plist
53+
plist.WriteToFile(plistPath);
54+
55+
Debug.Log("Successfully updated Info.plist with NSAllowsArbitraryLoads set to YES.");
56+
}
57+
58+
private static void ModifyXcodeProject(string pathToBuiltProject, string bundleIdentifier)
59+
{
60+
string pbxprojPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
61+
PBXProject pbxProject = new PBXProject();
62+
pbxProject.ReadFromFile(pbxprojPath);
63+
64+
string targetGuid = pbxProject.GetUnityMainTargetGuid(); // Unity 2019+
65+
pbxProject.SetBuildProperty(targetGuid, "PRODUCT_BUNDLE_IDENTIFIER", bundleIdentifier);
66+
67+
pbxProject.WriteToFile(pbxprojPath);
68+
Debug.Log($"Updated Xcode project with bundle identifier: {bundleIdentifier}");
69+
}
70+
71+
private static string GetBundleIdentifierFromArgs()
72+
{
73+
string[] args = System.Environment.GetCommandLineArgs();
74+
for (int i = 0; i < args.Length; i++)
75+
{
76+
if (args[i] == "--bundleIdentifier" && i + 1 < args.Length)
77+
{
78+
return args[i + 1];
79+
}
80+
}
81+
return "com.immutable.Immutable-Sample"; // Default fallback
82+
}
83+
}

sample/Assets/Editor/iOSPostBuildProcessor.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)