Skip to content

Commit b3bce3f

Browse files
committed
core(deploy): add Codemagic CI/CD config
1 parent 6902436 commit b3bce3f

File tree

9 files changed

+234
-2
lines changed

9 files changed

+234
-2
lines changed

Diff for: Assets/Editor.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Assets/Editor/Build.cs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Linq;
2+
using System;
3+
using UnityEditor;
4+
using UnityEngine;
5+
6+
public static class BuildScript
7+
{
8+
9+
[MenuItem("Build/Build Windows")]
10+
public static void BuildWindows()
11+
{
12+
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
13+
buildPlayerOptions.locationPathName = "windows/" + Application.productName + ".exe";
14+
buildPlayerOptions.target = BuildTarget.StandaloneWindows64;
15+
buildPlayerOptions.options = BuildOptions.None;
16+
buildPlayerOptions.scenes = GetScenes();
17+
18+
Debug.Log("Building StandaloneWindows64");
19+
BuildPipeline.BuildPlayer(buildPlayerOptions);
20+
Debug.Log("Built StandaloneWindows64");
21+
}
22+
23+
private static string[] GetScenes()
24+
{
25+
return (from scene in EditorBuildSettings.scenes where scene.enabled select scene.path).ToArray();
26+
}
27+
28+
}

Diff for: Assets/Editor/Build.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Packages/manifest.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"com.unity.test-framework": "1.1.29",
1515
"com.unity.textmeshpro": "3.0.6",
1616
"com.unity.timeline": "1.4.8",
17+
"com.unity.toolchain.macos-x86_64-linux-x86_64": "0.1.22-preview",
1718
"com.unity.ugui": "1.0.0",
1819
"com.unity.modules.ai": "1.0.0",
1920
"com.unity.modules.androidjni": "1.0.0",

Diff for: Packages/packages-lock.json

