-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
185 lines (167 loc) · 5.7 KB
/
.gitlab-ci.yml
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
stages:
- prepare
- test
- build
- deploy
# If you are looking for a place where to add 'UNITY_LICENSE_FILE' and other secrets, please visit your project's gitlab page:
# settings > CI/CD > Variables instead
variables:
BUILD_NAME: Tree-o
UNITY_ACTIVATION_FILE: ./unity3d.alf
IMAGE: unityci/editor # https://hub.docker.com/r/unityci/editor
IMAGE_VERSION: "0.17.2" # https://github.com/game-ci/docker/releases
UNITY_DIR: $CI_PROJECT_DIR # this needs to be an absolute path. Defaults to the root of your tree.
# You can expose this in Unity via Application.version
VERSION_NUMBER_VAR: $CI_COMMIT_REF_SLUG-$CI_PIPELINE_ID-$CI_JOB_ID
VERSION_BUILD_VAR: $CI_PIPELINE_IID
image: $IMAGE:$UNITY_VERSION-base-$IMAGE_VERSION
get-unity-version:
image: alpine
stage: prepare
variables:
GIT_DEPTH: 1
script:
- echo UNITY_VERSION=$(cat $UNITY_DIR/ProjectSettings/ProjectVersion.txt | grep "m_EditorVersion:.*" | awk '{ print $2}') | tee prepare.env
artifacts:
reports:
dotenv: prepare.env
.unity_before_script: &unity_before_script
before_script:
- chmod +x ./ci/before_script.sh && ./ci/before_script.sh
needs:
- job: get-unity-version
artifacts: true
.cache: &cache
cache:
key: "$CI_PROJECT_NAMESPACE-$CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG-$TEST_PLATFORM"
paths:
- $UNITY_DIR/Library/
.license: &license
rules:
- if: '$UNITY_LICENSE != null'
when: always
.unity_defaults: &unity_defaults
<<:
- *unity_before_script
- *cache
- *license
# run this job when you need to request a license
# you may need to follow activation steps from documentation
get-activation-file:
<<: *unity_before_script
rules:
- if: '$UNITY_LICENSE == null'
when: manual
stage: prepare
script:
- chmod +x ./ci/get_activation_file.sh && ./ci/get_activation_file.sh
artifacts:
paths:
- $UNITY_ACTIVATION_FILE
expire_in: 10 min # Expiring this as artifacts may contain sensitive data and should not be kept public
.test-with-junit-reports: &test-with-junit-reports
stage: test
<<: *unity_defaults
script:
# This could be made faster by adding these packages to base image or running in a separate job (and step)
# We could use an image with these two depencencies only and only do the saxonb-xslt command on
# previous job's artifacts
- apt-get update && apt-get install -y default-jre libsaxonb-java
- chmod +x ./ci/test.sh && ./ci/test.sh
- saxonb-xslt -s $UNITY_DIR/$TEST_PLATFORM-results.xml -xsl $CI_PROJECT_DIR/ci/nunit-transforms/nunit3-junit.xslt >$UNITY_DIR/$TEST_PLATFORM-junit-results.xml
artifacts:
when: always
paths:
# This is exported to allow viewing the Coverage Report in detail if needed
- $UNITY_DIR/$TEST_PLATFORM-coverage/
reports:
junit:
- $UNITY_DIR/$TEST_PLATFORM-junit-results.xml
- "$UNITY_DIR/$TEST_PLATFORM-coverage/coverage.xml"
expire_in: 2 weeks
coverage: /<Linecoverage>(.*?)</Linecoverage>/
test-playmode-with-junit-reports:
<<: *test-with-junit-reports
variables:
TEST_PLATFORM: playmode
TESTING_TYPE: JUNIT
test-editmode-with-junit-reports:
<<: *test-with-junit-reports
variables:
TEST_PLATFORM: editmode
TESTING_TYPE: JUNIT
.build: &build
stage: build
<<: *unity_defaults
script:
- chmod +x ./ci/build.sh && ./ci/build.sh
artifacts:
paths:
- $UNITY_DIR/Builds/
needs:
- job: test-playmode-with-junit-reports
- job: test-editmode-with-junit-reports
- job: get-unity-version
artifacts: true
rules:
- if: '$CI_COMMIT_REF_NAME == "main" || $CI_COMMIT_TAG'
build-StandaloneLinux64:
<<: *build
variables:
BUILD_TARGET: StandaloneLinux64
build-StandaloneWindows64:
<<: *build
image: $IMAGE:$UNITY_VERSION-windows-mono-$IMAGE_VERSION
variables:
BUILD_TARGET: StandaloneWindows64
# For webgl support, you need to set Compression Format to Disabled for v0.9. See https://github.com/game-ci/docker/issues/75
build-WebGL:
<<: *build
image: $IMAGE:$UNITY_VERSION-webgl-$IMAGE_VERSION
# Temporary workaround for https://github.com/game-ci/docker/releases/tag/v0.9 and webgl support in current project to prevent errors with missing ffmpeg
before_script:
- chmod +x ./ci/before_script.sh && ./ci/before_script.sh
- apt-get update && apt-get install ffmpeg -y
variables:
BUILD_TARGET: WebGL
pages:
image: alpine:latest
stage: deploy
script:
- mv "$UNITY_DIR/Builds/WebGL/${BUILD_NAME}" public
artifacts:
paths:
- public
only:
- main
package_registry:
stage: deploy
image: ubuntu:20.04
needs:
- job: build-StandaloneLinux64
- job: build-StandaloneWindows64
- job: build-WebGL
- job: get-unity-version
artifacts: true
rules:
- if: '$CI_COMMIT_TAG && $CI_COMMIT_TAG =~ /^v.*$/'
variables:
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/builds/$CI_COMMIT_TAG"
before_script:
- apt-get update -y
- apt-get install -y zip curl
script:
- zip -r build-StandaloneLinux64.zip ./Builds/StandaloneLinux64/
- zip -r build-StandaloneWindows64.zip ./Builds/StandaloneWindows64/
- zip -r build-WebGL.zip ./Builds/WebGL/${BUILD_NAME}/
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file build-StandaloneLinux64.zip "${PACKAGE_REGISTRY_URL}/StandaloneLinux64-$CI_COMMIT_TAG.zip"
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file build-StandaloneWindows64.zip "${PACKAGE_REGISTRY_URL}/StandaloneWindows64-$CI_COMMIT_TAG.zip"
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file build-WebGL.zip "${PACKAGE_REGISTRY_URL}/WebGL-$CI_COMMIT_TAG.zip"
workflow:
rules:
- if: $CI_MERGE_REQUEST_ID
when: never
- when: always