Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
unity: game-ci/unity@1.7.1
Use unity
elements in your existing workflows and jobs.
Opt-in to use of uncertified orbs on your organization’s Security settings page.
Drop-in solution to automatically run tests and build your Unity project using a Personal license. Make sure to read the documentation before using the orb: https://game.ci/docs/circleci/getting-started. For runner examples, see: https://game.ci/docs/circleci/executors#macos-runner and https://game.ci/docs/circleci/executors#windows-runner.
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
version: '2.1'
orbs:
unity: game-ci/unity@1.3.0
workflows:
test-build-with-executors:
jobs:
- checkout
- unity/test:
context: unity
executor:
editor_version: 2021.3.1f1
name: unity/ubuntu
resource_class: medium
target_platform: linux-il2cpp
name: test-linux
project-path: Unity2D-Demo-Game-CI-CD/src
step-name: Check if the tests run and results are uploaded
test-platform: playmode
unity-license-var-name: UNITY_ENCODED_LICENSE
unity-password-var-name: UNITY_PASSWORD
unity-username-var-name: UNITY_USERNAME
- unity/build:
build-target: StandaloneLinux64
compress: true
context: unity
executor:
editor_version: 2021.3.1f1
name: unity/ubuntu
resource_class: large
target_platform: linux-il2cpp
name: build-linux64-il2cpp
project-path: Unity2D-Demo-Game-CI-CD/src
requires:
- test-linux
step-name: Build StandaloneLinux64
unity-license-var-name: UNITY_ENCODED_LICENSE
unity-password-var-name: UNITY_PASSWORD
unity-username-var-name: UNITY_USERNAME
- unity/test:
context: unity
executor:
editor_version: 2021.3.2f1
name: unity/windows-2022
size: large
target_platform: windows-il2cpp
name: test-windows
project-path: Unity2D-Demo-Game-CI-CD/src
step-name: Check if the tests run and results are uploaded
test-platform: playmode
unity-license-var-name: UNITY_ENCODED_LICENSE
unity-password-var-name: UNITY_PASSWORD
unity-username-var-name: UNITY_USERNAME
- unity/build:
build-target: StandaloneWindows64
compress: true
context: unity
executor:
editor_version: 2021.3.2f1
name: unity/windows-2019
size: large
target_platform: windows-il2cpp
name: build-Windows64-il2cpp
project-path: Unity2D-Demo-Game-CI-CD/src
requires:
- test-windows
step-name: Build StandaloneWindows64 il2cpp
unity-license-var-name: UNITY_ENCODED_LICENSE
unity-password-var-name: UNITY_PASSWORD
unity-username-var-name: UNITY_USERNAME
- unity/test:
context: unity
executor:
editor_version: 2021.3.1f1
name: unity/macos
resource_class: large
name: test-osx
project-path: Unity2D-Demo-Game-CI-CD/src
step-name: Check if the tests run and results are uploaded
test-platform: playmode
unity-license-var-name: UNITY_ENCODED_LICENSE
unity-password-var-name: UNITY_PASSWORD
unity-username-var-name: UNITY_USERNAME
- unity/build:
build-target: StandaloneOSX
compress: true
context: unity
executor:
editor_version: 2021.3.2f1
name: unity/macos
resource_class: large
name: build-osx-il2cpp
project-path: Unity2D-Demo-Game-CI-CD/src
requires:
- test-osx
step-name: Build macOS IL2CPP
unity-license-var-name: UNITY_ENCODED_LICENSE
unity-password-var-name: UNITY_PASSWORD
unity-username-var-name: UNITY_USERNAME
Drop-in solution to automatically run tests and build your Unity project using a Pro or Plus license. Make sure to read the documentation before using the orb: https://game.ci/docs/circleci/getting-started. For runner examples, see: https://game.ci/docs/circleci/executors#macos-runner and https://game.ci/docs/circleci/executors#windows-runner.
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
version: '2.1'
orbs:
unity: game-ci/unity@1.3.0
workflows:
test-build-with-executors:
jobs:
- checkout
- unity/test:
context: unity
executor:
editor_version: 2021.3.1f1
name: unity/ubuntu
resource_class: medium
target_platform: linux-il2cpp
name: test-linux
project-path: Unity2D-Demo-Game-CI-CD/src
step-name: Check if the tests run and results are uploaded
test-platform: playmode
unity-password-var-name: UNITY_PASSWORD
unity-serial-var-name: UNITY_SERIAL
unity-username-var-name: UNITY_USERNAME
- unity/build:
build-target: StandaloneLinux64
compress: true
context: unity
executor:
editor_version: 2021.3.1f1
name: unity/ubuntu
resource_class: large
target_platform: linux-il2cpp
name: build-linux64-il2cpp
project-path: Unity2D-Demo-Game-CI-CD/src
requires:
- test-linux
step-name: Build StandaloneLinux64
unity-password-var-name: UNITY_PASSWORD
unity-serial-var-name: UNITY_SERIAL
unity-username-var-name: UNITY_USERNAME
- unity/test:
context: unity
executor:
editor_version: 2021.3.2f1
name: unity/windows-2022
size: large
target_platform: windows-il2cpp
name: test-windows
project-path: Unity2D-Demo-Game-CI-CD/src
step-name: Check if the tests run and results are uploaded
test-platform: playmode
unity-password-var-name: UNITY_PASSWORD
unity-serial-var-name: UNITY_SERIAL
unity-username-var-name: UNITY_USERNAME
- unity/build:
build-target: StandaloneWindows64
compress: true
context: unity
executor:
editor_version: 2021.3.2f1
name: unity/windows-2019
size: large
target_platform: windows-il2cpp
name: build-Windows64-il2cpp
project-path: Unity2D-Demo-Game-CI-CD/src
requires:
- test-windows
step-name: Build StandaloneWindows64 il2cpp
unity-password-var-name: UNITY_PASSWORD
unity-serial-var-name: UNITY_SERIAL
unity-username-var-name: UNITY_USERNAME
- unity/test:
context: unity
executor:
editor_version: 2021.3.1f1
name: unity/macos
resource_class: large
name: test-osx
project-path: Unity2D-Demo-Game-CI-CD/src
step-name: Check if the tests run and results are uploaded
test-platform: playmode
unity-password-var-name: UNITY_PASSWORD
unity-serial-var-name: UNITY_SERIAL
unity-username-var-name: UNITY_USERNAME
- unity/build:
build-target: StandaloneOSX
compress: true
context: unity
executor:
editor_version: 2021.3.2f1
name: unity/macos
resource_class: large
name: build-osx-il2cpp
project-path: Unity2D-Demo-Game-CI-CD/src
requires:
- test-osx
step-name: Build macOS IL2CPP
unity-password-var-name: UNITY_PASSWORD
unity-serial-var-name: UNITY_SERIAL
unity-username-var-name: UNITY_USERNAME
Simple drop-in job to build your Unity game.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
build-method | The method used as argument for the Unity CLI "executeMethod" parameter.
It must be a valid path to a static method and the class exist in the Assets/Editor directory.
If left empty, the default build method will be used.
| No | '' | string |
build-name | Enter the name for this build.
If left blank, the build will be named after the target platform.
| No | '' | string |
build-target | The target platform of your build.
Accepted arguments vary with Unity's version and can be found in the docs: https://docs.unity3d.com/2022.2/Documentation/ScriptReference/BuildTarget.html
| Yes | - | string |
compress | Whether to compress the build output to a ".tar.gz" archive.
This is recommended if you want to download the built artifacts from the CircleCI web app.
If left to "false" for decompressed WebGL builds, you can run the project directly from the CircleCI web app.
| No | true | boolean |
custom-parameters | Additional arguments for the Unity CLI.
Use it to pass arguments defined on your custom "build-method" or Unity's build options. Environment variables are supported.
The parameters must be separated by space and must be in the format "-key value" or "-key" for booleans.
Example: "-customArg1 WebGL -EnableHeadlessMode -customArg2 $CIRCLE_WORKFLOW_ID".
| No | '' | string |
executor | Pick an Executor to run the build job with.
| Yes | - | executor |
fetch-submodules | Whether to fetch git submodules
| No | false | boolean |
no_output_timeout | Elapsed time the command can run without output. | No | 20m | string |
persist-to-workspace | Whether to persist the build output to workspace. | No | false | boolean |
project-path | Enter the path of your Unity project.
This should be the directory that has an "Assets" folder inside it.
| No | . | string |
return-license | Whether to return the license used to build the project.
Unity only allows returning professional licenses.
| No | false | boolean |
step-name | Specify a custom step name for the build command, if desired.
| No | Build the project | string |
store-artifacts | Whether to store the build output.
If left to "false" you won't be able to download the build from the job's artifacts.
| No | true | boolean |
unity-license-var-name | Enter the name of the environment variable containing your Unity license file encoded in base64.
Required if you have a Personal license.
| No | UNITY_ENCODED_LICENSE | env_var_name |
unity-password-var-name | Enter the name of the environment variable containing your Unity password.
| No | UNITY_PASSWORD | env_var_name |
unity-serial-var-name | Enter the name of the environment variable containing your Unity serial number.
Required if you have a Plus or Pro license.
| No | UNITY_SERIAL | env_var_name |
unity-username-var-name | Enter the name of the environment variable containing your Unity username.
| No | UNITY_USERNAME | env_var_name |
Simple drop-in job to create a Unity activation file.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
editor_version | Pick the editor version for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
| No | 2021.3.7f1 | string |
Simple drop-in job to build your Unity game.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
custom-parameters | Additional arguments for the Unity CLI.
Use it to pass arguments to Unity's test options. Environment variables are supported.
The parameters must be separated by space and must be in the format "-key value" or "-key" for booleans.
Example: '-testFilter "MyNamespace.Something.MyTest" -assemblyNames "MyUnitTestAssembly" -testCategory "Unit;Integration"'.
| No | '' | string |
executor | Pick an Executor to run the build job with.
| Yes | - | executor |
no_output_timeout | Elapsed time the command can run without output. | No | 20m | string |
project-path | Enter the path of your Unity project.
This should be the directory that has an "Assets" folder inside it.
| No | . | string |
return-license | Whether to return the license used to test the project.
Unity only allows returning professional licenses.
| No | false | boolean |
step-name | Specify a custom step name for the test command, if desired.
| No | Run tests | string |
test-platform | Specify the test platform to run tests on.
Valid values are "editmode", "playmode" and Unity's target builds.
More information can be found on: https://docs.unity3d.com/Packages/com.unity.test-framework@2.0/manual/reference-command-line.html
| No | editmode | string |
unity-license-var-name | Enter the name of the environment variable containing your Unity license file encoded in base64.
Required if you have a Personal license.
| No | UNITY_ENCODED_LICENSE | env_var_name |
unity-password-var-name | Enter the name of the environment variable containing your Unity password.
| No | UNITY_PASSWORD | env_var_name |
unity-serial-var-name | Enter the name of the environment variable containing your Unity serial number.
Required if you have a Plus or Pro license.
| No | UNITY_SERIAL | env_var_name |
unity-username-var-name | Enter the name of the environment variable containing your Unity username.
| No | UNITY_USERNAME | env_var_name |
This command builds an Unity project.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
build-method | The method used as argument for the Unity CLI "executeMethod" parameter.
It must be a valid path to a static method and the class exist in the Assets/Editor directory.
If left empty, the default build method will be used.
| No | '' | string |
build-name | Enter the name for this build.
If left blank, the build will be named after the target platform.
| No | '' | string |
build-target | The target platform of your build.
Accepted arguments vary with Unity's version and can be found in the docs: https://docs.unity3d.com/2021.2/Documentation/ScriptReference/BuildTarget.html
| Yes | - | string |
cache-version | Change the default cache version if you need to clear the cache for any reason.
| No | v1 | string |
compress | Whether to compress the build output to a ".tar.gz" archive.
This is recommended if you want to download the built artifacts from the CircleCI web app.
If left to "false" for decompressed WebGL builds, you can run the project directly from the CircleCI web app.
| No | true | boolean |
custom-parameters | Additional arguments for the Unity CLI.
Use it to pass arguments defined on your custom "build-method" or Unity's build options. Environment variables are supported.
The parameters must be separated by space and must be in the format "-key value" or "-key" for booleans.
Example: "-customArg1 WebGL -EnableHeadlessMode -customArg2 $CIRCLE_WORKFLOW_ID".
| No | '' | string |
include-branch-in-cache-key | If true, this cache bucket will only apply to jobs within the same branch.
| No | true | boolean |
no_output_timeout | Elapsed time the command can run without output. | No | 10m | string |
persist-to-workspace | Whether to persist the build output to workspace. | No | false | boolean |
project-path | Enter the relative path of your Unity project.
This should be the directory that has an "Assets" folder inside it.
| No | . | string |
step-name | Specify a custom step name for this command, if desired.
| No | Build the project | string |
store-artifacts | Whether to store the build output.
If left to "false" you won't be able to download the build from the job's artifacts.
| No | true | boolean |
This command prepares the environment for testing or building an Unity project.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
cache-version | Change the default cache version if you need to clear the cache for any reason.
| No | v1 | string |
include-branch-in-cache-key | If true, this cache bucket will only apply to jobs within the same branch.
| No | true | boolean |
no_output_timeout | Elapsed time the command can run without output. | No | 10m | string |
project-path | Enter the path of your Unity project.
This should be the directory that has an "Assets" folder inside it.
| No | . | string |
unity-license-var-name | Enter the name of the environment variable containing your Unity license file encoded in base64.
Required if you have a Personal license.
| No | UNITY_ENCODED_LICENSE | env_var_name |
unity-password-var-name | Enter the name of the environment variable containing your Unity password.
| No | UNITY_PASSWORD | env_var_name |
unity-serial-var-name | Enter the name of the environment variable containing your Unity serial number.
Required if you have a Plus or Pro license.
| No | UNITY_SERIAL | env_var_name |
unity-username-var-name | Enter the name of the environment variable containing your Unity username.
| No | UNITY_USERNAME | env_var_name |
This command returns the license used to build or test the project.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
unity-password-var-name | Enter the name of the environment variable containing your Unity password.
| No | UNITY_PASSWORD | env_var_name |
unity-username-var-name | Enter the name of the environment variable containing your Unity username.
| No | UNITY_USERNAME | env_var_name |
This command tests an Unity project.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
cache-version | Change the default cache version if you need to clear the cache for any reason.
| No | v1 | string |
custom-parameters | Additional arguments for the Unity CLI.
Use it to pass arguments to Unity's test options. Environment variables are supported.
The parameters must be separated by space and must be in the format "-key value" or "-key" for booleans.
Example: '-testFilter "MyNamespace.Something.MyTest" -assemblyNames "MyUnitTestAssembly" -testCategory "Unit;Integration"'.
| No | '' | string |
include-branch-in-cache-key | If true, this cache bucket will only apply to jobs within the same branch.
| No | true | boolean |
no_output_timeout | Elapsed time the command can run without output. | No | 10m | string |
project-path | Enter the relative path of your Unity project.
This should be the directory that has an "Assets" folder inside it.
| No | . | string |
step-name | Specify a custom step name for this command, if desired.
| No | Run tests | string |
test-platform | Specify the test platform to run tests on.
Valid values are "editmode", "playmode" and Unity's target builds.
More information can be found on: https://docs.unity3d.com/Packages/com.unity.test-framework@2.0/manual/reference-command-line.html
| No | playmode | string |
Drop-in executor to build project in macOS.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
editor_version | Pick the Unity Editor version.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://unity3d.com/get-unity/download/archive.
| Yes | - | string |
resource_class | Resource class used for the executor.
If you are receiving a "CircleCI received exit code 137" from the build job, you may need to increase the resource class.
For details on resource class availability, see https://circleci.com/docs/using-macos#available-resource-classes.
| No | medium | enum |
xcode_version | Pick the Xcode version.
Available options can be found at https://circleci.com/docs/using-macos#supported-xcode-versions.
| No | 13.4.1 | string |
Drop-in executor to build projects in a macOS runner.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
editor_version | Pick the Unity Editor version.
Available options can be found at https://unity3d.com/get-unity/download/archive.
| Yes | - | string |
resource_class | Enter your Runner resource class.
For information on how to setup a Runner agent, see: https://circleci.com/docs/2.0/runner-overview/.
| Yes | - | string |
working_directory | Enter the working directory of your runner agent.
| No | /var/opt/circleci/workdir | string |
Select the Editor version and Target Platform for the GameCI image. Available target platforms can be found at: https://game.ci/docs/docker/versions. This executor only supports the "ubuntu" OS.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
editor_version | Pick the editor version for the GameCI image.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://game.ci/docs/docker/versions.
| Yes | - | string |
resource_class | Resource class used for the executor.
If you are receiving a "CircleCI received exit code 137" from the build job, you may need to increase the resource class.
| No | large | enum |
target_platform | Pick the target platform for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
The 2018 release doesn't support the "linux-il2cpp" target platform.
| Yes | - | enum |
Select the Editor version and Target Platform for the GameCI image. Available target platforms can be found at: https://game.ci/docs/docker/versions. For information on how to setup a Runner agent, see: https://circleci.com/docs/container-runner-installation/.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
editor_version | Pick the editor version for the GameCI image.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://game.ci/docs/docker/versions.
| Yes | - | string |
resource_class | Enter your Runner resource class.
For information on how to setup a Runner agent, see: https://circleci.com/docs/container-runner-installation/.
| Yes | - | string |
target_platform | Pick the target platform for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
The 2018 release doesn't support the "linux-il2cpp" target platform.
| Yes | - | enum |
Select the Editor version and Target Platform for the GameCI image. Available target platforms can be found at: https://game.ci/docs/docker/versions.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
editor_version | Pick the editor version for the GameCI image.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://game.ci/docs/docker/versions.
| Yes | - | string |
size | The size of Windows resource to use. | No | large | enum |
target_platform | Pick the target platform for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
The 2018 release doesn't support the "linux-il2cpp" target platform.
| Yes | - | enum |
version | The Windows image version to use.
| No | current | string |
Select the Editor version and Target Platform for the GameCI image. Available target platforms can be found at: https://game.ci/docs/docker/versions.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
editor_version | Pick the editor version for the GameCI image.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://game.ci/docs/docker/versions.
| Yes | - | string |
size | The size of Windows resource to use. | No | medium | enum |
target_platform | Pick the target platform for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
The 2018 release doesn't support the "linux-il2cpp" target platform.
| Yes | - | enum |
version | The Windows image version to use.
| No | current | string |
Select the Editor version and Target Platform for the GameCI image. Available target platforms can be found at: https://game.ci/docs/docker/versions.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
editor_version | Pick the editor version for the GameCI image.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://game.ci/docs/docker/versions.
| Yes | - | string |
size | The size of Windows resource to use. | No | large | enum |
target_platform | Pick the target platform for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
The 2018 release doesn't support the "linux-il2cpp" target platform.
| Yes | - | enum |
version | The Windows image version to use.
| No | current | string |
Select the Editor version and Target Platform for the GameCI image. Available target platforms can be found at: https://game.ci/docs/docker/versions. This executor only supports the "windows" OS and should be used with a CircleCI Runner. For information on how to setup a Runner agent, see: https://circleci.com/docs/2.0/runner-overview/.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
editor_version | Pick the editor version for the GameCI image.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://game.ci/docs/docker/versions.
| Yes | - | string |
resource_class | Enter your Runner resource class.
For information on how to setup a Runner agent, see: https://circleci.com/docs/2.0/runner-overview/.
| Yes | - | string |
target_platform | Pick the target platform for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
The 2018 release doesn't support the "linux-il2cpp" target platform.
| Yes | - | enum |
working_directory | Enter the working directory of your runner agent.
| No | C:\ProgramFiles\CircleCI\Workdir | string |
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
version: 2.1
description: |
Easily build and test Unity projects. The project artifacts and test results are stored in CircleCI and can be opened in the Workflow web app. Supports Windows, Linux and macOS.
display:
home_url: https://game.ci/docs/circleci/getting-started
source_url: https://github.com/game-ci/unity-orb
commands:
build:
description: |
This command builds an Unity project.
parameters:
build-method:
default: ""
description: |
The method used as argument for the Unity CLI "executeMethod" parameter.
It must be a valid path to a static method and the class exist in the Assets/Editor directory.
If left empty, the default build method will be used.
type: string
build-name:
default: ""
description: |
Enter the name for this build.
If left blank, the build will be named after the target platform.
type: string
build-target:
description: |
The target platform of your build.
Accepted arguments vary with Unity's version and can be found in the docs: https://docs.unity3d.com/2021.2/Documentation/ScriptReference/BuildTarget.html
type: string
cache-version:
default: v1
description: |
Change the default cache version if you need to clear the cache for any reason.
type: string
compress:
default: true
description: |
Whether to compress the build output to a ".tar.gz" archive.
This is recommended if you want to download the built artifacts from the CircleCI web app.
If left to "false" for decompressed WebGL builds, you can run the project directly from the CircleCI web app.
type: boolean
custom-parameters:
default: ""
description: |
Additional arguments for the Unity CLI.
Use it to pass arguments defined on your custom "build-method" or Unity's build options. Environment variables are supported.
The parameters must be separated by space and must be in the format "-key value" or "-key" for booleans.
Example: "-customArg1 WebGL -EnableHeadlessMode -customArg2 $CIRCLE_WORKFLOW_ID".
type: string
include-branch-in-cache-key:
default: true
description: |
If true, this cache bucket will only apply to jobs within the same branch.
type: boolean
no_output_timeout:
default: 10m
description: Elapsed time the command can run without output.
type: string
persist-to-workspace:
default: false
description: Whether to persist the build output to workspace.
type: boolean
project-path:
default: .
description: |
Enter the relative path of your Unity project.
This should be the directory that has an "Assets" folder inside it.
type: string
step-name:
default: Build the project
description: |
Specify a custom step name for this command, if desired.
type: string
store-artifacts:
default: true
description: |
Whether to store the build output.
If left to "false" you won't be able to download the build from the job's artifacts.
type: boolean
steps:
- run:
command: |
#!/usr/bin/env bash
# shellcheck disable=SC2034
readonly base_dir="${CIRCLE_WORKING_DIRECTORY/\~/$HOME}"
readonly unity_project_full_path="$base_dir/$PARAM_PROJECT_PATH"
# Import "utils.sh".
eval "$SCRIPT_UTILS"
# Detect host OS.
detect-os
# Copy builder to project directory if a custom isn't specified.
build_method="$PARAM_BUILD_METHOD"
if [ -z "$PARAM_BUILD_METHOD" ]; then
printf '%s\n' "The \"build-method\" parameter is empty. Falling back to the default build script."
mkdir -p "$unity_project_full_path/Assets/Editor/"
printf '%s\n' "$DEPENDENCY_UNITY_BUILDER" > "$unity_project_full_path/Assets/Editor/BuildCommand.cs"
build_method="BuildCommand.PerformBuild"
fi
# Expand custom parameters, if any.
custom_parameters="$(eval echo "$PARAM_CUSTOM_PARAMETERS")"
# If "build_name" is blank, use the build target.
if [ -z "$PARAM_BUILD_NAME" ]; then PARAM_BUILD_NAME="$PARAM_BUILD_TARGET"; fi
if [ "$PLATFORM" = "linux" ]; then eval "$SCRIPT_BUILD_LINUX";
elif [ "$PLATFORM" = "macos" ]; then eval "$SCRIPT_BUILD_MACOS";
elif [ "$PLATFORM" = "windows" ]; then eval "$SCRIPT_BUILD_WINDOWS";
fi
environment:
DEPENDENCY_UNITY_BUILDER: "using UnityEditor;\nusing System.Linq;\nusing System;\nusing System.IO;\n\nstatic class BuildCommand\n{\n private const string KEYSTORE_PASS = \"KEYSTORE_PASS\";\n private const string KEY_ALIAS_PASS = \"KEY_ALIAS_PASS\";\n private const string KEY_ALIAS_NAME = \"KEY_ALIAS_NAME\";\n private const string KEYSTORE = \"keystore.keystore\";\n private const string BUILD_OPTIONS_ENV_VAR = \"BuildOptions\";\n private const string ANDROID_BUNDLE_VERSION_CODE = \"VERSION_BUILD_VAR\";\n private const string ANDROID_APP_BUNDLE = \"BUILD_APP_BUNDLE\";\n private const string SCRIPTING_BACKEND_ENV_VAR = \"SCRIPTING_BACKEND\";\n private const string VERSION_NUMBER_VAR = \"VERSION_NUMBER_VAR\";\n private const string VERSION_iOS = \"VERSION_BUILD_VAR\";\n \n static string GetArgument(string name)\n {\n string[] args = Environment.GetCommandLineArgs();\n for (int i = 0; i < args.Length; i++)\n {\n if (args[i].Contains(name))\n {\n return args[i + 1];\n }\n }\n return null;\n }\n\n static string[] GetEnabledScenes()\n {\n return (\n from scene in EditorBuildSettings.scenes\n where scene.enabled\n where !string.IsNullOrEmpty(scene.path)\n select scene.path\n ).ToArray();\n }\n\n static BuildTarget GetBuildTarget()\n {\n string buildTargetName = GetArgument(\"customBuildTarget\");\n Console.WriteLine(\":: Received customBuildTarget \" + buildTargetName);\n\n if (buildTargetName.ToLower() == \"android\")\n {\n#if !UNITY_5_6_OR_NEWER\n\t\t\t// https://issuetracker.unity3d.com/issues/buildoptions-dot-acceptexternalmodificationstoplayer-causes-unityexception-unknown-project-type-0\n\t\t\t// Fixed in Unity 5.6.0\n\t\t\t// side effect to fix android build system:\n\t\t\tEditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Internal;\n#endif\n }\n\n if (buildTargetName.TryConvertToEnum(out BuildTarget target))\n return target;\n\n Console.WriteLine($\":: {nameof(buildTargetName)} \\\"{buildTargetName}\\\" not defined on enum {nameof(BuildTarget)}, using {nameof(BuildTarget.NoTarget)} enum to build\");\n\n return BuildTarget.NoTarget;\n }\n\n static string GetBuildPath()\n {\n string buildPath = GetArgument(\"customBuildPath\");\n Console.WriteLine(\":: Received customBuildPath \" + buildPath);\n if (buildPath == \"\")\n {\n throw new Exception(\"customBuildPath argument is missing\");\n }\n return buildPath;\n }\n\n static string GetBuildName()\n {\n string buildName = GetArgument(\"customBuildName\");\n Console.WriteLine(\":: Received customBuildName \" + buildName);\n if (buildName == \"\")\n {\n throw new Exception(\"customBuildName argument is missing\");\n }\n return buildName;\n }\n\n static string GetFixedBuildPath(BuildTarget buildTarget, string buildPath, string buildName)\n {\n if (buildTarget.ToString().ToLower().Contains(\"windows\")) {\n buildName += \".exe\";\n } else if (buildTarget == BuildTarget.Android) {\n#if UNITY_2018_3_OR_NEWER\n buildName += EditorUserBuildSettings.buildAppBundle ? \".aab\" : \".apk\";\n#else\n buildName += \".apk\";\n#endif\n }\n return buildPath + buildName;\n }\n\n static BuildOptions GetBuildOptions()\n {\n if (TryGetEnv(BUILD_OPTIONS_ENV_VAR, out string envVar)) {\n string[] allOptionVars = envVar.Split(',');\n BuildOptions allOptions = BuildOptions.None;\n BuildOptions option;\n string optionVar;\n int length = allOptionVars.Length;\n\n Console.WriteLine($\":: Detecting {BUILD_OPTIONS_ENV_VAR} env var with {length} elements ({envVar})\");\n\n for (int i = 0; i < length; i++) {\n optionVar = allOptionVars[i];\n\n if (optionVar.TryConvertToEnum(out option)) {\n allOptions |= option;\n }\n else {\n Console.WriteLine($\":: Cannot convert {optionVar} to {nameof(BuildOptions)} enum, skipping it.\");\n }\n }\n\n return allOptions;\n }\n\n return BuildOptions.None;\n }\n\n // https://stackoverflow.com/questions/1082532/how-to-tryparse-for-enum-value\n static bool TryConvertToEnum<TEnum>(this string strEnumValue, out TEnum value)\n {\n if (!Enum.IsDefined(typeof(TEnum), strEnumValue))\n {\n value = default;\n return false;\n }\n\n value = (TEnum)Enum.Parse(typeof(TEnum), strEnumValue);\n return true;\n }\n\n static bool TryGetEnv(string key, out string value)\n {\n value = Environment.GetEnvironmentVariable(key);\n return !string.IsNullOrEmpty(value);\n }\n\n static void SetScriptingBackendFromEnv(BuildTarget platform) {\n var targetGroup = BuildPipeline.GetBuildTargetGroup(platform);\n if (TryGetEnv(SCRIPTING_BACKEND_ENV_VAR, out string scriptingBackend)) {\n if (scriptingBackend.TryConvertToEnum(out ScriptingImplementation backend)) {\n Console.WriteLine($\":: Setting ScriptingBackend to {backend}\");\n PlayerSettings.SetScriptingBackend(targetGroup, backend);\n } else {\n string possibleValues = string.Join(\", \", Enum.GetValues(typeof(ScriptingImplementation)).Cast<ScriptingImplementation>());\n throw new Exception($\"Could not find '{scriptingBackend}' in ScriptingImplementation enum. Possible values are: {possibleValues}\");\n }\n } else {\n var defaultBackend = PlayerSettings.GetDefaultScriptingBackend(targetGroup);\n Console.WriteLine($\":: Using project's configured ScriptingBackend (should be {defaultBackend} for targetGroup {targetGroup}\");\n }\n }\n\n static void PerformBuild()\n {\n var buildTarget = GetBuildTarget();\n\n Console.WriteLine(\":: Performing build\");\n if (TryGetEnv(VERSION_NUMBER_VAR, out var bundleVersionNumber))\n {\n if (buildTarget == BuildTarget.iOS)\n {\n bundleVersionNumber = GetIosVersion();\n }\n Console.WriteLine($\":: Setting bundleVersionNumber to '{bundleVersionNumber}' (Length: {bundleVersionNumber.Length})\");\n PlayerSettings.bundleVersion = bundleVersionNumber;\n }\n\n if (buildTarget == BuildTarget.Android) {\n HandleAndroidAppBundle();\n HandleAndroidBundleVersionCode();\n HandleAndroidKeystore();\n }\n\n var buildPath = GetBuildPath();\n var buildName = GetBuildName();\n var buildOptions = GetBuildOptions();\n var fixedBuildPath = GetFixedBuildPath(buildTarget, buildPath, buildName);\n\n SetScriptingBackendFromEnv(buildTarget);\n\n var buildReport = BuildPipeline.BuildPlayer(GetEnabledScenes(), fixedBuildPath, buildTarget, buildOptions);\n\n if (buildReport.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded)\n throw new Exception($\"Build ended with {buildReport.summary.result} status\");\n\n Console.WriteLine(\":: Done with build\");\n }\n\n private static void HandleAndroidAppBundle()\n {\n if (TryGetEnv(ANDROID_APP_BUNDLE, out string value))\n {\n#if UNITY_2018_3_OR_NEWER\n if (bool.TryParse(value, out bool buildAppBundle))\n {\n EditorUserBuildSettings.buildAppBundle = buildAppBundle;\n Console.WriteLine($\":: {ANDROID_APP_BUNDLE} env var detected, set buildAppBundle to {value}.\");\n }\n else\n {\n Console.WriteLine($\":: {ANDROID_APP_BUNDLE} env var detected but the value \\\"{value}\\\" is not a boolean.\");\n }\n#else\n Console.WriteLine($\":: {ANDROID_APP_BUNDLE} env var detected but does not work with lower Unity version than 2018.3\");\n#endif\n }\n }\n\n private static void HandleAndroidBundleVersionCode()\n {\n if (TryGetEnv(ANDROID_BUNDLE_VERSION_CODE, out string value))\n {\n if (int.TryParse(value, out int version))\n {\n PlayerSettings.Android.bundleVersionCode = version;\n Console.WriteLine($\":: {ANDROID_BUNDLE_VERSION_CODE} env var detected, set the bundle version code to {value}.\");\n }\n else\n Console.WriteLine($\":: {ANDROID_BUNDLE_VERSION_CODE} env var detected but the version value \\\"{value}\\\" is not an integer.\");\n }\n }\n\n private static string GetIosVersion()\n {\n if (TryGetEnv(VERSION_iOS, out string value))\n {\n if (int.TryParse(value, out int version))\n {\n Console.WriteLine($\":: {VERSION_iOS} env var detected, set the version to {value}.\");\n return version.ToString();\n }\n else\n Console.WriteLine($\":: {VERSION_iOS} env var detected but the version value \\\"{value}\\\" is not an integer.\");\n }\n\n throw new ArgumentNullException(nameof(value), $\":: Error finding {VERSION_iOS} env var\");\n }\n\n private static void HandleAndroidKeystore()\n {\n#if UNITY_2019_1_OR_NEWER\n PlayerSettings.Android.useCustomKeystore = false;\n#endif\n\n if (!File.Exists(KEYSTORE)) {\n Console.WriteLine($\":: {KEYSTORE} not found, skipping setup, using Unity's default keystore\");\n return; \n }\n\n PlayerSettings.Android.keystoreName = KEYSTORE;\n\n string keystorePass;\n string keystoreAliasPass;\n\n if (TryGetEnv(KEY_ALIAS_NAME, out string keyaliasName)) {\n PlayerSettings.Android.keyaliasName = keyaliasName;\n Console.WriteLine($\":: using ${KEY_ALIAS_NAME} env var on PlayerSettings\");\n } else {\n Console.WriteLine($\":: ${KEY_ALIAS_NAME} env var not set, using Project's PlayerSettings\");\n }\n\n if (!TryGetEnv(KEYSTORE_PASS, out keystorePass)) {\n Console.WriteLine($\":: ${KEYSTORE_PASS} env var not set, skipping setup, using Unity's default keystore\");\n return;\n }\n\n if (!TryGetEnv(KEY_ALIAS_PASS, out keystoreAliasPass)) {\n Console.WriteLine($\":: ${KEY_ALIAS_PASS} env var not set, skipping setup, using Unity's default keystore\");\n return;\n }\n#if UNITY_2019_1_OR_NEWER\n PlayerSettings.Android.useCustomKeystore = true;\n#endif\n PlayerSettings.Android.keystorePass = keystorePass;\n PlayerSettings.Android.keyaliasPass = keystoreAliasPass;\n }\n}\n"
PARAM_BUILD_METHOD: << parameters.build-method >>
PARAM_BUILD_NAME: << parameters.build-name >>
PARAM_BUILD_TARGET: << parameters.build-target >>
PARAM_COMPRESS: << parameters.compress >>
PARAM_CUSTOM_PARAMETERS: << parameters.custom-parameters >>
PARAM_PROJECT_PATH: << parameters.project-path >>
SCRIPT_BUILD_LINUX: |
#!/bin/false
# shellcheck shell=bash
# shellcheck disable=SC2048,SC2154,SC2086
readonly build_path="$unity_project_full_path/Builds/$PARAM_BUILD_TARGET/"
mkdir -p "$build_path"
set -x
${UNITY_EXECUTABLE:-xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' unity-editor} \
-projectPath "$unity_project_full_path" \
-quit \
-batchmode \
-nographics \
-buildTarget "$PARAM_BUILD_TARGET" \
-customBuildTarget "$PARAM_BUILD_TARGET" \
-customBuildName "$PARAM_BUILD_NAME" \
-customBuildPath "$build_path" \
-executeMethod "$build_method" \
-logFile /dev/stdout \
$custom_parameters # Needs to be unquoted. Otherwise it will be treated as a single parameter.
set +x
if [ "$PARAM_COMPRESS" -eq 1 ]; then
printf '%s\n' 'Compressing build artifacts...'
# Compress artifacts to store them in the artifacts bucket.
tar -czf "$base_dir/$PARAM_BUILD_TARGET.tar.gz" -C "$build_path" .
fi
SCRIPT_BUILD_MACOS: |-
#!/bin/false
# shellcheck shell=bash
# shellcheck disable=SC2048,SC2154,SC2086
readonly build_path="$unity_project_full_path/Builds/$PARAM_BUILD_TARGET"
mkdir -p "$build_path"
set -x
# Build the project
"$UNITY_EDITOR_PATH" \
-quit \
-batchmode \
-nographics \
-projectPath "$unity_project_full_path" \
-buildTarget "$PARAM_BUILD_TARGET" \
-customBuildTarget "$PARAM_BUILD_TARGET" \
-customBuildPath "$build_path/$PARAM_BUILD_NAME" \
-executeMethod "$build_method" \
-buildVersion "1.0.0" \
-logfile /dev/stdout \
$custom_parameters # Needs to be unquoted. Otherwise it will be treated as a single parameter.
set +x
if [ "$PARAM_COMPRESS" -eq 1 ]; then
printf '%s\n' 'Compressing build artifacts...'
# Compress artifacts to store them in the artifacts bucket.
tar -czf "$base_dir/$PARAM_BUILD_TARGET.tar.gz" -C "$build_path" .
fi
SCRIPT_BUILD_WINDOWS: |
#!/bin/false
# shellcheck shell=bash
# shellcheck disable=SC2016,SC2154
trap_exit() {
local exit_status="$?"
if [ "$exit_status" -ne 0 ]; then
printf '%s\n' 'The script did not complete successfully.'
printf '%s\n' "Removing the container \"$CONTAINER_NAME\"."
docker rm -f "$CONTAINER_NAME" &> /dev/null || true
exit "$exit_status"
fi
}
trap trap_exit EXIT
# Add the build target and build name in the environment variables.
docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_NAME','$PARAM_BUILD_NAME', [System.EnvironmentVariableTarget]::Machine)"
docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_TARGET','$PARAM_BUILD_TARGET', [System.EnvironmentVariableTarget]::Machine)"
docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('BUILD_METHOD','$build_method', [System.EnvironmentVariableTarget]::Machine)"
docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('CUSTOM_PARAMS','$custom_parameters', [System.EnvironmentVariableTarget]::Machine)"
build_args=(
'-batchmode'
'-quit'
'-nographics'
'-projectPath $Env:PROJECT_PATH'
'-buildTarget $Env:BUILD_TARGET'
'-customBuildTarget $Env:BUILD_TARGET'
'-customBuildName $Env:BUILD_NAME'
'-customBuildPath "C:/build/"'
'-executeMethod $Env:BUILD_METHOD'
)
[ -n "$custom_parameters" ] && build_args+=( '$Env:CUSTOM_PARAMS.split()' )
# Build the project
# Versioning of the project needs work. This is how it's done in the GHA:
# https://github.com/game-ci/unity-builder/blob/main/src/model/versioning.ts
set -x
docker exec "$CONTAINER_NAME" powershell "& 'C:\Program Files\Unity\Hub\Editor\*\Editor\Unity.exe' ${build_args[*]} -logfile | Out-Host"
exit_code="$?"
set +x
if [ "$exit_code" -ne 0 ]; then
printf '%s\n' "Failed to build the project."
printf '%s\n' "Please try again, open an issue or reach out to us on Discord."
exit "$exit_code"
fi
printf '%s\n' "Build completed successfully:"
ls -la "$base_dir/build"
if [ "$PARAM_COMPRESS" -eq 1 ]; then
printf '%s\n' "Compressing artifacts..."
tar -czf "$base_dir/${PARAM_BUILD_TARGET}.tar.gz" -C "$base_dir/build" .
printf '%s\n' "Done."
ls -la "$base_dir"
fi
SCRIPT_UTILS: "#!/bin/false\n# shellcheck shell=bash\n# shellcheck disable=SC2154\n\ndetect-os() {\n local detected_platform\n \n detected_platform=\"$(uname -s | tr '[:upper:]' '[:lower:]')\"\n\n case \"$detected_platform\" in\n linux*)\n printf '%s\\n' \"Detected OS: Linux.\"\n PLATFORM=linux\n ;;\n darwin*)\n printf '%s\\n' \"Detected OS: macOS.\"\n PLATFORM=macos\n ;;\n msys*|cygwin*)\n printf '%s\\n' \"Detected OS: Windows.\"\n PLATFORM=windows\n ;;\n *)\n printf '%s\\n' \"Unsupported OS: \\\"$platform\\\".\"\n exit 1\n ;;\n esac\n\n export readonly PLATFORM\n}"
name: << parameters.step-name >>
no_output_timeout: << parameters.no_output_timeout >>
- save_cache:
key: unity-deps-{{ arch }}-<< parameters.cache-version >>-<<# parameters.include-branch-in-cache-key >>{{ .Branch }}-<</ parameters.include-branch-in-cache-key >>{{ checksum "<< parameters.project-path >>/Packages/packages-lock.json" }}
paths:
- << parameters.project-path >>/Library/
- when:
condition:
and:
- << parameters.store-artifacts >>
- << parameters.compress >>
steps:
- store_artifacts:
path: << parameters.build-target >>.tar.gz
- when:
condition:
and:
- << parameters.store-artifacts >>
- not: << parameters.compress >>
steps:
- store_artifacts:
path: << parameters.project-path >>/Builds/<< parameters.build-target >>
- when:
condition:
and:
- << parameters.persist-to-workspace >>
- << parameters.compress >>
steps:
- persist_to_workspace:
paths:
- << parameters.build-target >>.tar.gz
root: .
- when:
condition:
and:
- << parameters.persist-to-workspace >>
- not: << parameters.compress >>
steps:
- persist_to_workspace:
paths:
- Builds/<< parameters.build-target >>
root: << parameters.project-path >>
prepare-env:
description: |
This command prepares the environment for testing or building an Unity project.
parameters:
cache-version:
default: v1
description: |
Change the default cache version if you need to clear the cache for any reason.
type: string
include-branch-in-cache-key:
default: true
description: |
If true, this cache bucket will only apply to jobs within the same branch.
type: boolean
no_output_timeout:
default: 10m
description: Elapsed time the command can run without output.
type: string
project-path:
default: .
description: |
Enter the path of your Unity project.
This should be the directory that has an "Assets" folder inside it.
type: string
unity-license-var-name:
default: UNITY_ENCODED_LICENSE
description: |
Enter the name of the environment variable containing your Unity license file encoded in base64.
Required if you have a Personal license.
type: env_var_name
unity-password-var-name:
default: UNITY_PASSWORD
description: |
Enter the name of the environment variable containing your Unity password.
type: env_var_name
unity-serial-var-name:
default: UNITY_SERIAL
description: |
Enter the name of the environment variable containing your Unity serial number.
Required if you have a Plus or Pro license.
type: env_var_name
unity-username-var-name:
default: UNITY_USERNAME
description: |
Enter the name of the environment variable containing your Unity username.
type: env_var_name
steps:
- restore_cache:
keys:
- unity-deps-{{ arch }}-<< parameters.cache-version >>-<<# parameters.include-branch-in-cache-key >>{{ .Branch }}-<</ parameters.include-branch-in-cache-key >>{{ checksum "<< parameters.project-path >>/Packages/packages-lock.json" }}
- unity-deps-{{ arch }}-<< parameters.cache-version >>-<<# parameters.include-branch-in-cache-key >>{{ .Branch }}<</ parameters.include-branch-in-cache-key >>
- run:
command: |
#!/usr/bin/env bash
# shellcheck disable=SC2034
readonly base_dir="${CIRCLE_WORKING_DIRECTORY/\~/$HOME}"
readonly unity_project_full_path="$base_dir/$PARAM_PROJECT_PATH"
# Import "utils.sh".
eval "$SCRIPT_UTILS"
# Detect host OS.
detect-os
# Expand environment name variable parameters.
readonly unity_username="${!PARAM_UNITY_USERNAME_VAR_NAME}"
readonly unity_password="${!PARAM_UNITY_PASSWORD_VAR_NAME}"
readonly unity_serial="${!PARAM_UNITY_SERIAL_VAR_NAME}"
readonly unity_encoded_license="${!PARAM_UNITY_LICENSE_VAR_NAME}"
if [ "$PLATFORM" = "linux" ]; then eval "$SCRIPT_PREPARE_ENV_LINUX";
elif [ "$PLATFORM" = "macos" ]; then eval "$SCRIPT_PREPARE_ENV_MACOS";
elif [ "$PLATFORM" = "windows" ]; then eval "$SCRIPT_PREPARE_ENV_WINDOWS";
fi
environment:
PARAM_PROJECT_PATH: << parameters.project-path >>
PARAM_UNITY_LICENSE_VAR_NAME: << parameters.unity-license-var-name >>
PARAM_UNITY_PASSWORD_VAR_NAME: << parameters.unity-password-var-name >>
PARAM_UNITY_SERIAL_VAR_NAME: << parameters.unity-serial-var-name >>
PARAM_UNITY_USERNAME_VAR_NAME: << parameters.unity-username-var-name >>
SCRIPT_PREPARE_ENV_LINUX: |
#!/bin/false
# shellcheck shell=bash
# shellcheck disable=SC2154
create_manual_activation_file() {
unity-editor \
-batchmode \
-nographics \
-createManualActivationFile \
-quit \
-logfile /dev/null
# Check if license file was created successfully.
if ls Unity_v*.alf &> /dev/null; then return 0; else return 1; fi
}
resolve_unity_license() {
if [ -n "$unity_encoded_license" ]; then
# Decode Personal Unity License File.
unity_license=$(printf '%s\n' "$unity_encoded_license" | base64 --decode)
elif [ -n "$unity_username" ] && [ -n "$unity_password" ] && [ -n "$unity_serial" ]; then
# Generate Plus or Pro Unity License File.
unity-editor \
-logFile /dev/stdout \
-batchmode \
-nographics \
-quit \
-username "$unity_username" \
-password "$unity_password" \
-serial "$unity_serial"
if [ -e "/root/.local/share/unity3d/Unity/Unity_lic.ulf" ]; then
unity_license="$(cat /root/.local/share/unity3d/Unity/Unity_lic.ulf)"
else
printf '%s\n' "Failed to generate Unity license file."
printf '%s\n' "Make sure you have entered the correct username, password and serial and try again."
printf '%s\n' "If you are still having problems, please open an issue."
printf '%s\n' "See the docs for more details: https://game.ci/docs/circleci/activation#professional-license"
return 1
fi
else
printf '%s\n' "If you own a Personal Unity License File (.ulf), please provide it as a base64 encoded string."
printf '%s\n' "If you own a Plus or Pro Unity license, please provide your username, password and serial."
printf '%s\n' "See the docs for more details: https://game.ci/docs/circleci/activation"
if create_manual_activation_file; then
printf '%s\n' "Should you require a new Personal Activation License File (.alf), rerun the job with SSH and you will find it at \"${base_dir}/$(ls Unity_v*)\""
fi
return 1
fi
}
download_and_prepare_before_script() {
local repo_url="$1"
local ref="$2"
local file_path="$3"
local output_path="$4"
# Validate input parameters
if [[ -z "$repo_url" || -z "$ref" || -z "$file_path" || -z "$output_path" ]]; then
printf 'Error: Missing required parameters\n' >&2
return 1
fi
# Construct the full URL
local full_url="$repo_url/-/raw/$ref/$file_path"
# Use curl to download the file
curl --silent --location \
--request GET \
--url "$full_url" \
--output "$output_path" \
--fail \
|| { printf 'Error: Failed to download script from %s\n' "$full_url" >&2; return 1; }
# Verify downloaded file
if [[ ! -s "$output_path" ]]; then
printf 'Error: Downloaded file is empty or missing\n' >&2
return 1
fi
# Make the script executable
chmod +x "$output_path"
return 0
}
# Check if serial or encoded license was provided.
# If the latter, extract the serial from the license.
if ! resolve_unity_license; then
printf '%s\n' "Failed to find the serial or parse it from the Unity license."
printf '%s\n' "Please try again or open an issue."
exit 1
fi
# Define variables
repo_url="https://gitlab.com/game-ci/unity3d-gitlab-ci-example"
ref="173a67e" # v3.0.1
file_path="ci/before_script.sh"
before_script="$base_dir/before_script.sh"
# Download and prepare the before_script file
download_and_prepare_before_script "$repo_url" "$ref" "$file_path" "$before_script"
# Nomenclature required by the script.
readonly UNITY_LICENSE="$unity_license"
export UNITY_LICENSE
# Run the test script.
# shellcheck source=/dev/null
source "$before_script"
SCRIPT_PREPARE_ENV_MACOS: "#!/bin/false\n# shellcheck shell=bash\n# shellcheck disable=SC2154\n\nreadonly unity_hub_path=\"/Applications/Unity Hub.app/Contents/MacOS/Unity Hub\"\nreadonly unity_editor_path=\"/Applications/Unity/Hub/Editor/$UNITY_EDITOR_VERSION/Unity.app/Contents/MacOS/Unity\"\n\nprintf '%s\\n' \"export UNITY_HUB_PATH=\\\"$unity_hub_path\\\"\" >> \"$BASH_ENV\"\nprintf '%s\\n' \"export UNITY_EDITOR_PATH=$unity_editor_path\" >> \"$BASH_ENV\"\n\ncheck_and_install_unity_hub() {\n if [ ! -f \"$unity_hub_path\" ]; then\n printf '%s\\n' \"Could not find Unity Hub at \\\"$unity_hub_path\\\".\"\n printf '%s\\n' \"Installing it with brew...\"\n\n brew install --cask unity-hub\n\n if [ -f \"$unity_hub_path\" ]; then\n printf '%s\\n' \"Unity Hub installed successfully.\"\n\n else\n printf '%s\\n' \"Could not install the Unity Hub.\"\n printf '%s\\n' \"Please try again or open an issue.\"\n return 1\n fi\n fi\n\n return 0\n}\n\ncheck_and_install_unity_editor() {\n if [ ! -f \"$unity_editor_path\" ]; then\n printf '%s\\n' \"Could not find the Unity Editor at \\\"$unity_editor_path\\\".\"\n printf '%s\\n' \"Installing it with the Unity Hub...\"\n\n if check_and_install_unity_hub; then\n\n if ! command -v npm &> /dev/null; then\n printf '%s\\n' \"npm is required to fetch the Unity Editor changeset.\"\n printf '%s\\n' \"Please install it and try again.\"\n return 1\n fi\n\n changeset=\"$(npx unity-changeset \"$UNITY_EDITOR_VERSION\")\"\n\n set -x\n \"$unity_hub_path\" -- --headless install --version \"$UNITY_EDITOR_VERSION\" --changeset \"$changeset\" --module mac-il2cpp --childModules\n set +x\n\n if [ -f \"$unity_editor_path\" ]; then\n printf '%s\\n' \"Unity Editor installed successfully.\"\n\n else\n printf '%s\\n' \"Could not install the Unity Editor.\"\n printf '%s\\n' \"Please try again or open an issue.\"\n return 1\n fi\n else\n printf '%s\\n' \"Could not install the Editor because Unity Hub is not installed.\"\n return 1\n fi\n fi\n\n return 0\n}\n\nresolve_unity_serial() {\n if [ -n \"$unity_username\" ] && [ -n \"$unity_password\" ]; then\n # Serial provided.\n if [ -n \"$unity_serial\" ]; then\n printf '%s\\n' \"Detected Unity serial.\"\n readonly resolved_unity_serial=\"$unity_serial\"\n\n # License provided.\n elif [ -n \"$unity_encoded_license\" ]; then\n printf '%s\\n' \"No serial detected. Extracting it from the encoded license.\"\n \n if ! extract_serial_from_license; then\n printf '%s\\n' \"Failed to parse the serial from the Unity license.\"\n printf '%s\\n' \"Please try again or open an issue.\"\n printf '%s\\n' \"See the docs for more details: https://game.ci/docs/circleci/activation#personal-license\"\n return 1\n \n else\n readonly resolved_unity_serial=\"$decoded_unity_serial\"\n fi\n\n # Nothing provided.\n else\n printf '%s\\n' \"No serial or encoded license found.\"\n printf '%s\\n' \"Please run the script again with a serial or encoded license file.\"\n printf '%s\\n' \"See the docs for more details: https://game.ci/docs/circleci/activation\"\n return 1\n fi\n fi\n\n return 0\n}\n\nextract_serial_from_license() {\n # Fix locale setting in PERL.\n # https://stackoverflow.com/a/7413863\n export LC_CTYPE=en_US.UTF-8\n export LC_ALL=en_US.UTF-8 \n\n local unity_license\n local developer_data\n local encoded_serial\n\n unity_license=\"$(base64 --decode \\<<< \"$unity_encoded_license\")\"\n developer_data=\"$(perl -nle 'print $& while m{<DeveloperData Value\\=\"\\K.*?(?=\"/>)}g' \\<<< \"$unity_license\")\"\n encoded_serial=\"$(cut -c 5- \\<<< \"$developer_data\")\"\n \n decoded_unity_serial=\"$(base64 --decode \\<<< \"$encoded_serial\")\"\n readonly decoded_unity_serial\n\n if [ -n \"$decoded_unity_serial\" ]; then return 0; else return 1; fi\n}\n\n# Install the Editor if not already installed.\nif ! check_and_install_unity_editor; then\n printf '%s\\n' \"Something went wrong.\"\n printf '%s\\n' \"Please try again or open an issue.\"\n exit 1\nfi\n\n# Check if serial or encoded license was provided.\n# If the latter, extract the serial from the license.\nif ! resolve_unity_serial; then\n printf '%s\\n' \"Failed to find the serial or parse it from the Unity license.\"\n printf '%s\\n' \"Please try again or open an issue.\"\n exit 1\nfi\n\n# If it doesn't exist, create folder for the Unity License File.\nreadonly unity_license_file_path=\"/Library/Application Support/Unity\"\nsudo mkdir -p \"$unity_license_file_path\"\nsudo chmod -R 777 \"$unity_license_file_path\"\n\n# Activate the Unity Editor.\nset -x\n\"$unity_editor_path\" \\\n -batchmode \\\n -quit \\\n -nographics \\\n -username \"$unity_username\" \\\n -password \"$unity_password\" \\\n -serial \"$resolved_unity_serial\" \\\n -logfile /dev/stdout\nset +x"
SCRIPT_PREPARE_ENV_WINDOWS: |
#!/bin/false
# shellcheck shell=bash
# shellcheck disable=SC2154
trap_exit() {
local exit_status="$?"
if [ "$exit_status" -ne 0 ]; then
printf '%s\n' 'The script did not complete successfully.'
printf '%s\n' "Removing the container \"$container_name\"."
docker rm -f "$container_name" &> /dev/null || true
exit "$exit_status"
fi
}
trap trap_exit EXIT
resolve_unity_serial() {
local exit_code=0
if [ -n "$unity_username" ] && [ -n "$unity_password" ]; then
# Serial provided.
if [ -n "$unity_serial" ]; then
printf '%s\n' "Detected Unity serial."
readonly resolved_unity_serial="$unity_serial"
# License provided.
elif [ -n "$unity_encoded_license" ]; then
printf '%s\n' "No serial detected. Extracting it from the encoded license."
if ! extract_serial_from_license; then
printf '%s\n' "Failed to parse the serial from the Unity license."
printf '%s\n' "Please try again or open an issue."
printf '%s\n' "See the docs for more details: https://game.ci/docs/circleci/activation#personal-license"
exit_code=1
else
readonly resolved_unity_serial="$decoded_unity_serial"
fi
# Nothing provided.
else
printf '%s\n' "No serial or encoded license found."
printf '%s\n' "Please run the script again with a serial or encoded license file."
printf '%s\n' "See the docs for more details: https://game.ci/docs/circleci/activation"
exit_code=1
fi
fi
return "$exit_code"
}
extract_serial_from_license() {
export LANG=C.UTF-8
local unity_license
local developer_data
local encoded_serial
unity_license="$(base64 --decode \<<< "$unity_encoded_license")"
developer_data="$(grep -oP '<DeveloperData Value\="\K.*?(?="/>)' \<<< "$unity_license")"
encoded_serial="$(cut -c 5- \<<< "$developer_data")"
decoded_unity_serial="$(base64 --decode \<<< "$encoded_serial")"
readonly decoded_unity_serial
if [ -n "$decoded_unity_serial" ]; then return 0; else return 1; fi
}
# Install the Windows 10 SDK.
choco upgrade windows-sdk-10.1 visualstudio2022-workload-vctools --no-progress -y
# Extract the Windows SDK registry key.
mkdir -p "$base_dir/regkeys"
powershell "reg export HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\\"Microsoft SDKs\"\\Windows\\v10.0 $base_dir/regkeys/winsdk.reg /y"
readonly container_name="${CIRCLE_PROJECT_REPONAME}-${CIRCLE_BUILD_NUM}"
printf '%s\n' "export CONTAINER_NAME=$container_name" >> "$BASH_ENV"
# Delete any existing containers.
if docker ps -a | grep -wq "$container_name"; then
docker rm -f "$container_name"
fi
# Check if serial or encoded license was provided.
# If the latter, extract the serial from the license.
if ! resolve_unity_serial; then
printf '%s\n' "Failed to find the serial or parse it from the Unity license."
printf '%s\n' "Please try again or open an issue."
exit 1
fi
# Create folders to store artifacts.
mkdir -p "$base_dir/build" || { printf '%s\n' "Unable to create the build directory"; exit 1; }
mkdir -p "$base_dir/test" || { printf '%s\n' "Unable to create the test directory"; exit 1; }
set -x
# Run the container and prevent it from exiting.
# shellcheck disable=SC2140
docker run -dit \
--name "$container_name" \
--env PROJECT_PATH="C:/unity_project" \
--env UNITY_USERNAME="$unity_username" \
--env UNITY_PASSWORD="$unity_password" \
--env UNITY_SERIAL="$resolved_unity_serial" \
--volume "$unity_project_full_path":C:/unity_project \
--volume "$base_dir"/regkeys:"C:/regkeys" \
--volume "$base_dir"/build:"C:/build" \
--volume "$base_dir"/test:"C:/test" \
--volume "C:/Program Files (x86)/Microsoft Visual Studio":"C:/Program Files (x86)/Microsoft Visual Studio" \
--volume "C:/Program Files (x86)/Windows Kits":"C:/Program Files (x86)/Windows Kits" \
--volume "C:/ProgramData/Microsoft/VisualStudio":"C:/ProgramData/Microsoft/VisualStudio" \
"unityci/editor:windows-${GAMECI_EDITOR_VERSION}-${GAMECI_TARGET_PLATFORM}-2" \
powershell
set +x
# Register the Windows SDK and VCC Tools.
docker exec "$container_name" powershell 'reg import C:\regkeys\winsdk.reg'
docker exec "$container_name" powershell 'regsvr32 /s C:\ProgramData\Microsoft\VisualStudio\Setup\x64\Microsoft.VisualStudio.Setup.Configuration.Native.dll'
# Activate Unity
docker exec "$container_name" powershell '& "C:\Program Files\Unity\Hub\Editor\*\Editor\Unity.exe" -batchmode -quit -nographics -username $Env:UNITY_USERNAME -password $Env:UNITY_PASSWORD -serial $Env:UNITY_SERIAL -logfile | Out-Host'
SCRIPT_UTILS: "#!/bin/false\n# shellcheck shell=bash\n# shellcheck disable=SC2154\n\ndetect-os() {\n local detected_platform\n \n detected_platform=\"$(uname -s | tr '[:upper:]' '[:lower:]')\"\n\n case \"$detected_platform\" in\n linux*)\n printf '%s\\n' \"Detected OS: Linux.\"\n PLATFORM=linux\n ;;\n darwin*)\n printf '%s\\n' \"Detected OS: macOS.\"\n PLATFORM=macos\n ;;\n msys*|cygwin*)\n printf '%s\\n' \"Detected OS: Windows.\"\n PLATFORM=windows\n ;;\n *)\n printf '%s\\n' \"Unsupported OS: \\\"$platform\\\".\"\n exit 1\n ;;\n esac\n\n export readonly PLATFORM\n}"
name: Prepare the environment
no_output_timeout: << parameters.no_output_timeout >>
return-license:
description: |
This command returns the license used to build or test the project.
parameters:
unity-password-var-name:
default: UNITY_PASSWORD
description: |
Enter the name of the environment variable containing your Unity password.
type: env_var_name
unity-username-var-name:
default: UNITY_USERNAME
description: |
Enter the name of the environment variable containing your Unity username.
type: env_var_name
steps:
- run:
command: |-
#!/usr/bin/env bash
# shellcheck disable=SC2034
readonly base_dir="${CIRCLE_WORKING_DIRECTORY/\~/$HOME}"
# Import "utils.sh".
eval "$SCRIPT_UTILS"
# Detect host OS.
detect-os
# Expand environment name variable parameters.
readonly unity_username="${!PARAM_UNITY_USERNAME_VAR_NAME}"
readonly unity_password="${!PARAM_UNITY_PASSWORD_VAR_NAME}"
if [ "$PLATFORM" = "linux" ]; then eval "$SCRIPT_RETURN_LICENSE_LINUX";
elif [ "$PLATFORM" = "macos" ]; then eval "$SCRIPT_RETURN_LICENSE_MACOS";
elif [ "$PLATFORM" = "windows" ]; then eval "$SCRIPT_RETURN_LICENSE_WINDOWS";
fi
environment:
PARAM_UNITY_PASSWORD_VAR_NAME: << parameters.unity-password-var-name >>
PARAM_UNITY_USERNAME_VAR_NAME: << parameters.unity-username-var-name >>
SCRIPT_RETURN_LICENSE_LINUX: |-
#!/bin/false
# shellcheck shell=bash
# shellcheck disable=SC2154
set -x
# Return license
unity-editor \
-quit \
-batchmode \
-nographics \
-returnlicense \
-username "$unity_username" \
-password "$unity_password" \
-logfile /dev/stdout
set +x
SCRIPT_RETURN_LICENSE_MACOS: |-
#!/bin/false
# shellcheck shell=bash
# shellcheck disable=SC2154
set -x
# Return license
"$UNITY_EDITOR_PATH" \
-quit \
-batchmode \
-nographics \
-returnlicense \
-username "$unity_username" \
-password "$unity_password" \
-logfile /dev/stdout
set +x
SCRIPT_RETURN_LICENSE_WINDOWS: |-
#!/bin/false
# shellcheck shell=bash
# shellcheck disable=SC2154
trap_exit() {
local exit_status="$?"
if [ "$exit_status" -ne 0 ]; then
printf '%s\n' 'The script did not complete successfully.'
printf '%s\n' "Removing the container \"$CONTAINER_NAME\"."
docker rm -f "$CONTAINER_NAME" &> /dev/null || true
exit "$exit_status"
fi
}
trap trap_exit EXIT
set -x
# Return license
docker exec "$CONTAINER_NAME" powershell '& "C:\Program Files\Unity\Hub\Editor\*\Editor\Unity.exe" -returnlicense -batchmode -quit -nographics -username $Env:UNITY_USERNAME -password $Env:UNITY_PASSWORD -logfile | Out-Host'
set +x
# Remove the container.
docker rm -f "$CONTAINER_NAME"
SCRIPT_UTILS: "#!/bin/false\n# shellcheck shell=bash\n# shellcheck disable=SC2154\n\ndetect-os() {\n local detected_platform\n \n detected_platform=\"$(uname -s | tr '[:upper:]' '[:lower:]')\"\n\n case \"$detected_platform\" in\n linux*)\n printf '%s\\n' \"Detected OS: Linux.\"\n PLATFORM=linux\n ;;\n darwin*)\n printf '%s\\n' \"Detected OS: macOS.\"\n PLATFORM=macos\n ;;\n msys*|cygwin*)\n printf '%s\\n' \"Detected OS: Windows.\"\n PLATFORM=windows\n ;;\n *)\n printf '%s\\n' \"Unsupported OS: \\\"$platform\\\".\"\n exit 1\n ;;\n esac\n\n export readonly PLATFORM\n}"
name: Return the Unity license
test:
description: |
This command tests an Unity project.
parameters:
cache-version:
default: v1
description: |
Change the default cache version if you need to clear the cache for any reason.
type: string
custom-parameters:
default: ""
description: |
Additional arguments for the Unity CLI.
Use it to pass arguments to Unity's test options. Environment variables are supported.
The parameters must be separated by space and must be in the format "-key value" or "-key" for booleans.
Example: '-testFilter "MyNamespace.Something.MyTest" -assemblyNames "MyUnitTestAssembly" -testCategory "Unit;Integration"'.
type: string
include-branch-in-cache-key:
default: true
description: |
If true, this cache bucket will only apply to jobs within the same branch.
type: boolean
no_output_timeout:
default: 10m
description: Elapsed time the command can run without output.
type: string
project-path:
default: .
description: |
Enter the relative path of your Unity project.
This should be the directory that has an "Assets" folder inside it.
type: string
step-name:
default: Run tests
description: |
Specify a custom step name for this command, if desired.
type: string
test-platform:
default: playmode
description: |
Specify the test platform to run tests on.
Valid values are "editmode", "playmode" and Unity's target builds.
More information can be found on: https://docs.unity3d.com/Packages/com.unity.test-framework@2.0/manual/reference-command-line.html
type: string
steps:
- run:
command: |
#!/usr/bin/env bash
# shellcheck disable=SC2034
readonly base_dir="${CIRCLE_WORKING_DIRECTORY/\~/$HOME}"
readonly unity_project_full_path="$base_dir/$PARAM_PROJECT_PATH"
# Import "utils.sh".
eval "$SCRIPT_UTILS"
# Detect host OS.
detect-os
# Expand custom parameters, if any.
custom_parameters="$(eval echo "$PARAM_CUSTOM_PARAMETERS")" && readonly custom_parameters
if [ "$PLATFORM" = "linux" ]; then eval "$SCRIPT_TEST_LINUX";
elif [ "$PLATFORM" = "macos" ]; then eval "$SCRIPT_TEST_MACOS";
elif [ "$PLATFORM" = "windows" ]; then eval "$SCRIPT_TEST_WINDOWS";
fi
environment:
DEPENDENCY_NUNIT_TRANSFORM: "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<xsl:stylesheet version=\"2.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n <xsl:output method=\"xml\" indent=\"yes\"/>\n\n <xsl:template match=\"/test-run\">\n <testsuites tests=\"{@testcasecount}\" failures=\"{@failed}\" disabled=\"{@skipped}\" time=\"{@duration}\">\n <xsl:apply-templates/>\n </testsuites>\n </xsl:template>\n\n <xsl:template match=\"test-suite\">\n <xsl:if test=\"test-case\">\n <testsuite tests=\"{@testcasecount}\" time=\"{@duration}\" errors=\"{@testcasecount - @passed - @skipped - @failed}\" failures=\"{@failed}\" skipped=\"{@skipped}\" timestamp=\"{@start-time}\">\n <xsl:attribute name=\"name\">\n <xsl:for-each select=\"ancestor-or-self::test-suite/@name\">\n <xsl:value-of select=\"concat(., '.')\"/>\n </xsl:for-each>\n </xsl:attribute>\n <xsl:apply-templates select=\"test-case\"/>\n </testsuite>\n <xsl:apply-templates select=\"test-suite\"/>\n </xsl:if>\n <xsl:if test=\"not(test-case)\">\n <xsl:apply-templates/>\n </xsl:if>\n </xsl:template>\n\n <xsl:template match=\"test-case\">\n <testcase name=\"{@name}\" assertions=\"{@asserts}\" time=\"{@duration}\" status=\"{@result}\" classname=\"{@classname}\">\n <xsl:if test=\"@runstate = 'Skipped' or @runstate = 'Ignored'\">\n <skipped/>\n </xsl:if>\n \n <xsl:apply-templates/>\n </testcase>\n </xsl:template>\n\n <xsl:template match=\"command-line\"/>\n <xsl:template match=\"settings\"/>\n\n <xsl:template match=\"output\">\n <system-out>\n <xsl:value-of select=\".\"/>\n </system-out>\n </xsl:template>\n\n <xsl:template match=\"stack-trace\">\n </xsl:template>\n\n <xsl:template match=\"test-case/failure\">\n <failure message=\"{./message}\">\n <xsl:value-of select=\"./stack-trace\"/>\n </failure>\n </xsl:template>\n\n <xsl:template match=\"test-suite/failure\"/>\n\n <xsl:template match=\"test-case/reason\">\n <skipped message=\"{./message}\"/>\n </xsl:template>\n \n <xsl:template match=\"test-case/assertions\">\n </xsl:template>\n\n <xsl:template match=\"test-suite/reason\"/>\n\n <xsl:template match=\"properties\"/>\n</xsl:stylesheet>\n\n"
PARAM_CUSTOM_PARAMETERS: << parameters.custom-parameters >>
PARAM_PROJECT_PATH: << parameters.project-path >>
PARAM_TEST_PLATFORM: << parameters.test-platform >>
SCRIPT_TEST_LINUX: |
#!/bin/false
# shellcheck shell=bash
# shellcheck disable=SC2154
parse_results_to_junit() {
# Intall dependencies for the JUnit parser.
apt-get update && apt-get install -y default-jre libsaxonb-java
# Parse Unity's results xml to JUnit format.
printf '%s\n' "$DEPENDENCY_NUNIT_TRANSFORM" >"$base_dir/nunit3-junit.xslt"
saxonb-xslt -s "$unity_project_full_path/$PARAM_TEST_PLATFORM-results.xml" -xsl "$base_dir/nunit3-junit.xslt" >"$unity_project_full_path/$PARAM_TEST_PLATFORM-junit-results.xml"
}
set -x
# shellcheck disable=SC2086 # $custom_parameters needs to be unquoted. Otherwise it will be treated as a single parameter.
${UNITY_EXECUTABLE:-xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' unity-editor} \
-projectPath "$unity_project_full_path" \
-runTests \
-testPlatform "$PARAM_TEST_PLATFORM" \
-testResults "$unity_project_full_path"/"$PARAM_TEST_PLATFORM"-results.xml \
-logFile /dev/stdout \
-batchmode \
-nographics \
-enableCodeCoverage \
-coverageResultsPath "$unity_project_full_path"/"$PARAM_TEST_PLATFORM"-coverage \
-coverageOptions "generateAdditionalMetrics;generateHtmlReport;generateHtmlReportHistory;generateBadgeReport;" \
-debugCodeOptimization \
$custom_parameters
unity_exit_code=$?
set +x
if [ "$unity_exit_code" -eq 0 ] || [ "$unity_exit_code" -eq 2 ]; then
printf '%s\n' "Run succeeded. Exit code $unity_exit_code"
parse_results_to_junit
# Print the results to the console.
cat "$unity_project_full_path/$PARAM_TEST_PLATFORM-junit-results.xml"
else
printf '%s\n' "Run failed. Exit code $unity_exit_code"
fi
code_coverage_package="com.unity.testtools.codecoverage"
package_manifest_path="$unity_project_full_path/Packages/manifest.json"
# Check if the Code Coverage package is installed and move the coverage results to the root of the project.
if grep -q "$code_coverage_package" "$package_manifest_path"; then
grep "$unity_project_full_path"/"$PARAM_TEST_PLATFORM"-coverage/Report/Summary.xml Linecoverage
mv "$unity_project_full_path"/"$PARAM_TEST_PLATFORM"-coverage/"$CIRCLE_PROJECT_REPONAME"-opencov/*Mode/TestCoverageResults_*.xml "$unity_project_full_path"/"$PARAM_TEST_PLATFORM"-coverage/coverage.xml
rm -r "$unity_project_full_path"/"$PARAM_TEST_PLATFORM"-coverage/"$CIRCLE_PROJECT_REPONAME"-opencov/
else
{
echo -e "\033[33mCode Coverage package not found in $package_manifest_path. Please install the package \"Code Coverage\" through Unity's Package Manager to enable coverage reports.\033[0m"
} 2>/dev/null
fi
exit "$unity_exit_code"
SCRIPT_TEST_MACOS: "#!/bin/false\n# shellcheck shell=bash\n# shellcheck disable=SC2154\n\ncheck_and_install_saxonb() {\n if ! brew list saxon-b &> /dev/null; then\n printf '%s\\n' \"Saxon-B is required to parse Unity's XML results to the JUnit format.\"\n printf '%s\\n' \"Installing it with Brew.\"\n \n if brew install saxon-b; then\n printf '%s\\n' \"Saxon-B installed successfully.\"\n saxonb_jar=\"$(brew --prefix saxon-b | xargs -I saxon_path find saxon_path/ -name saxon9.jar)\"\n return 0\n\n else\n printf '%s\\n' \"Something went wrong.\"\n printf '%s\\n' \"Please try again or open an issue.\"\n return 1\n\n fi\n fi\n}\n\ncheck_and_install_java() {\n if ! command -v java &> /dev/null; then\n printf '%s\\n' \"Java is required to parse Unity's XML results to JUnit.\"\n printf '%s\\n' \"Installing it with Brew.\"\n \n if brew cask install java; then\n printf '%s\\n' \"Java installed successfully.\"\n return 0\n\n else\n printf '%s\\n' \"Something went wrong.\"\n printf '%s\\n' \"Please try again or open an issue.\"\n return 1\n\n fi\n fi\n}\n\nparse_xml_to_junit() {\n if ! check_and_install_java; then\n printf '%s\\n' \"Java wasn't found and couldn't be installed.\"\n printf '%s\\n' \"It won't be possible to parse Unity's XML results to JUnit.\"\n return 1\n fi\n\n if ! check_and_install_saxonb; then\n printf '%s\\n' \"Saxon-B wasn't found and couldn't be installed.\"\n printf '%s\\n' \"Impossible to parse Unity's XML results to JUnit.\"\n return 1\n fi\n\n printf '%s\\n' \"Parsing Unity's XML results to JUnit.\"\n printf '%s\\n' \"$DEPENDENCY_NUNIT_TRANSFORM\" > \"$base_dir/nunit3-junit.xslt\"\n\n java -jar \"$saxonb_jar\" -s \"$base_dir/results.xml\" -xsl \"$base_dir\"/nunit3-junit.xslt > \"$unity_project_full_path/$PARAM_TEST_PLATFORM-junit-results.xml\"\n saxon_exit_code=$?\n\n if [ \"$saxon_exit_code\" -ne 0 ] || [ ! -f \"$unity_project_full_path/$PARAM_TEST_PLATFORM-junit-results.xml\" ]; then\n printf '%s\\n' \"Something went wrong.\"\n printf '%s\\n' \"Please try again or open an issue.\"\n return 1\n\n else\n printf '%s\\n' \"Unity's XML results parsed to JUnit successfully.\"\n return 0\n fi\n}\n\nset -x\n# Run the tests.\n# shellcheck disable=SC2086 # $custom_parameters needs to be unquoted. Otherwise it will be treated as a single parameter.\n\"$UNITY_EDITOR_PATH\" \\\n -batchmode \\\n -nographics \\\n -projectPath \"$unity_project_full_path\" \\\n -runTests \\\n -testPlatform \"$PARAM_TEST_PLATFORM\" \\\n -testResults \"$base_dir/results.xml\" \\\n -logfile /dev/stdout \\\n $custom_parameters\n\nunity_exit_code=$?\nset +x\n\nif [ \"$unity_exit_code\" -eq 0 ]; then\n printf '%s\\n' \"Run succeeded, no failures occurred.\";\n if ! parse_xml_to_junit; then exit 1; fi\n\nelif [ \"$unity_exit_code\" -eq 2 ]; then\n printf '%s\\n' \"Run succeeded, some tests failed.\";\n if ! parse_xml_to_junit; then exit 1; fi\n\nelif [ \"$unity_exit_code\" -eq 3 ]; then\n printf '%s\\n' \"Run failure (other failure).\";\n exit 1\nelse\n printf '%s\\n' \"Unexpected exit code $unity_exit_code.\";\n exit 1\nfi\n"
SCRIPT_TEST_WINDOWS: |
#!/bin/false
# shellcheck shell=bash
# shellcheck disable=SC2154,SC2016
trap_exit() {
local exit_status="$?"
if [ "$exit_status" -ne 0 ]; then
printf '%s\n' 'The script did not complete successfully.'
printf '%s\n' "Removing the container \"$CONTAINER_NAME\"."
docker rm -f "$CONTAINER_NAME" &> /dev/null || true
exit "$exit_status"
fi
}
trap trap_exit EXIT
# Add necessary values in the environment variables.
docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('TEST_PLATFORM','$PARAM_TEST_PLATFORM', [System.EnvironmentVariableTarget]::Machine)"
docker exec "$CONTAINER_NAME" powershell "[System.Environment]::SetEnvironmentVariable('CUSTOM_PARAMS','$custom_parameters', [System.EnvironmentVariableTarget]::Machine)"
test_args=(
'-batchmode'
'-nographics'
'-projectPath $Env:PROJECT_PATH'
'-runTests'
'-testPlatform $Env:TEST_PLATFORM'
'-testResults "C:/test/results.xml"'
)
[ -n "$custom_parameters" ] && test_args+=( '$Env:CUSTOM_PARAMS.split()' )
# Run the tests.
set -x
docker exec "$CONTAINER_NAME" powershell "& 'C:\Program Files\Unity\Hub\Editor\*\Editor\Unity.exe' ${test_args[*]} -logfile | Out-Host"
set +x
# Install JDK to run Saxon.
docker exec "$CONTAINER_NAME" powershell 'choco upgrade jdk8 --no-progress -y'
# Download and extract Saxon-B.
docker exec "$CONTAINER_NAME" powershell 'Invoke-WebRequest -Uri "https://versaweb.dl.sourceforge.net/project/saxon/Saxon-B/9.1.0.8/saxonb9-1-0-8j.zip" -Method "GET" -OutFile "C:/test/saxonb.zip"'
docker exec "$CONTAINER_NAME" powershell "Expand-Archive -Force C:/test/saxonb.zip C:/test/saxonb"
# Copy the Saxon-B template to the container.
printf '%s\n' "$DEPENDENCY_NUNIT_TRANSFORM" > "$base_dir/test/nunit3-junit.xslt"
# Parse Unity's results xml to JUnit format.
docker exec "$CONTAINER_NAME" powershell 'java -jar C:/test/saxonb/saxon9.jar -s C:/test/results.xml -xsl C:/test/nunit3-junit.xslt > C:/test/junit-results.xml'
# Convert CRLF to LF otherwise CircleCI won't be able to read the results.
# https://stackoverflow.com/a/48919146
docker exec "$CONTAINER_NAME" powershell '((Get-Content C:/test/junit-results.xml) -join "`n") + "`n" | Set-Content -NoNewline -Encoding utf8 C:/test/junit-results-lf.xml'
# Move test results to project folder for upload.
mv "$base_dir"/test/junit-results-lf.xml "$unity_project_full_path"/"$PARAM_TEST_PLATFORM"-junit-results.xml
SCRIPT_UTILS: "#!/bin/false\n# shellcheck shell=bash\n# shellcheck disable=SC2154\n\ndetect-os() {\n local detected_platform\n \n detected_platform=\"$(uname -s | tr '[:upper:]' '[:lower:]')\"\n\n case \"$detected_platform\" in\n linux*)\n printf '%s\\n' \"Detected OS: Linux.\"\n PLATFORM=linux\n ;;\n darwin*)\n printf '%s\\n' \"Detected OS: macOS.\"\n PLATFORM=macos\n ;;\n msys*|cygwin*)\n printf '%s\\n' \"Detected OS: Windows.\"\n PLATFORM=windows\n ;;\n *)\n printf '%s\\n' \"Unsupported OS: \\\"$platform\\\".\"\n exit 1\n ;;\n esac\n\n export readonly PLATFORM\n}"
name: << parameters.step-name >>
no_output_timeout: << parameters.no_output_timeout >>
- save_cache:
key: unity-deps-{{ arch }}-<<parameters.cache-version>>-<<#parameters.include-branch-in-cache-key>>{{ .Branch }}-<</parameters.include-branch-in-cache-key>>{{ checksum "<<parameters.project-path>>/Packages/packages-lock.json" }}
paths:
- <<parameters.project-path>>/Library/
- store_test_results:
path: << parameters.project-path >>/<< parameters.test-platform >>-junit-results.xml
executors:
macos:
description: |
Drop-in executor to build project in macOS.
environment:
- UNITY_EDITOR_VERSION=<< parameters.editor_version >>
macos:
resource_class: << parameters.resource_class >>
xcode: << parameters.xcode_version >>
parameters:
editor_version:
description: |
Pick the Unity Editor version.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://unity3d.com/get-unity/download/archive.
type: string
resource_class:
default: medium
description: |
Resource class used for the executor.
If you are receiving a "CircleCI received exit code 137" from the build job, you may need to increase the resource class.
For details on resource class availability, see https://circleci.com/docs/using-macos#available-resource-classes.
enum:
- medium
- macos.x86.medium.gen2
- large
- macos.x86.metal.gen1
type: enum
xcode_version:
default: 13.4.1
description: |
Pick the Xcode version.
Available options can be found at https://circleci.com/docs/using-macos#supported-xcode-versions.
type: string
macos-runner:
description: |
Drop-in executor to build projects in a macOS runner.
environment:
- UNITY_EDITOR_VERSION=<< parameters.editor_version >>
machine: true
parameters:
editor_version:
description: |
Pick the Unity Editor version.
Available options can be found at https://unity3d.com/get-unity/download/archive.
type: string
resource_class:
description: |
Enter your Runner resource class.
For information on how to setup a Runner agent, see: https://circleci.com/docs/2.0/runner-overview/.
type: string
working_directory:
default: /var/opt/circleci/workdir
description: |
Enter the working directory of your runner agent.
type: string
resource_class: << parameters.resource_class >>
working_directory: << parameters.working_directory >>
ubuntu:
description: |
Select the Editor version and Target Platform for the GameCI image.
Available target platforms can be found at: https://game.ci/docs/docker/versions.
This executor only supports the "ubuntu" OS.
docker:
- environment:
- GAMECI_EDITOR_VERSION=<< parameters.editor_version >>
- GAMECI_TARGET_PLATFORM=<< parameters.target_platform >>
image: unityci/editor:ubuntu-<<parameters.editor_version>>-<<parameters.target_platform>>-2
parameters:
editor_version:
description: |
Pick the editor version for the GameCI image.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://game.ci/docs/docker/versions.
type: string
resource_class:
default: large
description: |
Resource class used for the executor.
If you are receiving a "CircleCI received exit code 137" from the build job, you may need to increase the resource class.
enum:
- small
- medium
- medium+
- large
- xlarge
- 2xlarge
- 2xlarge+
type: enum
target_platform:
description: |
Pick the target platform for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
The 2018 release doesn't support the "linux-il2cpp" target platform.
enum:
- android
- base
- ios
- linux-il2cpp
- mac-mono
- webgl
- windows-mono
type: enum
resource_class: << parameters.resource_class >>
ubuntu-container-runner:
description: |
Select the Editor version and Target Platform for the GameCI image.
Available target platforms can be found at: https://game.ci/docs/docker/versions.
For information on how to setup a Runner agent, see: https://circleci.com/docs/container-runner-installation/.
docker:
- environment:
- GAMECI_EDITOR_VERSION=<< parameters.editor_version >>
- GAMECI_TARGET_PLATFORM=<< parameters.target_platform >>
image: unityci/editor:ubuntu-<<parameters.editor_version>>-<<parameters.target_platform>>-2
parameters:
editor_version:
description: |
Pick the editor version for the GameCI image.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://game.ci/docs/docker/versions.
type: string
resource_class:
description: |
Enter your Runner resource class.
For information on how to setup a Runner agent, see: https://circleci.com/docs/container-runner-installation/.
type: string
target_platform:
description: |
Pick the target platform for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
The 2018 release doesn't support the "linux-il2cpp" target platform.
enum:
- android
- base
- ios
- linux-il2cpp
- mac-mono
- webgl
- windows-mono
type: enum
resource_class: << parameters.resource_class >>
windows-2019:
description: |
Select the Editor version and Target Platform for the GameCI image.
Available target platforms can be found at: https://game.ci/docs/docker/versions.
environment:
- GAMECI_EDITOR_VERSION=<< parameters.editor_version >>
- GAMECI_TARGET_PLATFORM=<< parameters.target_platform >>
machine:
image: windows-server-2019-vs2019:<< parameters.version >>
resource_class: windows.<< parameters.size >>
shell: bash.exe
parameters:
editor_version:
description: |
Pick the editor version for the GameCI image.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://game.ci/docs/docker/versions.
type: string
size:
default: large
description: The size of Windows resource to use.
enum:
- medium
- large
- xlarge
- 2xlarge
type: enum
target_platform:
description: |
Pick the target platform for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
The 2018 release doesn't support the "linux-il2cpp" target platform.
enum:
- appletv
- base
- universal-windows-platform
- windows-il2cpp
type: enum
version:
default: current
description: |
The Windows image version to use.
type: string
windows-2019-cuda:
description: |
Select the Editor version and Target Platform for the GameCI image.
Available target platforms can be found at: https://game.ci/docs/docker/versions.
environment:
- GAMECI_EDITOR_VERSION=<< parameters.editor_version >>
- GAMECI_TARGET_PLATFORM=<< parameters.target_platform >>
machine:
image: windows-server-2019-cuda:<< parameters.version >>
resource_class: windows.gpu.nvidia.<< parameters.size >>
shell: bash.exe
parameters:
editor_version:
description: |
Pick the editor version for the GameCI image.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://game.ci/docs/docker/versions.
type: string
size:
default: medium
description: The size of Windows resource to use.
enum:
- small
- medium
type: enum
target_platform:
description: |
Pick the target platform for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
The 2018 release doesn't support the "linux-il2cpp" target platform.
enum:
- appletv
- base
- universal-windows-platform
- windows-il2cpp
type: enum
version:
default: current
description: |
The Windows image version to use.
type: string
windows-2022:
description: |
Select the Editor version and Target Platform for the GameCI image.
Available target platforms can be found at: https://game.ci/docs/docker/versions.
environment:
- GAMECI_EDITOR_VERSION=<< parameters.editor_version >>
- GAMECI_TARGET_PLATFORM=<< parameters.target_platform >>
machine:
image: windows-server-2022-gui:<< parameters.version >>
resource_class: windows.<< parameters.size >>
shell: bash.exe
parameters:
editor_version:
description: |
Pick the editor version for the GameCI image.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://game.ci/docs/docker/versions.
type: string
size:
default: large
description: The size of Windows resource to use.
enum:
- medium
- large
- xlarge
- 2xlarge
type: enum
target_platform:
description: |
Pick the target platform for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
The 2018 release doesn't support the "linux-il2cpp" target platform.
enum:
- appletv
- base
- universal-windows-platform
- windows-il2cpp
type: enum
version:
default: current
description: |
The Windows image version to use.
type: string
windows-runner:
description: |
Select the Editor version and Target Platform for the GameCI image.
Available target platforms can be found at: https://game.ci/docs/docker/versions.
This executor only supports the "windows" OS and should be used with a CircleCI Runner.
For information on how to setup a Runner agent, see: https://circleci.com/docs/2.0/runner-overview/.
environment:
- GAMECI_EDITOR_VERSION=<< parameters.editor_version >>
- GAMECI_TARGET_PLATFORM=<< parameters.target_platform >>
machine: true
parameters:
editor_version:
description: |
Pick the editor version for the GameCI image.
Make sure to pick the same major version as the Unity version you generated the license for.
Available options can be found at https://game.ci/docs/docker/versions.
type: string
resource_class:
description: |
Enter your Runner resource class.
For information on how to setup a Runner agent, see: https://circleci.com/docs/2.0/runner-overview/.
type: string
target_platform:
description: |
Pick the target platform for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
The 2018 release doesn't support the "linux-il2cpp" target platform.
enum:
- appletv
- base
- universal-windows-platform
- windows-il2cpp
type: enum
working_directory:
default: C:\ProgramFiles\CircleCI\Workdir
description: |
Enter the working directory of your runner agent.
type: string
resource_class: << parameters.resource_class >>
working_directory: << parameters.working_directory >>
jobs:
build:
description: |
Simple drop-in job to build your Unity game.
executor: << parameters.executor >>
parameters:
build-method:
default: ""
description: |
The method used as argument for the Unity CLI "executeMethod" parameter.
It must be a valid path to a static method and the class exist in the Assets/Editor directory.
If left empty, the default build method will be used.
type: string
build-name:
default: ""
description: |
Enter the name for this build.
If left blank, the build will be named after the target platform.
type: string
build-target:
description: |
The target platform of your build.
Accepted arguments vary with Unity's version and can be found in the docs: https://docs.unity3d.com/2022.2/Documentation/ScriptReference/BuildTarget.html
type: string
compress:
default: true
description: |
Whether to compress the build output to a ".tar.gz" archive.
This is recommended if you want to download the built artifacts from the CircleCI web app.
If left to "false" for decompressed WebGL builds, you can run the project directly from the CircleCI web app.
type: boolean
custom-parameters:
default: ""
description: |
Additional arguments for the Unity CLI.
Use it to pass arguments defined on your custom "build-method" or Unity's build options. Environment variables are supported.
The parameters must be separated by space and must be in the format "-key value" or "-key" for booleans.
Example: "-customArg1 WebGL -EnableHeadlessMode -customArg2 $CIRCLE_WORKFLOW_ID".
type: string
executor:
description: |
Pick an Executor to run the build job with.
type: executor
fetch-submodules:
default: false
description: |
Whether to fetch git submodules
type: boolean
no_output_timeout:
default: 20m
description: Elapsed time the command can run without output.
type: string
persist-to-workspace:
default: false
description: Whether to persist the build output to workspace.
type: boolean
project-path:
default: .
description: |
Enter the path of your Unity project.
This should be the directory that has an "Assets" folder inside it.
type: string
return-license:
default: false
description: |
Whether to return the license used to build the project.
Unity only allows returning professional licenses.
type: boolean
step-name:
default: Build the project
description: |
Specify a custom step name for the build command, if desired.
type: string
store-artifacts:
default: true
description: |
Whether to store the build output.
If left to "false" you won't be able to download the build from the job's artifacts.
type: boolean
unity-license-var-name:
default: UNITY_ENCODED_LICENSE
description: |
Enter the name of the environment variable containing your Unity license file encoded in base64.
Required if you have a Personal license.
type: env_var_name
unity-password-var-name:
default: UNITY_PASSWORD
description: |
Enter the name of the environment variable containing your Unity password.
type: env_var_name
unity-serial-var-name:
default: UNITY_SERIAL
description: |
Enter the name of the environment variable containing your Unity serial number.
Required if you have a Plus or Pro license.
type: env_var_name
unity-username-var-name:
default: UNITY_USERNAME
description: |
Enter the name of the environment variable containing your Unity username.
type: env_var_name
steps:
- checkout
- run:
command: |
git submodule sync
git submodule update --init
condition: << parameters.fetch-submodules >>
name: Fetch submodules
- prepare-env:
no_output_timeout: << parameters.no_output_timeout>>
project-path: <<parameters.project-path>>
unity-license-var-name: << parameters.unity-license-var-name >>
unity-password-var-name: << parameters.unity-password-var-name >>
unity-serial-var-name: << parameters.unity-serial-var-name >>
unity-username-var-name: << parameters.unity-username-var-name >>
- build:
build-method: <<parameters.build-method>>
build-name: <<parameters.build-name>>
build-target: <<parameters.build-target>>
compress: <<parameters.compress>>
custom-parameters: <<parameters.custom-parameters>>
no_output_timeout: << parameters.no_output_timeout>>
persist-to-workspace: <<parameters.persist-to-workspace>>
project-path: <<parameters.project-path>>
step-name: << parameters.step-name >>
store-artifacts: <<parameters.store-artifacts>>
- when:
condition: <<parameters.return-license>>
steps:
- return-license:
unity-password-var-name: << parameters.unity-password-var-name >>
unity-username-var-name: << parameters.unity-username-var-name >>
create-activation-file:
description: |
Simple drop-in job to create a Unity activation file.
docker:
- image: unityci/editor:ubuntu-<<parameters.editor_version>>-base-1
parameters:
editor_version:
default: 2021.3.7f1
description: |
Pick the editor version for the GameCI image.
Available options can be found at https://game.ci/docs/docker/versions.
type: string
resource_class: medium
steps:
- checkout
- run:
command: |-
#!/bin/false
# shellcheck shell=bash
# shellcheck disable=SC2154
create_manual_activation_file() {
unity-editor \
-batchmode \
-nographics \
-createManualActivationFile \
-quit \
-logfile /dev/null
# Check if license file was created successfully.
if ls Unity_v*.alf &> /dev/null; then return 0; else return 1; fi
}
if ! create_manual_activation_file; then
printf '%s\n' "Failed to create Unity license file."
printf '%s\n' "Please try again or open an issue."
exit 1
fi
mv Unity_v*.alf Unity.alf
name: Create Unity activation file
- store_artifacts:
path: Unity.alf
test:
description: |
Simple drop-in job to build your Unity game.
executor: << parameters.executor >>
parameters:
custom-parameters:
default: ""
description: |
Additional arguments for the Unity CLI.
Use it to pass arguments to Unity's test options. Environment variables are supported.
The parameters must be separated by space and must be in the format "-key value" or "-key" for booleans.
Example: '-testFilter "MyNamespace.Something.MyTest" -assemblyNames "MyUnitTestAssembly" -testCategory "Unit;Integration"'.
type: string
executor:
description: |
Pick an Executor to run the build job with.
type: executor
no_output_timeout:
default: 20m
description: Elapsed time the command can run without output.
type: string
project-path:
default: .
description: |
Enter the path of your Unity project.
This should be the directory that has an "Assets" folder inside it.
type: string
return-license:
default: false
description: |
Whether to return the license used to test the project.
Unity only allows returning professional licenses.
type: boolean
step-name:
default: Run tests
description: |
Specify a custom step name for the test command, if desired.
type: string
test-platform:
default: editmode
description: |
Specify the test platform to run tests on.
Valid values are "editmode", "playmode" and Unity's target builds.
More information can be found on: https://docs.unity3d.com/Packages/com.unity.test-framework@2.0/manual/reference-command-line.html
type: string
unity-license-var-name:
default: UNITY_ENCODED_LICENSE
description: |
Enter the name of the environment variable containing your Unity license file encoded in base64.
Required if you have a Personal license.
type: env_var_name
unity-password-var-name:
default: UNITY_PASSWORD
description: |
Enter the name of the environment variable containing your Unity password.
type: env_var_name
unity-serial-var-name:
default: UNITY_SERIAL
description: |
Enter the name of the environment variable containing your Unity serial number.
Required if you have a Plus or Pro license.
type: env_var_name
unity-username-var-name:
default: UNITY_USERNAME
description: |
Enter the name of the environment variable containing your Unity username.
type: env_var_name
steps:
- checkout
- prepare-env:
no_output_timeout: << parameters.no_output_timeout>>
project-path: <<parameters.project-path>>
unity-license-var-name: << parameters.unity-license-var-name >>
unity-password-var-name: << parameters.unity-password-var-name >>
unity-serial-var-name: << parameters.unity-serial-var-name >>
unity-username-var-name: << parameters.unity-username-var-name >>
- test:
custom-parameters: << parameters.custom-parameters >>
no_output_timeout: << parameters.no_output_timeout>>
project-path: << parameters.project-path >>
step-name: << parameters.step-name >>
test-platform: << parameters.test-platform >>
- when:
condition: <<parameters.return-license>>
steps:
- return-license:
unity-password-var-name: << parameters.unity-password-var-name >>
unity-username-var-name: << parameters.unity-username-var-name >>
examples:
test_and_build_personal_license:
description: |
Drop-in solution to automatically run tests and build your Unity project using a Personal license. Make sure to read the documentation before using the orb: https://game.ci/docs/circleci/getting-started. For runner examples, see: https://game.ci/docs/circleci/executors#macos-runner and https://game.ci/docs/circleci/executors#windows-runner.
usage:
version: "2.1"
orbs:
unity: game-ci/unity@1.3.0
workflows:
test-build-with-executors:
jobs:
- checkout
- unity/test:
context: unity
executor:
editor_version: 2021.3.1f1
name: unity/ubuntu
resource_class: medium
target_platform: linux-il2cpp
name: test-linux
project-path: Unity2D-Demo-Game-CI-CD/src
step-name: Check if the tests run and results are uploaded
test-platform: playmode
unity-license-var-name: UNITY_ENCODED_LICENSE
unity-password-var-name: UNITY_PASSWORD
unity-username-var-name: UNITY_USERNAME
- unity/build:
build-target: StandaloneLinux64
compress: true
context: unity
executor:
editor_version: 2021.3.1f1
name: unity/ubuntu
resource_class: large
target_platform: linux-il2cpp
name: build-linux64-il2cpp
project-path: Unity2D-Demo-Game-CI-CD/src
requires:
- test-linux
step-name: Build StandaloneLinux64
unity-license-var-name: UNITY_ENCODED_LICENSE
unity-password-var-name: UNITY_PASSWORD
unity-username-var-name: UNITY_USERNAME
- unity/test:
context: unity
executor:
editor_version: 2021.3.2f1
name: unity/windows-2022
size: large
target_platform: windows-il2cpp
name: test-windows
project-path: Unity2D-Demo-Game-CI-CD/src
step-name: Check if the tests run and results are uploaded
test-platform: playmode
unity-license-var-name: UNITY_ENCODED_LICENSE
unity-password-var-name: UNITY_PASSWORD
unity-username-var-name: UNITY_USERNAME
- unity/build:
build-target: StandaloneWindows64
compress: true
context: unity
executor:
editor_version: 2021.3.2f1
name: unity/windows-2019
size: large
target_platform: windows-il2cpp
name: build-Windows64-il2cpp
project-path: Unity2D-Demo-Game-CI-CD/src
requires:
- test-windows
step-name: Build StandaloneWindows64 il2cpp
unity-license-var-name: UNITY_ENCODED_LICENSE
unity-password-var-name: UNITY_PASSWORD
unity-username-var-name: UNITY_USERNAME
- unity/test:
context: unity
executor:
editor_version: 2021.3.1f1
name: unity/macos
resource_class: large
name: test-osx
project-path: Unity2D-Demo-Game-CI-CD/src
step-name: Check if the tests run and results are uploaded
test-platform: playmode
unity-license-var-name: UNITY_ENCODED_LICENSE
unity-password-var-name: UNITY_PASSWORD
unity-username-var-name: UNITY_USERNAME
- unity/build:
build-target: StandaloneOSX
compress: true
context: unity
executor:
editor_version: 2021.3.2f1
name: unity/macos
resource_class: large
name: build-osx-il2cpp
project-path: Unity2D-Demo-Game-CI-CD/src
requires:
- test-osx
step-name: Build macOS IL2CPP
unity-license-var-name: UNITY_ENCODED_LICENSE
unity-password-var-name: UNITY_PASSWORD
unity-username-var-name: UNITY_USERNAME
test_and_build_pro_or_plus_license:
description: |
Drop-in solution to automatically run tests and build your Unity project using a Pro or Plus license. Make sure to read the documentation before using the orb: https://game.ci/docs/circleci/getting-started. For runner examples, see: https://game.ci/docs/circleci/executors#macos-runner and https://game.ci/docs/circleci/executors#windows-runner.
usage:
version: "2.1"
orbs:
unity: game-ci/unity@1.3.0
workflows:
test-build-with-executors:
jobs:
- checkout
- unity/test:
context: unity
executor:
editor_version: 2021.3.1f1
name: unity/ubuntu
resource_class: medium
target_platform: linux-il2cpp
name: test-linux
project-path: Unity2D-Demo-Game-CI-CD/src
step-name: Check if the tests run and results are uploaded
test-platform: playmode
unity-password-var-name: UNITY_PASSWORD
unity-serial-var-name: UNITY_SERIAL
unity-username-var-name: UNITY_USERNAME
- unity/build:
build-target: StandaloneLinux64
compress: true
context: unity
executor:
editor_version: 2021.3.1f1
name: unity/ubuntu
resource_class: large
target_platform: linux-il2cpp
name: build-linux64-il2cpp
project-path: Unity2D-Demo-Game-CI-CD/src
requires:
- test-linux
step-name: Build StandaloneLinux64
unity-password-var-name: UNITY_PASSWORD
unity-serial-var-name: UNITY_SERIAL
unity-username-var-name: UNITY_USERNAME
- unity/test:
context: unity
executor:
editor_version: 2021.3.2f1
name: unity/windows-2022
size: large
target_platform: windows-il2cpp
name: test-windows
project-path: Unity2D-Demo-Game-CI-CD/src
step-name: Check if the tests run and results are uploaded
test-platform: playmode
unity-password-var-name: UNITY_PASSWORD
unity-serial-var-name: UNITY_SERIAL
unity-username-var-name: UNITY_USERNAME
- unity/build:
build-target: StandaloneWindows64
compress: true
context: unity
executor:
editor_version: 2021.3.2f1
name: unity/windows-2019
size: large
target_platform: windows-il2cpp
name: build-Windows64-il2cpp
project-path: Unity2D-Demo-Game-CI-CD/src
requires:
- test-windows
step-name: Build StandaloneWindows64 il2cpp
unity-password-var-name: UNITY_PASSWORD
unity-serial-var-name: UNITY_SERIAL
unity-username-var-name: UNITY_USERNAME
- unity/test:
context: unity
executor:
editor_version: 2021.3.1f1
name: unity/macos
resource_class: large
name: test-osx
project-path: Unity2D-Demo-Game-CI-CD/src
step-name: Check if the tests run and results are uploaded
test-platform: playmode
unity-password-var-name: UNITY_PASSWORD
unity-serial-var-name: UNITY_SERIAL
unity-username-var-name: UNITY_USERNAME
- unity/build:
build-target: StandaloneOSX
compress: true
context: unity
executor:
editor_version: 2021.3.2f1
name: unity/macos
resource_class: large
name: build-osx-il2cpp
project-path: Unity2D-Demo-Game-CI-CD/src
requires:
- test-osx
step-name: Build macOS IL2CPP
unity-password-var-name: UNITY_PASSWORD
unity-serial-var-name: UNITY_SERIAL
unity-username-var-name: UNITY_USERNAME