-
Notifications
You must be signed in to change notification settings - Fork 4
446 lines (446 loc) · 19.3 KB
/
build.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
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
name: Biên dịch QLTK và Game
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
permissions:
actions: write
jobs:
cronjob-based-github-action:
name: Cronjob based github action (Keep workflow alive)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gautamkrishnar/keepalive-workflow@v2
check-new-commit:
name: Kiểm tra commit mới
runs-on: windows-latest
outputs:
cancel: ${{ steps.check_hash.outputs.cancel }}
strategy:
fail-fast: false
env:
cache-key: latest-commit
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lấy hash commit mới nhất
run: |
$commit = git ls-remote https://github.com/${{ secrets.SOURCE_CODE_REPOSITORY }}.git ${{ secrets.SOURCE_CODE_BRANCH }}
$hash = $commit.Split("`t")[0]
echo "LATEST_COMMIT=$hash" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Cache hash commit
id: cache-restore
uses: actions/cache/restore@v4
with:
path: latest-commit.txt
key: ${{ env.cache-key }}
- name: kiểm tra hash
id: check_hash
run: $hash = "${{ env.LATEST_COMMIT }}"; if ((Test-Path latest-commit.txt -PathType Leaf)) { $commitContent = Get-Content -Path latest-commit.txt; $output = ($commitContent -eq $hash).ToString().ToLower(); } else { $output = "false" } $output = "cancel=$output".ToString().ToLower(); echo $output | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Lấy hash commit mới nhất
run: echo "${{ env.LATEST_COMMIT }}" > latest-commit.txt
- name: Xóa cache trước đó
if: ${{ steps.cache-restore.outputs.cache-hit }}
continue-on-error: true
run: gh cache delete "${{ env.cache-key }}" --repo ${{ github.repository }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Lưu cache mới
uses: actions/cache/save@v4
with:
path: latest-commit.txt
key: ${{ env.cache-key }}
cancel-current-workflow:
name: Hủy workflow hiện tại
needs: [check-new-commit]
runs-on: windows-latest
if: needs.check-new-commit.outputs.cancel == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Hủy workflow hiện tại
run: gh run cancel ${{ github.run_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-Account-Manager:
name: Biên dịch QLTK
needs: [check-new-commit]
if: needs.check-new-commit.outputs.cancel == 'false'
strategy:
matrix:
configuration: [Debug, Release]
runs-on: windows-latest
env:
Solution-Path: QLTK\QLTK.sln
steps:
- name: Clone
uses: actions/checkout@v4
with:
repository: ${{ secrets.SOURCE_CODE_REPOSITORY }}
ref: ${{ secrets.SOURCE_CODE_BRANCH }}
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
- name: Setup NuGet
uses: nuget/setup-nuget@v2
- name: Khôi phục dự án
run: msbuild ${{ env.Solution-Path }} /t:Restore /p:Configuration=$env:Configuration && nuget restore ${{ env.Solution-Path }}
env:
Configuration: ${{ matrix.configuration }}
- name: Biên dịch dự án
run: msbuild ${{ env.Solution-Path }} -t:rebuild -property:Configuration=$env:Configuration
env:
Configuration: ${{ matrix.configuration }}
- name: Upload file đã biên dịch
uses: actions/upload-artifact@v4
with:
name: QLTK-${{ matrix.configuration }}
path: QLTK/bin/${{ matrix.configuration }}
build-Unity-Windows:
name: Biên dịch StandaloneWindows trên máy chủ Windows
needs: [check-new-commit]
if: needs.check-new-commit.outputs.cancel == 'false'
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
targetPlatform:
- StandaloneWindows
- StandaloneWindows64
- StandaloneWindowsArm64
scriptingBackend:
- Mono2x # 0
- IL2CPP # 1
steps:
- name: Clone
uses: actions/checkout@v4
with:
repository: ${{ secrets.SOURCE_CODE_REPOSITORY }}
ref: ${{ secrets.SOURCE_CODE_BRANCH }}
- name: Cache
id: cache-restore
uses: actions/cache@v4
with:
path: GameProject/DragonBoy/Library
key: Library-Windows
- name: Tải artifact Build-${{ matrix.targetPlatform }}-${{ matrix.scriptingBackend }}
uses: dawidd6/action-download-artifact@v5
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow_search: true
workflow_conclusion: success
if_no_artifact_found: warn
allow_forks: false
name: Build-${{ matrix.targetPlatform }}-${{ matrix.scriptingBackend }}
path: build/${{ matrix.targetPlatform }}
- name: Biên dịch dự án
if: ${{ matrix.targetPlatform != 'StandaloneWindowsArm64' }}
uses: game-ci/unity-builder@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
targetPlatform: ${{ matrix.targetPlatform }}
projectPath: GameProject/DragonBoy
buildName: DragonBoy CommunityMod
versioning: Custom
version: 0.0.1
buildMethod: UnityBuilderAction.BuildScript.Build
customParameters: -scriptingBackend ${{ matrix.scriptingBackend }}
- name: Biên dịch dự án (Arm64)
if: ${{ matrix.targetPlatform == 'StandaloneWindowsArm64' }}
uses: game-ci/unity-builder@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
targetPlatform: StandaloneWindows64
projectPath: GameProject/DragonBoy
buildName: DragonBoy CommunityMod
versioning: Custom
version: 0.0.1
buildMethod: UnityBuilderAction.BuildScript.Build
customParameters: -scriptingBackend ${{ matrix.scriptingBackend }} -architecture ARM64
- name: Upload file game đã biên dịch
if: ${{ matrix.targetPlatform != 'StandaloneWindowsArm64' }}
uses: actions/upload-artifact@v4
with:
name: Build-${{ matrix.targetPlatform }}-${{ matrix.scriptingBackend }}
path: build/${{ matrix.targetPlatform }}
- name: Upload file game đã biên dịch (Arm64)
if: ${{ matrix.targetPlatform == 'StandaloneWindowsArm64' }}
uses: actions/upload-artifact@v4
with:
name: Build-${{ matrix.targetPlatform }}-${{ matrix.scriptingBackend }}
path: build/StandaloneWindows64
- name: Xóa cache trước đó
if: ${{ steps.cache-restore.outputs.cache-hit }}
continue-on-error: true
run: |
gh cache delete "Library-Windows" --repo ${{ github.repository }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Lưu cache
uses: actions/cache/save@v4
with:
path: GameProject/DragonBoy/Library
key: Library-Windows
build-Unity-Linux:
name: Biên dịch StandaloneLinux64 trên máy chủ Linux
needs: [check-new-commit]
if: needs.check-new-commit.outputs.cancel == 'false'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
targetPlatform:
- StandaloneLinux64
scriptingBackend:
- Mono2x # 0
- IL2CPP # 1
steps:
- name: Clone
uses: actions/checkout@v4
with:
repository: ${{ secrets.SOURCE_CODE_REPOSITORY }}
ref: ${{ secrets.SOURCE_CODE_BRANCH }}
- name: Cache
uses: actions/cache@v4
id: cache-restore
with:
path: GameProject/DragonBoy/Library
key: Library-Linux
- name: Tải artifact Build-${{ matrix.targetPlatform }}-${{ matrix.scriptingBackend }}
uses: dawidd6/action-download-artifact@v5
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow_search: true
workflow_conclusion: success
if_no_artifact_found: warn
allow_forks: false
name: Build-${{ matrix.targetPlatform }}-${{ matrix.scriptingBackend }}
path: build/${{ matrix.targetPlatform }}
- name: Giải phóng bộ nhớ
uses: jlumbroso/[email protected]
- name: Biên dịch dự án
uses: game-ci/unity-builder@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
targetPlatform: ${{ matrix.targetPlatform }}
projectPath: GameProject/DragonBoy
buildName: DragonBoy CommunityMod
versioning: Custom
version: 0.0.1
buildMethod: UnityBuilderAction.BuildScript.Build
customParameters: -scriptingBackend ${{ matrix.scriptingBackend }}
- name: Upload file game đã biên dịch
uses: actions/upload-artifact@v4
with:
name: Build-${{ matrix.targetPlatform }}-${{ matrix.scriptingBackend }}
path: build/${{ matrix.targetPlatform }}
- name: Xóa cache trước đó
if: ${{ steps.cache-restore.outputs.cache-hit }}
continue-on-error: true
run: |
gh cache delete "Library-Linux" --repo ${{ github.repository }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Lưu cache
uses: actions/cache/save@v4
with:
path: GameProject/DragonBoy/Library
key: Library-Linux
build-Unity-Android:
name: Biên dịch Android trên máy chủ Linux
needs: [check-new-commit]
if: needs.check-new-commit.outputs.cancel == 'false'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
targetPlatform:
- Android
scriptingBackend:
- Mono2x # 0
- IL2CPP # 1
steps:
- name: Clone
uses: actions/checkout@v4
with:
repository: ${{ secrets.SOURCE_CODE_REPOSITORY }}
ref: ${{ secrets.SOURCE_CODE_BRANCH }}
- name: Giải phóng bộ nhớ
uses: jlumbroso/[email protected]
- name: Cache
if: ${{ matrix.scriptingBackend == 'Mono2x' }}
uses: actions/cache@v4
id: cache-restore
with:
path: GameProject/DragonBoy/Library
key: Library-Linux
- name: Cache (IL2CPP)
if: ${{ matrix.scriptingBackend == 'IL2CPP' }}
uses: actions/cache@v4
id: cache-restore-il2cpp
with:
path: GameProject/DragonBoy/Library
key: Library-${{ matrix.targetPlatform }}-${{ matrix.scriptingBackend }}
- name: Tải artifact Build-${{ matrix.targetPlatform }}-${{ matrix.scriptingBackend }}
uses: dawidd6/action-download-artifact@v5
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow_search: true
workflow_conclusion: success
if_no_artifact_found: warn
allow_forks: false
name: Build-${{ matrix.targetPlatform }}-${{ matrix.scriptingBackend }}
path: build/${{ matrix.targetPlatform }}
- name: Biên dịch dự án
uses: game-ci/unity-builder@v4
# continue-on-error: true
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
targetPlatform: ${{ matrix.targetPlatform }}
androidKeystoreName: DragonBoy-pk9r327-UnityProject.keystore # This file won't exist, but this property needs to exist.
androidKeystoreBase64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
androidKeystorePass: ${{ secrets.ANDROID_KEYSTORE_PASS }}
androidKeyaliasName: ${{ secrets.ANDROID_KEYALIAS_NAME }}
androidKeyaliasPass: ${{ secrets.ANDROID_KEYALIAS_PASS }}
androidTargetSdkVersion: AndroidApiLevel29
projectPath: GameProject/DragonBoy
buildName: DragonBoy CommunityMod
versioning: Custom
version: 0.0.1
buildMethod: UnityBuilderAction.BuildScript.Build
customParameters: -scriptingBackend ${{ matrix.scriptingBackend }}
- name: Upload file game đã biên dịch
uses: actions/upload-artifact@v4
with:
name: Build-${{ matrix.targetPlatform }}-${{ matrix.scriptingBackend }}
path: build/${{ matrix.targetPlatform }}
- name: Xóa cache trước đó
if: ${{ steps.cache-restore.outputs.cache-hit }}
continue-on-error: true
run: |
gh cache delete "Library-Linux" --repo ${{ github.repository }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Xóa cache trước đó (IL2CPP)
if: ${{ steps.cache-restore-il2cpp.outputs.cache-hit }}
continue-on-error: true
run: |
gh cache delete "Library-${{ matrix.targetPlatform }}-${{ matrix.scriptingBackend }}" --repo ${{ github.repository }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Lưu cache
if: ${{ matrix.scriptingBackend == 'Mono2x' }}
uses: actions/cache/save@v4
with:
path: GameProject/DragonBoy/Library
key: Library-Linux
- name: Lưu cache (IL2CPP)
if: ${{ matrix.scriptingBackend == 'IL2CPP' }}
uses: actions/cache/save@v4
with:
path: GameProject/DragonBoy/Library
key: Library-${{ matrix.targetPlatform }}-${{ matrix.scriptingBackend }}
release-latest-artifacts:
name: Phát hành artiact mới nhất
runs-on: ubuntu-latest
needs: [build-Unity-Windows, build-Unity-Linux, build-Unity-Android, build-Account-Manager]
if: ${{ !cancelled() && (needs.build-Unity-Windows.result != 'cancelled' && needs.build-Unity-Linux.result != 'cancelled' && needs.build-Unity-Android.result != 'cancelled' && needs.build-Account-Manager.result != 'cancelled') && !(needs.build-Unity-Windows.result == 'skipped' && needs.build-Unity-Linux.result == 'skipped' && needs.build-Unity-Android.result == 'skipped' && needs.build-Account-Manager.result == 'skipped')}}
permissions:
contents: write
outputs:
release-url: ${{ steps.release-artifacts.outputs.url }}
steps:
- name: Tải artifact mới nhất
uses: dawidd6/action-download-artifact@v5
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow_conclusion: ""
if_no_artifact_found: warn
allow_forks: false
skip_unpack: true
path: artifacts
- name: Lấy danh sách artifact
run: |
echo 'artifacts<<EOF' >> $GITHUB_ENV
cd artifacts
ls -1 | xargs realpath >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Phát hành artifact
id: release-artifacts
uses: softprops/action-gh-release@v2
with:
files: ${{ env.artifacts }}
token: ${{ secrets.GITHUB_TOKEN }}
name: Latest build
draft: false
prerelease: false
tag_name: latest
send-artifact-links-announcement:
name: Gửi link artifact tới Discord webhook
needs: [build-Unity-Windows, build-Unity-Linux, build-Unity-Android, build-Account-Manager, release-latest-artifacts]
if: ${{ !cancelled() && (needs.build-Unity-Windows.result != 'cancelled' && needs.build-Unity-Linux.result != 'cancelled' && needs.build-Unity-Android.result != 'cancelled' && needs.build-Account-Manager.result != 'cancelled' && needs.release-latest-artifacts.result != 'cancelled') && needs.release-latest-artifacts.result != 'skipped' && !(needs.build-Unity-Windows.result == 'skipped' && needs.build-Unity-Linux.result == 'skipped' && needs.build-Unity-Android.result == 'skipped' && needs.build-Account-Manager.result == 'skipped') }}
runs-on: windows-latest
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
steps:
- name: Tạo thông báo để gửi tới Discord webhook
if: ${{ env.DISCORD_WEBHOOK != '' }}
run: |
$workflow_ref = "${{ github.workflow_ref }}".Substring(0, "${{ github.workflow_ref }}".IndexOf('@'));
$workflowFile = $workflow_ref.Split('/')[-1];
$artifactsAPIUrl = (Invoke-RestMethod -Uri "https://api.github.com/repos/${{ github.repository }}/actions/workflows/${workflowFile}/runs?per_page=1" -Headers @{Authorization = "Bearer ${{ secrets.GITHUB_TOKEN }}"}).workflow_runs[0].artifacts_url;
$artifacts = (Invoke-RestMethod -Uri $artifactsAPIUrl -Headers @{Authorization = "Bearer ${{ secrets.GITHUB_TOKEN }}"}).artifacts;
$buildAccountManager="${{ needs.build-Account-Manager.result }}";
$buildUnityLinux="${{ needs.build-Unity-Linux.result }}";
$buildUnityWindows="${{ needs.build-Unity-Windows.result }}";
$buildUnityAndroid="${{ needs.build-Unity-Android.result }}";
$failure_count = 0;
if ($buildAccountManager -eq "failure") {$failure_count++} if ($buildUnityLinux -eq "failure") {$failure_count++} if ($buildUnityWindows -eq "failure") {$failure_count++} if ($buildUnityAndroid -eq "failure") {$failure_count++}
if ($failure_count -eq 4) {$color = 0xff0000} elseif ($failure_count -eq 3) {$color = 0xff5a00} elseif ($failure_count -eq 2) {$color = 0xffa500} elseif ($failure_count -eq 1) {$color = 0xffff00} else {$color = 0x00ff00}
$output = "Kết quả:";
if (${buildAccountManager} -ne "skipped") {
$output += "`r`n- Biên dịch QLTK: **${buildAccountManager}**";
}
if (${buildUnityWindows} -ne "skipped") {
$output += "`r`n- Biên dịch Game cho HĐH Windows: **${buildUnityWindows}**";
}
if (${buildUnityLinux} -ne "skipped") {
$output += "`r`n- Biên dịch Game cho HĐH Linux: **${buildUnityLinux}**";
}
if (${buildUnityAndroid} -ne "skipped") {
$output += "`r`n- Biên dịch Game cho HĐH Android: **${buildUnityAndroid}**";
}
if ($artifacts.Count -gt 0) {
$output += "`r`n------------------------------------------------";
$output += "`r`n[Latest release](${{ needs.release-latest-artifacts.outputs.release-url }})"
$output += "`r`n------------------------------------------------";
$output += "`r`n$($artifacts.Count) Artifact:"
}
for ($i = 0; $i -le $artifacts.Count - 1; $i++) {
$output += "`r`n$i. [$($artifacts[$i].name)](${{ github.event.repository.html_url }}/actions/runs/$($artifacts[$i].workflow_run.id)/artifacts/$($artifacts[$i].id))"
}
$payload = [PSCustomObject]@{
username = "GitHub Actions Webhook"
embeds = @(
@{
title = "${{ github.event.repository.name }}"
url = "${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}"
description = $output
color = $color
timestamp = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ssZ")
}
)
}
Invoke-RestMethod -Uri ${{ env.DISCORD_WEBHOOK }} -Method Post -Body (ConvertTo-Json $payload) -ContentType "application/json"