+26
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@
127127
},
128128
"url": "https://packages.unity.com"
129129
},
130+
"com.unity.sysroot": {
131+
"version": "0.1.19-preview",
132+
"depth": 1,
133+
"source": "registry",
134+
"dependencies": {},
135+
"url": "https://packages.unity.com"
136+
},
137+
"com.unity.sysroot.linux-x86_64": {
138+
"version": "0.1.14-preview",
139+
"depth": 1,
140+
"source": "registry",
141+
"dependencies": {
142+
"com.unity.sysroot": "0.1.18-preview"
143+
},
144+
"url": "https://packages.unity.com"
145+
},
130146
"com.unity.test-framework": {
131147
"version": "1.1.29",
132148
"depth": 0,
@@ -159,6 +175,16 @@
159175
},
160176
"url": "https://packages.unity.com"
161177
},
178+
"com.unity.toolchain.macos-x86_64-linux-x86_64": {
179+
"version": "0.1.22-preview",
180+
"depth": 0,
181+
"source": "registry",
182+
"dependencies": {
183+
"com.unity.sysroot": "0.1.19-preview",
184+
"com.unity.sysroot.linux-x86_64": "0.1.14-preview"
185+
},
186+
"url": "https://packages.unity.com"
187+
},
162188
"com.unity.ugui": {
163189
"version": "1.0.0",
164190
"depth": 0,

Diff for: ProjectSettings/ProjectSettings.asset

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ PlayerSettings:
1212
targetDevice: 2
1313
useOnDemandResources: 0
1414
accelerometerFrequency: 60
15-
companyName: DefaultCompany
15+
companyName: minapecheux
1616
productName: UnitTestingPong
1717
defaultCursor: {fileID: 0}
1818
cursorHotspot: {x: 0, y: 0}
@@ -152,7 +152,8 @@ PlayerSettings:
152152
resolutionScalingMode: 0
153153
androidSupportedAspectRatio: 1
154154
androidMaxAspectRatio: 2.1
155-
applicationIdentifier: {}
155+
applicationIdentifier:
156+
Standalone: com.minapecheux.UnitTestingPong
156157
buildNumber:
157158
Standalone: 0
158159
iPhone: 0

Diff for: codemagic.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
workflows:
2+
unity-windows-workflow:
3+
name: Unity Windows Workflow
4+
max_build_duration: 120
5+
environment:
6+
groups:
7+
- unity
8+
scripts:
9+
- name: Run Unit Tests
10+
script: |
11+
python3 run_unit_tests.py windows
12+
- name: Build Windows
13+
script: |
14+
python3 export_unity.py windows
15+
artifacts:
16+
- windows/UnitTestingPong.exe
17+
- Logs/unity_build_*.log

Diff for: export_unity.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import os
2+
import platform
3+
import sys
4+
5+
# Check if the app type argument has been provided, e.g python3 export_unity.py windows | ios | android
6+
if len(sys.argv) >= 2:
7+
APP_TYPE = sys.argv[1].lower()
8+
print(f'APP_TYPE set to: {APP_TYPE}')
9+
else:
10+
print('APP_TYPE not set. End process.')
11+
sys.exit()
12+
13+
# Check that environment variables have been set
14+
vars = {'UNITY_HOME' : None, 'UNITY_SERIAL': None, 'UNITY_USERNAME' : None, 'UNITY_PASSWORD': None}
15+
for key,value in vars.items():
16+
if key in os.environ:
17+
vars[key] = os.getenv(key)
18+
else:
19+
print(f'{key} is not set. End process.')
20+
sys.exit()
21+
22+
# Set location of Unity binary according to machine type
23+
platform = platform.system()
24+
if platform == 'Darwin':
25+
UNITY_BIN = vars['UNITY_HOME'] + '/Contents/MacOS/Unity'
26+
LOG_DIR = '/Logs/'
27+
elif platform == 'Windows':
28+
UNITY_BIN = vars['UNITY_HOME'] + '\\Unity.exe'
29+
LOG_DIR = '\\Logs\\'
30+
elif platform == "Linux":
31+
print("Build for Linux on Mac or Windows. End Process.")
32+
sys.exit()
33+
34+
# Check that UNITY_BIN has been set
35+
if UNITY_BIN is not None:
36+
print('UNITY_BIN set to: ' + UNITY_BIN)
37+
else:
38+
print('UNITY_BIN does not exist. End process.')
39+
sys.exit()
40+
41+
# Set log file locations
42+
UNITY_PROJECT_PATH = os.getcwd()
43+
LOG_PATH = f'{UNITY_PROJECT_PATH}{LOG_DIR}'
44+
UNITY_LOG_FILE_PLATFORM = f'{LOG_PATH}unity_build_{APP_TYPE}.log'
45+
UNITY_LOG_FILE_LICENSE = f'{LOG_PATH}unity_license.log'
46+
47+
def buildPlatform(appType, unityBin, projectPath, logPath):
48+
print(f'UNITY START BUILDING {appType}')
49+
os.system(f'"{unityBin}" -quit -batchmode -projectPath {projectPath} -executeMethod BuildScript.Build{appType.capitalize()} -nographics -logFile {logPath}')
50+
print(f'UNITY END BUILDING {appType}')
51+
52+
def activateLicense(unityBin, logPath, unitySerial, unityUsername, unityPassword):
53+
print('UNITY LICENSE START')
54+
os.system(f'"{unityBin}" -quit -batchmode -skipBundles -logFile {logPath} -serial {unitySerial} -username {unityUsername} -password {unityPassword}')
55+
print('UNITY LICENSE END')
56+
57+
def returnLicense(unityBin):
58+
print('UNITY RETURN LICENSE START')
59+
os.system(f'"{unityBin}" -quit -batchmode -returnlicense -nographics')
60+
print('UNITY RETURN LICENSE END')
61+
62+
63+
activateLicense(UNITY_BIN, UNITY_LOG_FILE_LICENSE, vars["UNITY_SERIAL"],vars["UNITY_USERNAME"],vars["UNITY_PASSWORD"])
64+
buildPlatform(APP_TYPE.upper(), UNITY_BIN, UNITY_PROJECT_PATH, UNITY_LOG_FILE_PLATFORM)
65+
returnLicense(UNITY_BIN)
66+
67+
print('UNITY BUILDING DONE')

Diff for: run_unit_tests.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import os
2+
import platform
3+
import sys
4+
import xml.etree.ElementTree as ET
5+
6+
# Check if the app type argument has been provided, e.g python3 export_unity.py windows | ios | android
7+
if len(sys.argv) >= 2:
8+
APP_TYPE = sys.argv[1].lower()
9+
print(f'APP_TYPE set to: {APP_TYPE}')
10+
else:
11+
print('APP_TYPE not set. End process.')
12+
sys.exit()
13+
14+
# Check that environment variables have been set
15+
vars = {'UNITY_HOME' : None}
16+
for key,value in vars.items():
17+
if key in os.environ:
18+
vars[key] = os.getenv(key)
19+
else:
20+
print(f'{key} is not set. End process.')
21+
sys.exit()
22+
23+
# Set location of Unity binary according to machine type
24+
platform = platform.system()
25+
if platform == 'Darwin':
26+
UNITY_BIN = vars['UNITY_HOME'] + '/Contents/MacOS/Unity'
27+
LOG_DIR = '/Logs/'
28+
elif platform == 'Windows':
29+
UNITY_BIN = vars['UNITY_HOME'] + '\\Unity.exe'
30+
LOG_DIR = '\\Logs\\'
31+
elif platform == "Linux":
32+
print("Build for Linux on Mac or Windows. End Process.")
33+
sys.exit()
34+
35+
# Check that UNITY_BIN has been set
36+
if UNITY_BIN is not None:
37+
print('UNITY_BIN set to: ' + UNITY_BIN)
38+
else:
39+
print('UNITY_BIN does not exist. End process.')
40+
sys.exit()
41+
42+
# Set log file locations
43+
UNITY_PROJECT_PATH = os.getcwd()
44+
LOG_PATH = f'{UNITY_PROJECT_PATH}{LOG_DIR}'
45+
UNITY_LOG_FILE_PLATFORM = f'{LOG_PATH}unity_unit_test_{APP_TYPE}.log'
46+
UNIT_TEST_FILE_PATH = f'{UNITY_PROJECT_PATH}/tests.xml'
47+
48+
def runTests(appType, unityBin, projectPath, testFilePath, logPath):
49+
print(f'UNITY START UNIT TESTS {appType}')
50+
os.system(f'"{unityBin}" -batchmode -projectPath {projectPath} -nographics -runTests -testResults {testFilePath} -logFile {logPath}')
51+
print(f'UNITY END UNIT TESTS {appType}')
52+
53+
def checkTests(testFilePath):
54+
if not os.path.exists(testFilePath):
55+
print(f'Could not find unit tests results!')
56+
return 1
57+
58+
tree = ET.parse(testFilePath)
59+
root = tree.getroot()
60+
hasPassed = root.attrib['result'] == 'Passed'
61+
if hasPassed:
62+
print(f'Tests succeeded :(')
63+
return 0
64+
else:
65+
print(f'Tests failed :(')
66+
return 1
67+
68+
runTests(APP_TYPE.upper(), UNITY_BIN, UNITY_PROJECT_PATH, UNIT_TEST_FILE_PATH, UNITY_LOG_FILE_PLATFORM)
69+
testsExitCode = checkTests(UNIT_TEST_FILE_PATH)
70+
71+
print('UNIT TESTS DONE')
72+
os.remove(UNIT_TEST_FILE_PATH)
73+
sys.exit(testsExitCode)

0 commit comments

Comments
 (0)