-
Notifications
You must be signed in to change notification settings - Fork 8
271 lines (252 loc) · 11.5 KB
/
build_and_test.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
name: Builds + Test
on:
push:
branches:
- develop
- master
- releasecandidate/*
pull_request:
branches:
- develop
- master
- releasecandidate/*
workflow_dispatch:
inputs:
createRelease:
description: 'Upload to GitHub Releases and itch.io?'
required: true
default: 'false'
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
# Get version number from ProjectSettings/ProjectSettings.asset -> PlayerSettings/bundleVersion
extractVersionNumber:
name: Extract project version number
runs-on: ubuntu-latest
outputs:
version_number: ${{ steps.extractVersionNumber_job.outputs.version_number }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Attempt extraction
id: extractVersionNumber_job
working-directory: unity-ggjj/
run: |
version_number=$(grep 'bundleVersion: ' ./ProjectSettings/ProjectSettings.asset)
version_number=${version_number:17}
echo "Version number: $version_number"
echo "version_number=$version_number" >> $GITHUB_OUTPUT
# Unity build
checkLicense:
name: Check if UNITY_SERIAL is set in github secrets
runs-on: ubuntu-latest
outputs:
is_unity_serial_set: ${{ steps.checkLicense_job.outputs.is_unity_serial_set }}
steps:
- name: Check whether Unity activation requests should be done
id: checkLicense_job
run: |
echo "Skip activation job: ${{ secrets.UNITY_SERIAL != '' }}"
echo "is_unity_serial_set=${{ secrets.UNITY_SERIAL != '' }}" >> $GITHUB_OUTPUT
activation:
name: Request activation file 🔑
needs: [checkLicense]
if: needs.checkLicense.outputs.is_unity_serial_set == 'false'
runs-on: ubuntu-latest
steps:
- name: Request manual activation file
id: getManualLicenseFile
uses: game-ci/[email protected]
with:
unityVersion: 2022.3.4f1
- name: Expose as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.getManualLicenseFile.outputs.filePath }}
path: ${{ steps.getManualLicenseFile.outputs.filePath }}
unityBuild:
name: Build for ${{ matrix.targetPlatform.outputName }}
needs: [extractVersionNumber, checkLicense]
if: needs.checkLicense.outputs.is_unity_serial_set == 'true'
strategy:
fail-fast: false
matrix:
targetPlatform: [
{ unityPlatform: "StandaloneOSX", outputName: "macOS" },
{ unityPlatform: "StandaloneWindows", outputName: "Windows-x86" },
{ unityPlatform: "StandaloneWindows64", outputName: "Windows-x64" },
{ unityPlatform: "StandaloneLinux64", outputName: "Linux-x64" },
{ unityPlatform: "WebGL", outputName: "WebGL" }
]
uses: ./.github/workflows/build_game.yml
with:
unityPlatform: ${{ matrix.targetPlatform.unityPlatform }}
outputName: ${{ matrix.targetPlatform.outputName }}
secrets: inherit
# Unity tests
generateTestMatrix:
name: Generate Test Matrix
needs: [checkLicense]
runs-on: ubuntu-latest
if: needs.checkLicense.outputs.is_unity_serial_set == 'true'
outputs:
testDirectories: ${{ steps.bashScript.outputs.testDirectories }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run script file
id: bashScript
run: |
relativeTestSuites="$(echo unity-ggjj/Assets/Tests/EditModeTests/Suites/*/) $(echo unity-ggjj/Assets/Tests/PlayModeTests/Suites/*/)"
regex='^[^\/]+\/[^\/]+\/[^\/]+\/([^\/]+)Tests\/[^\/]+\/([^\/]+)'
for subDirectory in $relativeTestSuites
do
echo $subDirectory
if [[ $subDirectory =~ $regex ]]
then
output="\"${BASH_REMATCH[1]}\", \"${BASH_REMATCH[2]}\"|$output"
fi
echo $output
done
output=$(echo $output | sed 's/| *$//g')
echo $output
relativeTestSuitesAsJSON="[[$(sed 's:|:], [:g' <<< $output)]]"
echo $relativeTestSuitesAsJSON
relativeTestSuitesAsJSON="{\"directories\":$relativeTestSuitesAsJSON}"
echo "testDirectories=$relativeTestSuitesAsJSON" >> $GITHUB_OUTPUT
echo $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
shell: bash
runUnityTests:
name: "Execute sharded tests"
needs: [generateTestMatrix, checkLicense]
if: needs.checkLicense.outputs.is_unity_serial_set == 'true'
permissions:
checks: write # allows dependabot PRs to set pull request checks
contents: read
pull-requests: write
strategy:
fail-fast: false
matrix: ${{fromJson(needs.generateTestMatrix.outputs.testDirectories)}}
uses: ./.github/workflows/execute_tests.yml
with:
subdirectory: ${{ matrix.directories[0] }}Tests/Suites/${{ matrix.directories[1] }}
testMode: ${{ matrix.directories[0] }}
secrets: inherit
# Releases
checkIfTagExists:
name: Check if tag exists
needs: [extractVersionNumber]
if: (github.event.inputs.createRelease == 'true' || (github.ref == 'refs/heads/master' && github.event_name == 'push'))
runs-on: ubuntu-latest
steps:
- name: Check if tag exists
uses: mukunku/[email protected]
id: checkTag
with:
tag: ${{ needs.extractVersionNumber.outputs.version_number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Fail if tag already exists
run: |
echo "Tag '${{ needs.extractVersionNumber.outputs.version_number }}' already exists: ${{ steps.checkTag.outputs.exists }}"
exit $([ "${{ steps.checkTag.outputs.exists }}" = 'true' ] && echo 1 || echo 0)
# GitHub Releases
createGitHubRelease:
name: Create GitHub Release
needs: [extractVersionNumber, checkIfTagExists, unityBuild]
if: (github.event.inputs.createRelease == 'true' || (github.ref == 'refs/heads/master' && github.event_name == 'push'))
runs-on: ubuntu-latest
steps:
- name: Download macOS
uses: actions/download-artifact@v4
with:
name: macOS-v${{ needs.extractVersionNumber.outputs.version_number }}
path: build/macOS-v${{ needs.extractVersionNumber.outputs.version_number }}
- name: Download Windows-x86
uses: actions/download-artifact@v4
with:
name: Windows-x86-v${{ needs.extractVersionNumber.outputs.version_number }}
path: build/Windows-x86-v${{ needs.extractVersionNumber.outputs.version_number }}
- name: Download Windows-x64
uses: actions/download-artifact@v4
with:
name: Windows-x64-v${{ needs.extractVersionNumber.outputs.version_number }}
path: build/Windows-x64-v${{ needs.extractVersionNumber.outputs.version_number }}
- name: Download Linux-x64
uses: actions/download-artifact@v4
with:
name: Linux-x64-v${{ needs.extractVersionNumber.outputs.version_number }}
path: build/Linux-x64-v${{ needs.extractVersionNumber.outputs.version_number }}
- name: Download WebGL
uses: actions/download-artifact@v4
with:
name: WebGL-v${{ needs.extractVersionNumber.outputs.version_number }}
path: build/WebGL-v${{ needs.extractVersionNumber.outputs.version_number }}
- name: Zip macOS
run: zip -r "build/macOS-v${{ needs.extractVersionNumber.outputs.version_number }}.zip" "build/macOS-v${{ needs.extractVersionNumber.outputs.version_number }}"
- name: Zip Windows-x86
run: zip -r "build/Windows-x86-v${{ needs.extractVersionNumber.outputs.version_number }}.zip" "build/Windows-x86-v${{ needs.extractVersionNumber.outputs.version_number }}"
- name: Zip Windows-x64
run: zip -r "build/Windows-x64-v${{ needs.extractVersionNumber.outputs.version_number }}.zip" "build/Windows-x64-v${{ needs.extractVersionNumber.outputs.version_number }}"
- name: Zip Linux-x64
run: zip -r "build/Linux-x64-v${{ needs.extractVersionNumber.outputs.version_number }}.zip" "build/Linux-x64-v${{ needs.extractVersionNumber.outputs.version_number }}"
- name: Zip WebGL
run: zip -r "build/WebGL-v${{ needs.extractVersionNumber.outputs.version_number }}.zip" "build/WebGL-v${{ needs.extractVersionNumber.outputs.version_number }}"
- name: Create GitHub Release
uses: ncipollo/[email protected]
with:
# glob-files need to be escaped
artifacts: |
build/macOS-v${{ needs.extractVersionNumber.outputs.version_number }}.zip,
build/Windows-x86-v${{ needs.extractVersionNumber.outputs.version_number }}.zip,
build/Windows-x64-v${{ needs.extractVersionNumber.outputs.version_number }}.zip,
build/Linux-x64-v${{ needs.extractVersionNumber.outputs.version_number }}.zip,
build/WebGL-v${{ needs.extractVersionNumber.outputs.version_number }}.zip
artifactErrorsFailBuild: true
tag: ${{ needs.extractVersionNumber.outputs.version_number }}
name: "Release #${{ needs.extractVersionNumber.outputs.version_number }}"
token: ${{ secrets.GITHUB_TOKEN }}
# itch.io uploader
checkItchIO:
name: Check if ITCHIO_APIKEY is set in github secrets
runs-on: ubuntu-latest
outputs:
is_ITCHIO_set: ${{ steps.checkItchIO_job.outputs.is_ITCHIO_set }}
steps:
- name: Check whether an itch.io build should be pushed
id: checkItchIO_job
run: |
echo "Push itch.io build: ${{ secrets.ITCHIO_APIKEY != '' && secrets.ITCHIO_USERNAME != '' && secrets.ITCHIO_PROJECTNAME != '' }}"
echo "is_ITCHIO_set=${{ secrets.ITCHIO_APIKEY != '' && secrets.ITCHIO_USERNAME != '' && secrets.ITCHIO_PROJECTNAME != '' }}" >> $GITHUB_OUTPUT
createItchIORelease:
name: Create/update itch.io for ${{ matrix.platforms.outputName }}
needs: [extractVersionNumber, checkIfTagExists, unityBuild, checkItchIO]
if: (github.event.inputs.createRelease == 'true' || (github.ref == 'refs/heads/master' && github.event_name == 'push')) && needs.checkItchIO.outputs.is_ITCHIO_set == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platforms: [
{ outputName: "macOS", itchIOChannel: "mac" },
{ outputName: "Windows-x86", itchIOChannel: "windows-x86" },
{ outputName: "Windows-x64", itchIOChannel: "windows-x64" },
{ outputName: "Linux-x64", itchIOChannel: "linux" },
{ outputName: "WebGL", itchIOChannel: "webGL" }
]
steps:
- name: Download ${{ matrix.platforms.outputName }}
uses: actions/download-artifact@v4
with:
name: ${{ matrix.platforms.outputName }}-v${{ needs.extractVersionNumber.outputs.version_number }}
path: build/${{ matrix.platforms.outputName }}-v${{ needs.extractVersionNumber.outputs.version_number }}
- name: Create itch.io '${{ matrix.platforms.itchIOChannel }}' Release
uses: josephbmanley/butler-publish-itchio-action@master
env:
BUTLER_CREDENTIALS: ${{ secrets.ITCHIO_APIKEY }}
CHANNEL: ${{ matrix.platforms.itchIOChannel }}
ITCH_GAME: ${{ secrets.ITCHIO_PROJECTNAME }}
ITCH_USER: ${{ secrets.ITCHIO_USERNAME }}
PACKAGE: build/${{ matrix.platforms.outputName }}-v${{ needs.extractVersionNumber.outputs.version_number }}
VERSION: ${{ needs.extractVersionNumber.outputs.version_number }}