-
Notifications
You must be signed in to change notification settings - Fork 0
/
.space.kts
169 lines (143 loc) · 6.05 KB
/
.space.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
job("00 - Generate license request") {
// This job needs to be run only once.
// Set the UNITY_USERNAME and UNITY_PASSWORD secrets to generate an activation file.
//
// After run:
// 1. The activation file is echoed to build output, and should be saved as *.alf
// 2. Visit https://license.unity3d.com/manual
// 3. Upload the file in the form
// 4. Answer questions (unity pro vs personal edition, both will work, just pick the one you use)
// 5. Download 'Unity_v2021.x.ulf' file
// 6. Copy the content of 'Unity_v2021.x.ulf' license file to the secret unity_license
startOn {
gitPush { enabled = false }
}
container(displayName = "Unity", image = "unityci/editor:ubuntu-2021.3.17f1-linux-il2cpp-1.0.1") {
resources {
cpu = 2.cpu
memory = 8.gb
}
env.set("UNITY_USERNAME", Secrets("unity_username"))
env.set("UNITY_PASSWORD", Secrets("unity_password"))
shellScript {
content = """
${'$'}{UNITY_EXECUTABLE:-xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' unity-editor} \
-batchmode \
-nographics \
-username "${'$'}UNITY_USERNAME" -password "${'$'}UNITY_PASSWORD" \
-logFile /dev/stdout | tee ./unity-output.log
cat ./unity-output.log | grep 'LICENSE SYSTEM .* Posting *' | sed 's/.*Posting *//' > "/tmp/request.txt"
echo "----------------------"
echo "1. Save the below output as *.alf"
echo "2. Visit https://license.unity3d.com/manual
echo "3. Upload the file in the form
echo "4. Answer questions (unity pro vs personal edition, both will work, just pick the one you use)
echo "5. Download 'Unity_v20xx.x.ulf' file
echo "6. Copy the content of 'Unity_v20xx.x.ulf' license file to the Space project secret unity_license
echo "----------------------"
cat "/tmp/request.txt"
echo "----------------------"
""".trimIndent()
}
}
}
job("Build TowerDefense - Linux x64") {
buildUnity(
displayName = "Build Linux x64",
containerImage = "unityci/editor:ubuntu-2021.3.17f1-linux-il2cpp-1.0.1",
executeMethod = "Editor.BuildPlayer.LinuxBuild",
artifactsPath = "artifacts/linux-x64/",
publishArtifactFileName = "towerdefense-linux-x64.tar.gz"
)
}
job("Build TowerDefense - macOS") {
buildUnity(
displayName = "Build macOS",
containerImage = "unityci/editor:2021.3.17f1-mac-mono-1.0.1",
executeMethod = "Editor.BuildPlayer.MacOsBuild",
artifactsPath = "artifacts/macos/",
publishArtifactFileName = "towerdefense-macos.tar.gz"
)
}
job("Build TowerDefense - Windows x64") {
buildUnity(
displayName = "Build Windows",
containerImage = "unityci/editor:2021.3.17f1-windows-mono-1.0.1",
executeMethod = "Editor.BuildPlayer.WindowsBuild",
artifactsPath = "artifacts/windows-x64/",
publishArtifactFileName = "towerdefense-windows-x64.tar.gz"
)
}
job("Build TowerDefense - Android") {
startOn {
gitPush { enabled = false }
}
buildUnity(
displayName = "Build Android",
containerImage = "unityci/editor:2021.3.17f1-android-1.0.1",
executeMethod = "Editor.BuildPlayer.AndroidBuild",
artifactsPath = "artifacts/android/",
publishArtifactFileName = "towerdefense-android.tar.gz"
)
}
job("Build TowerDefense - iOS") {
startOn {
gitPush { enabled = false }
}
buildUnity(
displayName = "Build iOS",
containerImage = "unityci/editor:2021.3.17f1-ios-1.0.1",
executeMethod = "Editor.BuildPlayer.IosBuild",
artifactsPath = "artifacts/ios/",
publishArtifactFileName = "towerdefense-ios.tar.gz"
)
}
fun StepsScope.buildUnity(
displayName: String,
containerImage: String,
executeMethod: String,
artifactsPath: String,
publishArtifactFileName: String
) {
container(displayName = displayName, image = containerImage) {
resources {
cpu = 8.cpu
memory = 16.gb
}
fileInput {
source = FileSource.Text("{{ project:unity_license }}")
localPath = "/mnt/space/Unity_lic.ulf"
}
// https://josusb.com/en/blog/building-unity-on-the-command-line/
// https://gitlab.com/game-ci/unity3d-gitlab-ci-example/-/blob/main/ci/build.sh
shellScript {
content = """
## Initialize and copy license secret
mkdir -p /root/.cache/unity3d
mkdir -p /root/.local/share/unity3d/Unity/
cp /mnt/space/Unity_lic.ulf /root/.local/share/unity3d/Unity
## Build
unity-editor \
-projectPath ./ \
-quit \
-batchmode \
-nographics \
-executeMethod $executeMethod \
-logFile /dev/stdout
UNITY_EXIT_CODE=${'$'}?
if [ ${'$'}UNITY_EXIT_CODE -eq 0 ]; then
echo "Run succeeded, no failures occurred";
elif [ ${'$'}UNITY_EXIT_CODE -eq 2 ]; then
echo "Run succeeded, some tests failed";
elif [ ${'$'}UNITY_EXIT_CODE -eq 3 ]; then
echo "Run failure (other failure)";
else
echo "Unexpected exit code ${'$'}UNITY_EXIT_CODE";
fi
echo Uploading artifacts...
tar -zcvf $publishArtifactFileName $artifactsPath
curl -i -H "Authorization: Bearer ${'$'}JB_SPACE_CLIENT_TOKEN" -F file=@"$publishArtifactFileName" https://files.pkg.jetbrains.space/demo/p/td/towerdefense/space/${'$'}JB_SPACE_EXECUTION_NUMBER/
""".trimIndent()
}
}
}