-
Notifications
You must be signed in to change notification settings - Fork 0
501 lines (453 loc) · 20.5 KB
/
Copy pathaddressables-deploy.yml
File metadata and controls
501 lines (453 loc) · 20.5 KB
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
name: Addressables Deploy
# ============================================
# Addressables ビルド&R2アップロード
#
# 使用例:
# gh workflow run "Addressables Deploy" --field build_target=StandaloneWindows64
# gh workflow run "Addressables Deploy" --field build_target=All --field deploy=true
# ============================================
on:
workflow_dispatch:
inputs:
build_target:
description: 'Build target platform'
required: true
default: 'StandaloneWindows64'
type: choice
options:
- StandaloneWindows64
- StandaloneLinux64
- StandaloneOSX
- WebGL
- Android
- iOS
- All
deploy:
description: 'Deploy to Cloudflare R2'
required: false
default: true
type: boolean
dry_run:
description: 'Dry run (do not actually upload)'
required: false
default: false
type: boolean
game_environment:
description: 'Game environment for Addressables profile'
required: true
default: 'Develop'
type: choice
options:
- Develop
- Staging
- Review
- Release
clean_build:
description: 'Clean Library/com.unity.addressables before build (ensures catalog and bundles are in sync)'
required: false
default: false
type: boolean
concurrency:
group: ${{ github.workflow }}-${{ github.run_id }}
cancel-in-progress: false
env:
R2_BUCKET_NAME: unity6-portfolio
R2_CUSTOM_DOMAIN: rei-unity6-portfolio.com
jobs:
# ============================================
# 設定読み込み
# ============================================
load-config:
name: Load Configuration
runs-on: [self-hosted, linux, unity, docker]
outputs:
unity_project_path: ${{ steps.config.outputs.UNITY_PROJECT_PATH }}
build_timestamp: ${{ steps.timestamp.outputs.value }}
# build / deploy 両方で使う matrix include 配列を動的生成(job-level `if` で matrix を参照できないため)
build_matrix: ${{ steps.matrix.outputs.value }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
sparse-checkout: .github
- name: Generate build timestamp
id: timestamp
run: echo "value=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_OUTPUT
- name: Generate build matrix
id: matrix
run: |
# 対応 runner があるプラットフォームのみ matrix に含める
# WebGL / Android / macOS / iOS は scope 外(runner 未配置)→ 入力されても matrix が空 → job スキップ
WIN='{"platform":"StandaloneWindows64","build_target":"Win64","runner_label":"windows-mono"}'
LINUX='{"platform":"StandaloneLinux64","build_target":"Linux64","runner_label":"linux-il2cpp"}'
case "${{ inputs.build_target }}" in
All) MATRIX="[${WIN},${LINUX}]" ;;
StandaloneWindows64) MATRIX="[${WIN}]" ;;
StandaloneLinux64) MATRIX="[${LINUX}]" ;;
*) MATRIX="[]" ;;
esac
echo "value=${MATRIX}" >> "$GITHUB_OUTPUT"
echo "Generated matrix: ${MATRIX}"
- name: Load configuration
id: config
run: |
chmod +x .github/scripts/load-config.sh
.github/scripts/load-config.sh
# ============================================
# Addressables ビルド(マトリックス)
# ============================================
build-addressables:
name: Build Addressables (${{ matrix.platform }})
# platform 別に self-hosted runner を振り分け(matrix.runner_label で AND マッチング)
runs-on: [self-hosted, linux, unity, docker, "${{ matrix.runner_label }}"]
needs: load-config
timeout-minutes: 720
strategy:
fail-fast: false
# load-config が input に応じて生成した matrix を使う
# (job-level `if` で matrix context は使えないため、matrix 自体を空にして job をスキップする方式)
matrix:
include: ${{ fromJSON(needs.load-config.outputs.build_matrix) }}
env:
UNITY_PROJECT_PATH: ${{ needs.load-config.outputs.unity_project_path }}
BUILD_TIMESTAMP: ${{ needs.load-config.outputs.build_timestamp }}
GAME_ENVIRONMENT: ${{ inputs.game_environment }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
lfs: false
clean: false
- name: Setup Library cache
run: |
chmod +x .github/scripts/setup-library-cache.sh
.github/scripts/setup-library-cache.sh "${{ env.UNITY_PROJECT_PATH }}" "${{ matrix.build_target }}"
- name: Setup directories
run: |
mkdir -p "${{ github.workspace }}/Logs"
mkdir -p "${{ env.UNITY_PROJECT_PATH }}/ServerData"
- name: Clean Addressables Library (optional)
if: inputs.clean_build == true
run: |
echo "=== Clean Build Requested ==="
# 1. Library/com.unity.addressables を削除
ADDRESSABLES_LIB="${{ env.UNITY_PROJECT_PATH }}/Library/com.unity.addressables"
echo "Checking: $ADDRESSABLES_LIB"
if [ -d "$ADDRESSABLES_LIB" ]; then
rm -rf "$ADDRESSABLES_LIB"
echo " Removed: $ADDRESSABLES_LIB"
else
echo " Not found (skipped)"
fi
# 2. ServerData を削除
SERVER_DATA="${{ env.UNITY_PROJECT_PATH }}/ServerData/${{ matrix.platform }}"
echo "Checking: $SERVER_DATA"
if [ -d "$SERVER_DATA" ]; then
rm -rf "$SERVER_DATA"
echo " Removed: $SERVER_DATA"
else
echo " Not found (skipped)"
fi
# 3. Assets/AddressableAssetsData/{platform}/ を削除 (増分ビルドキャッシュ)
# これらのファイルが古いと、カタログが古いバンドルハッシュを参照してしまう
case "${{ matrix.platform }}" in
StandaloneWindows64) PLATFORM_FOLDER="Windows" ;;
StandaloneLinux64) PLATFORM_FOLDER="Linux64" ;;
StandaloneOSX) PLATFORM_FOLDER="OSXUniversal" ;;
*) PLATFORM_FOLDER="${{ matrix.platform }}" ;;
esac
PLATFORM_DATA="${{ env.UNITY_PROJECT_PATH }}/Assets/AddressableAssetsData/$PLATFORM_FOLDER"
echo "Checking: $PLATFORM_DATA"
if [ -d "$PLATFORM_DATA" ]; then
rm -rf "$PLATFORM_DATA"
echo " Removed: $PLATFORM_DATA"
else
echo " Not found (skipped)"
fi
echo "=== Clean Complete ==="
echo "Fresh Addressables build will be performed."
- name: Build Addressables
run: |
source .github/scripts/setup-accelerator.sh
xvfb-run --auto-servernum --server-args='-screen 0 1920x1080x24' \
unity-editor \
-batchmode \
-nographics \
-quit \
-projectPath "${{ env.UNITY_PROJECT_PATH }}" \
-buildTarget "${{ matrix.build_target }}" \
$ACCELERATOR_ARGS \
-executeMethod Game.Editor.Build.AddressablesR2Uploader.BuildAddressablesCI \
-logFile "${{ github.workspace }}/Logs/addressables-build-${{ matrix.platform }}.log"
- name: List build output
run: |
echo "=== ServerData contents ==="
ls -la "${{ env.UNITY_PROJECT_PATH }}/ServerData/" || echo "ServerData not found"
if [ -d "${{ env.UNITY_PROJECT_PATH }}/ServerData/${{ matrix.platform }}" ]; then
echo "=== ${{ matrix.platform }} contents ==="
ls -la "${{ env.UNITY_PROJECT_PATH }}/ServerData/${{ matrix.platform }}/"
echo "=== File count and size ==="
find "${{ env.UNITY_PROJECT_PATH }}/ServerData/${{ matrix.platform }}" -type f | wc -l
du -sh "${{ env.UNITY_PROJECT_PATH }}/ServerData/${{ matrix.platform }}"
fi
echo ""
echo "=== Library/com.unity.addressables contents ==="
ADDRESSABLES_LIB="${{ env.UNITY_PROJECT_PATH }}/Library/com.unity.addressables"
if [ -d "$ADDRESSABLES_LIB" ]; then
find "$ADDRESSABLES_LIB" -type f | head -30
echo "..."
echo "Total files:"
find "$ADDRESSABLES_LIB" -type f | wc -l
du -sh "$ADDRESSABLES_LIB"
else
echo "Library/com.unity.addressables not found"
fi
- name: Collect LocalBundles
run: |
ADDRESSABLES_LIB="${{ env.UNITY_PROJECT_PATH }}/Library/com.unity.addressables"
LOCALBUNDLES_DIR="${{ github.workspace }}/LocalBundles-${{ matrix.platform }}"
echo "Collecting LocalBundles from: $ADDRESSABLES_LIB"
echo "Output directory: $LOCALBUNDLES_DIR"
if [ ! -d "$ADDRESSABLES_LIB" ]; then
echo "ERROR: Library/com.unity.addressables not found!"
exit 1
fi
# Copy entire com.unity.addressables folder
mkdir -p "$LOCALBUNDLES_DIR"
cp -r "$ADDRESSABLES_LIB/"* "$LOCALBUNDLES_DIR/"
echo "=== Collected files ==="
find "$LOCALBUNDLES_DIR" -type f | head -20
echo "..."
echo "Total: $(find "$LOCALBUNDLES_DIR" -type f | wc -l) files"
- name: Generate index.json
run: |
LOCALBUNDLES_DIR="${{ github.workspace }}/LocalBundles-${{ matrix.platform }}"
# Determine platform folder name (Windows for StandaloneWindows64)
case "${{ matrix.platform }}" in
StandaloneWindows64) PLATFORM_FOLDER="Windows" ;;
StandaloneLinux64) PLATFORM_FOLDER="Linux64" ;;
StandaloneOSX) PLATFORM_FOLDER="OSXUniversal" ;;
*) PLATFORM_FOLDER="${{ matrix.platform }}" ;;
esac
# Read catalog.hash
CATALOG_HASH_FILE="$LOCALBUNDLES_DIR/aa/$PLATFORM_FOLDER/catalog.hash"
if [ -f "$CATALOG_HASH_FILE" ]; then
CATALOG_HASH=$(cat "$CATALOG_HASH_FILE" | tr -d '\n\r')
echo "Catalog hash: $CATALOG_HASH"
else
echo "WARNING: catalog.hash not found at $CATALOG_HASH_FILE"
CATALOG_HASH=""
fi
# Generate file list
cd "$LOCALBUNDLES_DIR"
FILES=$(find . -type f -name "*" | sed 's|^\./||' | sort)
# Create JSON using jq
echo "$FILES" | jq -R -s --arg hash "$CATALOG_HASH" '
{
catalogHash: $hash,
files: (split("\n") | map(select(length > 0)))
}
' > index.json
echo "=== Generated index.json ==="
cat index.json
echo ""
echo "File count: $(echo "$FILES" | wc -l)"
- name: Upload Addressables artifact (ServerData)
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: Addressables-${{ matrix.platform }}-${{ env.BUILD_TIMESTAMP }}
path: ${{ env.UNITY_PROJECT_PATH }}/ServerData/${{ matrix.platform }}
retention-days: 7
if-no-files-found: error
- name: Upload LocalBundles artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: LocalBundles-${{ matrix.platform }}-${{ env.BUILD_TIMESTAMP }}
path: ${{ github.workspace }}/LocalBundles-${{ matrix.platform }}
retention-days: 7
if-no-files-found: error
- name: Upload build log
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: always()
with:
name: Addressables-Log-${{ matrix.platform }}-${{ env.BUILD_TIMESTAMP }}
path: Logs/addressables-build-${{ matrix.platform }}.log
# ============================================
# R2 アップロード
# ============================================
deploy-to-r2:
name: Deploy to R2 (${{ matrix.platform }})
# 軽量タスク(rclone のみ)。任意の self-hosted runner で実行可
runs-on: [self-hosted, linux, unity, docker]
needs: [load-config, build-addressables]
if: inputs.deploy == true
timeout-minutes: 360
strategy:
fail-fast: false
# build-addressables と同じ matrix を共有(platform フィールドのみ参照)
matrix:
include: ${{ fromJSON(needs.load-config.outputs.build_matrix) }}
env:
BUILD_TIMESTAMP: ${{ needs.load-config.outputs.build_timestamp }}
steps:
- name: Download Addressables artifact (ServerData)
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: Addressables-${{ matrix.platform }}-${{ env.BUILD_TIMESTAMP }}
path: ./ServerData/${{ matrix.platform }}
- name: Download LocalBundles artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: LocalBundles-${{ matrix.platform }}-${{ env.BUILD_TIMESTAMP }}
path: ./LocalBundles/${{ matrix.platform }}
- name: List downloaded files
run: |
echo "=== Downloaded ServerData files ==="
ls -la ./ServerData/${{ matrix.platform }}/
echo "=== File count and size ==="
find ./ServerData/${{ matrix.platform }} -type f | wc -l
du -sh ./ServerData/${{ matrix.platform }}
echo ""
echo "=== Downloaded LocalBundles files ==="
find ./LocalBundles/${{ matrix.platform }} -type f | head -20
echo "..."
echo "Total: $(find ./LocalBundles/${{ matrix.platform }} -type f | wc -l) files"
du -sh ./LocalBundles/${{ matrix.platform }}
- name: Install rclone
run: |
if ! command -v rclone &> /dev/null && [ ! -f "$HOME/.local/bin/rclone" ]; then
echo "Installing rclone to user directory..."
mkdir -p "$HOME/.local/bin"
cd /tmp
curl -sO https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip -q rclone-current-linux-amd64.zip
cp rclone-*-linux-amd64/rclone "$HOME/.local/bin/"
chmod +x "$HOME/.local/bin/rclone"
rm -rf rclone-*-linux-amd64*
echo "$HOME/.local/bin" >> $GITHUB_PATH
echo "rclone installed: $($HOME/.local/bin/rclone version | head -1)"
else
echo "rclone already installed: $(rclone version | head -1)"
fi
- name: Configure rclone
env:
R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
run: |
mkdir -p ~/.config/rclone
printf '[r2]\ntype = s3\nprovider = Cloudflare\naccess_key_id = %s\nsecret_access_key = %s\nendpoint = https://%s.r2.cloudflarestorage.com\nacl = private\nno_check_bucket = true\n' \
"${R2_ACCESS_KEY_ID}" "${R2_SECRET_ACCESS_KEY}" "${R2_ACCOUNT_ID}" \
> ~/.config/rclone/rclone.conf
echo "rclone configured for R2"
- name: Verify R2 connection
run: |
echo "Testing R2 connection..."
# バケット単位でスコープされたトークンでは ListBuckets (lsd r2:) が失敗するため
# バケットを直接指定してテスト
rclone ls r2:${{ env.R2_BUCKET_NAME }} --max-depth 0 2>&1 || true
echo "R2 connection configured (bucket: ${{ env.R2_BUCKET_NAME }})"
- name: Upload ServerData to R2
env:
DRY_RUN: ${{ inputs.dry_run && '--dry-run' || '' }}
FORCE_UPLOAD: ${{ inputs.clean_build && '--ignore-times' || '' }}
run: |
echo "Uploading ServerData (${{ matrix.platform }}) to R2..."
echo "Destination: r2:${{ env.R2_BUCKET_NAME }}/${{ matrix.platform }}"
[ -n "$FORCE_UPLOAD" ] && echo "Force upload enabled (clean build)"
rclone sync \
./ServerData/${{ matrix.platform }} \
r2:${{ env.R2_BUCKET_NAME }}/${{ matrix.platform }} \
--checksum \
$FORCE_UPLOAD \
--transfers 8 \
--checkers 16 \
--progress \
--stats-one-line \
--stats 5s \
$DRY_RUN
echo "ServerData upload completed"
- name: Upload LocalBundles to R2
env:
DRY_RUN: ${{ inputs.dry_run && '--dry-run' || '' }}
FORCE_UPLOAD: ${{ inputs.clean_build && '--ignore-times' || '' }}
run: |
echo "Uploading LocalBundles (${{ matrix.platform }}) to R2..."
echo "Destination: r2:${{ env.R2_BUCKET_NAME }}/${{ matrix.platform }}/LocalBundles"
[ -n "$FORCE_UPLOAD" ] && echo "Force upload enabled (clean build)"
rclone sync \
./LocalBundles/${{ matrix.platform }} \
r2:${{ env.R2_BUCKET_NAME }}/${{ matrix.platform }}/LocalBundles \
--checksum \
$FORCE_UPLOAD \
--transfers 8 \
--checkers 16 \
--progress \
--stats-one-line \
--stats 5s \
$DRY_RUN
echo "LocalBundles upload completed"
- name: Verify upload
if: inputs.dry_run == false
run: |
echo "=== Verifying uploaded ServerData files ==="
rclone ls r2:${{ env.R2_BUCKET_NAME }}/${{ matrix.platform }}/ --max-depth 1 | head -20
echo ""
echo "=== Verifying uploaded LocalBundles files ==="
rclone ls r2:${{ env.R2_BUCKET_NAME }}/${{ matrix.platform }}/LocalBundles/ | head -20
echo "..."
echo "Total LocalBundles files:"
rclone ls r2:${{ env.R2_BUCKET_NAME }}/${{ matrix.platform }}/LocalBundles/ | wc -l
- name: Output URLs
if: inputs.dry_run == false
run: |
echo "=========================================="
echo "Deployment Complete!"
echo "=========================================="
echo ""
echo "Access URLs:"
echo " Catalog: https://${{ env.R2_CUSTOM_DOMAIN }}/${{ matrix.platform }}/catalog_*.bin"
echo " LocalBundles: https://${{ env.R2_CUSTOM_DOMAIN }}/${{ matrix.platform }}/LocalBundles/"
echo " Index: https://${{ env.R2_CUSTOM_DOMAIN }}/${{ matrix.platform }}/LocalBundles/index.json"
echo " Base: https://${{ env.R2_CUSTOM_DOMAIN }}/${{ matrix.platform }}/"
echo ""
# ============================================
# サマリー出力
# ============================================
summary:
name: Deployment Summary
runs-on: ubuntu-latest
needs: [load-config, build-addressables, deploy-to-r2]
if: always()
env:
BUILD_TIMESTAMP: ${{ needs.load-config.outputs.build_timestamp }}
steps:
- name: Generate summary
run: |
echo "## Addressables Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Timestamp:** ${{ env.BUILD_TIMESTAMP }}" >> $GITHUB_STEP_SUMMARY
echo "**Target:** ${{ inputs.build_target }}" >> $GITHUB_STEP_SUMMARY
echo "**Environment:** ${{ inputs.game_environment }}" >> $GITHUB_STEP_SUMMARY
echo "**Deploy:** ${{ inputs.deploy }}" >> $GITHUB_STEP_SUMMARY
echo "**Dry Run:** ${{ inputs.dry_run }}" >> $GITHUB_STEP_SUMMARY
echo "**Clean Build:** ${{ inputs.clean_build }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ inputs.deploy }}" == "true" ] && [ "${{ inputs.dry_run }}" == "false" ]; then
echo "### Deployed URLs" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ inputs.build_target }}" == "All" ]; then
for platform in StandaloneWindows64 StandaloneLinux64; do
echo "- **${platform}:** https://${{ env.R2_CUSTOM_DOMAIN }}/${platform}/" >> $GITHUB_STEP_SUMMARY
done
else
echo "- **${{ inputs.build_target }}:** https://${{ env.R2_CUSTOM_DOMAIN }}/${{ inputs.build_target }}/" >> $GITHUB_STEP_SUMMARY
fi
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Build Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Build | ${{ needs.build-addressables.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Deploy | ${{ needs.deploy-to-r2.result }} |" >> $GITHUB_STEP_SUMMARY