-
Notifications
You must be signed in to change notification settings - Fork 0
310 lines (300 loc) · 14.2 KB
/
main.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
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
name: Unity Actions
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
PROJECT_PATH: src
UNITY_VERSION: 2020.3.1f1
TEST_MODE: all
jobs:
# Checks if certain secrets are available and store the results in the output of this job.
check_gh_secrets:
name: Check GitHub Secrets
runs-on: ubuntu-latest
outputs:
unity_license_exists: ${{ steps.set_secrets_exist_flags.outputs.unity_license_exists }}
android_keystore_base64_exists: ${{ steps.set_secrets_exist_flags.outputs.android_keystore_base64_exists }}
android_keystore_pass_exists: ${{ steps.set_secrets_exist_flags.outputs.android_keystore_pass_exists }}
android_keyalias_name_exists: ${{ steps.set_secrets_exist_flags.outputs.android_keyalias_name_exists }}
android_keyalias_pass_exists: ${{ steps.set_secrets_exist_flags.outputs.android_keyalias_pass_exists }}
gha_dynamic_badges_gist_id_exists: ${{ steps.set_secrets_exist_flags.outputs.gha_dynamic_badges_gist_id_exists }}
gha_dynamic_badges_gist_scope_token_exists: ${{ steps.set_secrets_exist_flags.outputs.gha_dynamic_badges_gist_scope_token_exists }}
steps:
- name: Set Secrets Exist Flags
id: set_secrets_exist_flags
run: |
echo "::set-output name=unity_license_exists::${{ secrets.UNITY_LICENSE != '' }}"
echo "::set-output name=android_keystore_base64_exists::${{ secrets.ANDROID_KEYSTORE_BASE64 != '' }}"
echo "::set-output name=android_keystore_pass_exists::${{ secrets.ANDROID_KEYSTORE_PASS != '' }}"
echo "::set-output name=android_keyalias_name_exists::${{ secrets.ANDROID_KEYALIAS_NAME != '' }}"
echo "::set-output name=android_keyalias_pass_exists::${{ secrets.ANDROID_KEYALIAS_PASS != '' }}"
echo "::set-output name=gha_dynamic_badges_gist_id_exists::${{ secrets.GHA_DYNAMIC_BADGES_GIST_ID != '' }}"
echo "::set-output name=gha_dynamic_badges_gist_scope_token_exists::${{ secrets.GHA_DYNAMIC_BADGES_GIST_SCOPE_TOKEN != '' }}"
# Checks if certain skip keywords exist in the commits and store the results in the output of this job.
check_skip_commits:
name: Check Skip Commits
runs-on: ubuntu-latest
outputs:
skip_test: ${{ steps.set_skip_flags.outputs.skip_test }}
skip_build: ${{ steps.set_skip_flags.outputs.skip_build }}
skip_android: ${{ steps.set_skip_flags.outputs.skip_android }}
skip_webgl: ${{ steps.set_skip_flags.outputs.skip_webgl }}
env:
COMMITS_JSON: ${{ toJSON(github.event.commits.*.message) }}
steps:
- name: Set Skip Flags
id: set_skip_flags
run: |
echo "::set-output name=skip_test::${{ env.SKIP_TEST }}"
echo "::set-output name=skip_build::${{ env.SKIP_BUILD }}"
echo "::set-output name=skip_android::${{ env.SKIP_ANDROID }}"
echo "::set-output name=skip_webgl::${{ env.SKIP_WEBGL }}"
env:
SKIP_TEST: ${{ contains(env.COMMITS_JSON, '[skip test]') || contains(env.COMMITS_JSON, '[no test]') || contains(env.COMMITS_JSON, '[test skip]') }}
SKIP_BUILD: ${{ contains(env.COMMITS_JSON, '[skip build]') || contains(env.COMMITS_JSON, '[no build]') || contains(env.COMMITS_JSON, '[build skip]') }}
SKIP_ANDROID: ${{ contains(env.COMMITS_JSON, '[skip android]') || contains(env.COMMITS_JSON, '[no android]') || contains(env.COMMITS_JSON, '[android skip]') }}
SKIP_WEBGL: ${{ contains(env.COMMITS_JSON, '[skip webgl]') || contains(env.COMMITS_JSON, '[no webgl]') || contains(env.COMMITS_JSON, '[webgl skip]') }}
# Requests the manual activation file for Unity if 'UNITY_LICENSE' is not found in GitHub Secrets.
request_unity_activation_file:
name: Request Unity Activation File
needs: [ check_gh_secrets ]
runs-on: ubuntu-latest
if: needs.check_gh_secrets.outputs.unity_license_exists != 'true'
steps:
- name: Attention
run: |
echo "::group::ATTENTION"
echo "It looks like you have not set 'UNITY_LICENSE' in your secrets."
echo "Requesting a manual activation file from Unity.."
echo "::endgroup::"
# GitHub Action for requesting the manual activation file for Unity. Part of the GameCI open source project.
- name: Unity - Request Activation File
id: unity_request_activation_file
uses: game-ci/[email protected]
with:
unityVersion: ${{ env.UNITY_VERSION }}
# This uploads artifacts from your workflow allowing you to share data between jobs and store data once a workflow is complete.
- name: Upload Unity_vX.X.X.alf file as Artifact
id: upload_artifact
uses: actions/upload-artifact@v2
with:
name: ${{ steps.unity_request_activation_file.outputs.filePath }}
path: ${{ steps.unity_request_activation_file.outputs.filePath }}
- name: Instructions
run: |
echo "::group::INSTRUCTIONS"
echo "Follow these (one-time) steps for setting 'UNITY_LICENSE' in your secret:"
echo " 1. Download the manual activation file (Unity_vX.X.X.alf) that now appeared as an artifact."
echo " 2. Visit license.unity3d.com and upload it."
echo " 3. You should now receive your license file (Unity_vX.X.ulf) as a download."
echo " 4. Open GitHub > YOUR_REPOSITORY > Settings > Secrets."
echo " 5. Create a secret called 'UNITY_LICENSE' and copy the contents your license file into it."
echo "::endgroup::"
# Runs the Unity Test Runner and uploads the Unity Test Results as an artifact.
run_unity_test_runner:
name: Run Unity Test Runner
needs: [ check_gh_secrets, check_skip_commits ]
runs-on: ubuntu-latest
if: |
needs.check_gh_secrets.outputs.unity_license_exists == 'true' &&
needs.check_skip_commits.outputs.skip_test != 'true'
steps:
# This action checks-out your repository under $GITHUB_WORKSPACE, so your workflow can access it.
- name: Checkout
id: checkout
uses: actions/[email protected]
with:
lfs: true
# This action allows caching dependencies and build outputs to improve workflow execution time.
- name: Cache
id: cache
uses: actions/[email protected]
with:
path: ${{ env.PROJECT_PATH }}/Library
key: Library-test
restore-keys: |
Library-
Library
# GitHub Action to run tests for any Unity project. Part of the GameCI open source project.
- name: Unity - Test Runner
id: unity_test_runner
uses: game-ci/[email protected]
with:
projectPath: ${{ env.PROJECT_PATH }}
unityVersion: ${{ env.UNITY_VERSION }}
testMode: ${{ env.TEST_MODE }}
customParameters: -nographics
githubToken: ${{ secrets.GITHUB_TOKEN }}
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
# This uploads artifacts from your workflow allowing you to share data between jobs and store data once a workflow is complete.
- name: Upload Unity Test Results as Artifact
id: upload_artifact
uses: actions/upload-artifact@v2
with:
name: Unity Test Results
path: ${{ steps.unity_test_runner.outputs.artifactsPath }}
# Builds the Unity project with Android as the target platform.
build_unity_project_android:
name: Build Unity Project (Android)
needs: [ check_gh_secrets, check_skip_commits ]
runs-on: ubuntu-latest
outputs:
build_version: ${{ steps.unity_builder.outputs.buildVersion }}
if: |
needs.check_gh_secrets.outputs.unity_license_exists == 'true' &&
needs.check_skip_commits.outputs.skip_build != 'true' &&
needs.check_skip_commits.outputs.skip_android != 'true' &&
needs.check_gh_secrets.outputs.android_keystore_base64_exists == 'true' &&
needs.check_gh_secrets.outputs.android_keystore_pass_exists == 'true' &&
needs.check_gh_secrets.outputs.android_keyalias_name_exists == 'true' &&
needs.check_gh_secrets.outputs.android_keyalias_pass_exists == 'true'
steps:
# This action checks-out your repository under $GITHUB_WORKSPACE, so your workflow can access it.
- name: Checkout
id: checkout
uses: actions/[email protected]
with:
lfs: true
# This action allows caching dependencies and build outputs to improve workflow execution time.
- name: Cache
id: cache
uses: actions/[email protected]
with:
path: ${{ env.PROJECT_PATH }}/Library
key: Library-Android
restore-keys: |
Library-
Library
# GitHub Action to build Unity projects for different platforms. Part of the GameCI open source project.
- name: Unity - Builder
id: unity_builder
uses: game-ci/[email protected]
with:
projectPath: ${{ env.PROJECT_PATH }}
unityVersion: ${{ env.UNITY_VERSION }}
targetPlatform: Android
versioning: Semantic
githubToken: ${{ secrets.GITHUB_TOKEN }}
androidKeystoreName: user.keystore
androidKeystoreBase64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
androidKeystorePass: ${{ secrets.ANDROID_KEYSTORE_PASS }}
androidKeyaliasName: ${{ secrets.ANDROID_KEYALIAS_NAME }}
androidKeyaliasPass: ${{ secrets.ANDROID_KEYALIAS_PASS }}
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
# This uploads artifacts from your workflow allowing you to share data between jobs and store data once a workflow is complete.
- name: Upload Build as Artifact
id: upload_artifact
uses: actions/upload-artifact@v2
with:
name: Build-Android-${{ steps.unity_builder.outputs.buildVersion }}
path: build
# This action allows you to create badges for your README.md with shields.io which may change with every commit.
- name: Update Build Status Badge
id: update_build_status_badge
if: |
github.event_name == 'push' &&
needs.check_gh_secrets.outputs.gha_dynamic_badges_gist_id_exists == 'true' &&
needs.check_gh_secrets.outputs.gha_dynamic_badges_gist_scope_token_exists == 'true' &&
always()
uses: Schneegans/[email protected]
with:
auth: ${{ secrets.GHA_DYNAMIC_BADGES_GIST_SCOPE_TOKEN }}
gistID: ${{ secrets.GHA_DYNAMIC_BADGES_GIST_ID }}
filename: Android.json
label: Android Build
message: ${{ steps.unity_builder.conclusion }}
color: lightgrey
namedLogo: unity
# Builds the Unity project with WebGL as the target platform.
build_unity_project_webgl:
name: Build Unity Project (WebGL)
needs: [ check_gh_secrets, check_skip_commits ]
runs-on: ubuntu-latest
outputs:
build_version: ${{ steps.unity_builder.outputs.buildVersion }}
if: |
needs.check_gh_secrets.outputs.unity_license_exists == 'true' &&
needs.check_skip_commits.outputs.skip_build != 'true' &&
needs.check_skip_commits.outputs.skip_webgl != 'true'
steps:
# This action checks-out your repository under $GITHUB_WORKSPACE, so your workflow can access it.
- name: Checkout
id: checkout
uses: actions/[email protected]
with:
lfs: true
# This action allows caching dependencies and build outputs to improve workflow execution time.
- name: Cache
id: cache
uses: actions/[email protected]
with:
path: ${{ env.PROJECT_PATH }}/Library
key: Library-WebGL
restore-keys: |
Library-
Library
# GitHub Action to build Unity projects for different platforms. Part of the GameCI open source project.
- name: Unity - Builder
id: unity_builder
uses: game-ci/[email protected]
with:
projectPath: ${{ env.PROJECT_PATH }}
unityVersion: ${{ env.UNITY_VERSION }}
targetPlatform: WebGL
versioning: Semantic
githubToken: ${{ secrets.GITHUB_TOKEN }}
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
# This uploads artifacts from your workflow allowing you to share data between jobs and store data once a workflow is complete.
- name: Upload Build as Artifact
id: upload_artifact
uses: actions/upload-artifact@v2
with:
name: Build-WebGL-${{ steps.unity_builder.outputs.buildVersion }}
path: build
# This action allows you to create badges for your README.md with shields.io which may change with every commit.
- name: Update Build Status Badge
id: update_build_status_badge
if: |
github.event_name == 'push' &&
needs.check_gh_secrets.outputs.gha_dynamic_badges_gist_id_exists == 'true' &&
needs.check_gh_secrets.outputs.gha_dynamic_badges_gist_scope_token_exists == 'true' &&
always()
uses: Schneegans/[email protected]
with:
auth: ${{ secrets.GHA_DYNAMIC_BADGES_GIST_SCOPE_TOKEN }}
gistID: ${{ secrets.GHA_DYNAMIC_BADGES_GIST_ID }}
filename: WebGL.json
label: WebGL Build
message: ${{ steps.unity_builder.conclusion }}
color: lightgrey
namedLogo: unity
# Deploys the WebGL build into GitHub pages.
deploy_build_webgl:
name: Deploy Build (WebGL)
needs: [ build_unity_project_webgl ]
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
# This downloads artifacts from your build.
- name: Download WebGL Artifact
id: download_artifact
uses: actions/download-artifact@v2
with:
name: Build-WebGL-${{ needs.build_unity_project_webgl.outputs.build_version }}
path: build
# This is a GitHub Action to deploy your static files to GitHub Pages.
- name: Deploy to GitHub Pages
id: deploy_to_gh_pages
uses: peaceiris/[email protected]
with:
publish_branch: webgl
publish_dir: build/WebGL/WebGL
force_orphan: true
user_name: github-actions[bot]
user_email: github-actions[bot]@users.noreply.github.com
github_token: ${{ secrets.GITHUB_TOKEN }}