-
Notifications
You must be signed in to change notification settings - Fork 1
261 lines (234 loc) · 8.85 KB
/
Copy pathbuild-unitycloud.yml
File metadata and controls
261 lines (234 loc) · 8.85 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
name: Unity Cloud Build
on:
push:
branches:
- main
tags:
- 'v*'
workflow_dispatch:
inputs:
development_build:
description: 'Development Build'
required: false
default: true
type: boolean
clean_build:
description: 'Clean Build'
required: false
default: false
type: boolean
cache_strategy:
description: 'Select cache strategy'
required: true
default: 'library'
type: choice
options:
- none
- library
- workspace
- inherit
jobs:
prebuild:
name: Prebuild
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
commit_sha: ${{ steps.get_commit_sha.outputs.commit_sha }}
options: ${{ steps.get_options.outputs.options }}
version: ${{ steps.get_version.outputs.full_version }}
clean_build: ${{ steps.set_defaults.outputs.clean_build }}
cache_strategy: ${{ steps.set_defaults.outputs.cache_strategy }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Get commit SHA
id: get_commit_sha
run: |
echo "commit_sha=$GITHUB_SHA" >> $GITHUB_OUTPUT
- name: Debug Commit SHA
run: |
echo "Ref from Pull Request: ${{ github.event.pull_request.head.sha }}"
echo "Full Commit from git rev-parse: $(git rev-parse $GITHUB_SHA)"
echo "HEAD Commit: $(git rev-parse HEAD)"
- name: Get version
id: get_version
run: |
TAG=$(git describe --tags --abbrev=0)
VERSION=${TAG#v}
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
echo "version=$VERSION" >> $GITHUB_OUTPUT
else
COMMIT_SHA="${{ steps.get_commit_sha.outputs.commit_sha }}"
SHORT_SHA=${COMMIT_SHA:0:7}
echo "version=$VERSION-$SHORT_SHA" >> $GITHUB_OUTPUT
fi
- name: Set default values
id: set_defaults
run: |
# Clean build logic
if [ "${{ github.event.inputs.clean_build }}" ]; then
clean_build=${{ github.event.inputs.clean_build }}
elif [[ "$GITHUB_REF" == refs/tags/* ]]; then
clean_build=true
else
clean_build=false
fi
echo "Set clean_build to: $clean_build"
echo "clean_build=${clean_build}" >> $GITHUB_OUTPUT
if [ "${{ github.event.inputs.cache_strategy }}" ]; then
cache_strategy=${{ github.event.inputs.cache_strategy }}
elif [[ "$GITHUB_REF" == refs/tags/* ]]; then
cache_strategy='none'
else
cache_strategy='library'
fi
echo "Set cache_strategy to: $cache_strategy"
echo "cache_strategy=${cache_strategy}" >> $GITHUB_OUTPUT
- name: Get BuildOptions
id: get_options
run: |
#!/bin/bash
#options=("DetailedBuildReport")
options=()
# development build
development="${{ github.event.inputs.development_build }}"
if [[ "$development" == "true" ]]; then
options+=("Development")
fi
# Write the array as a comma-separated string
# Set the Internal Field Separator to comma
IFS=,
echo "options=${options[*]}" >> "$GITHUB_OUTPUT"
build:
name: Build
runs-on: ubuntu-latest
needs: prebuild
timeout-minutes: 360
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref_name }}
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: 3.12.3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r .github/scripts/requirements.txt
- name: Execute Unity Cloud build
uses: nick-fields/retry@v3
with:
timeout_minutes: 180 # matches your GLOBAL_TIMEOUT = 10800s
max_attempts: 3
retry_on: any
retry_wait_seconds: 30
on_retry_command: |
echo "::warning::🔁 Unity Cloud Build retry triggered at $(date '+%Y-%m-%d %H:%M:%S')"
command: |
echo "🔧 Starting Unity Cloud Build attempt at $(date '+%Y-%m-%d %H:%M:%S')"
python -u .github/scripts/build.py
env:
API_KEY: ${{ secrets.UNITY_CLOUD_API_KEY }}
ORG_ID: ${{ secrets.UNITY_CLOUD_ORG_ID }}
PROJECT_ID: ${{ secrets.UNITY_CLOUD_PROJECT_ID }}
POLL_TIME: 60 # Set the polling time in seconds
GLOBAL_TIMEOUT: 10800 # Set the global timeout in seconds (e.g., 3 hours)
TARGET: t_web
REF_NAME: ${{ github.ref_name }}
COMMIT_SHA: ${{ needs.prebuild.outputs.commit_sha }}
BUILD_OPTIONS: ${{ needs.prebuild.outputs.options }}
CLEAN_BUILD: ${{ needs.prebuild.outputs.clean_build }}
CACHE_STRATEGY: ${{ needs.prebuild.outputs.cache_strategy }}
IS_RELEASE_BUILD: ${{ startsWith(github.ref, 'refs/tags/') }}
TAG_VERSION: ${{ needs.prebuild.outputs.version }}
#Possible values: { none, library, workspace, inherit }
# Any ENV variables starting with "PARAM_" will be passed to Unity without the prefix
# (The "PARAM_" prefix exists to allow any future values config-free)
# e.g.: PARAM_ALLOW_DEBUG -> In Unity will be available as "ALLOW_DEBUG"
# e.g.: Editor.CloudBuild.Parameters["ALLOW_DEBUG"]
PARAM_BUILD_VERSION: ${{ needs.prebuild.outputs.version }}
#PARAM_BUILD_VERSION: 0.0.1-test
PARAM_UNITY_EXTRA_PARAMS: '-disable-assembly-updater'
- name: Set artifact name
id: set_artifact_name
run: |
echo "artifact_name=aang-renderer" >> $GITHUB_ENV
- name: Upload artifact
id: upload-artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifact_name }}
path: |
build
if-no-files-found: error
- name: Zip Build Output
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: zip -r build.zip build/
- name: Create GitHub Release
if: ${{ startsWith(github.ref, 'refs/tags/') }}
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
body: Release for ${{ github.ref_name }}
draft: false
prerelease: false
- name: Upload Release Asset
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: build.zip
asset_name: aang-renderer-${{ github.ref_name }}.zip
asset_content_type: application/zip
- name: Set SHA, branch, and build prefix
run: |
echo "SHA_SHORT=$(echo ${{ needs.prebuild.outputs.commit_sha }} | cut -c1-7)" >> $GITHUB_ENV
echo "SAFE_BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" >> $GITHUB_ENV
EVENT_NAME="${{ github.event_name }}"
echo "Detected event: $EVENT_NAME"
case "$EVENT_NAME" in
pull_request) echo "BUILD_PREFIX=pr" >> $GITHUB_ENV ;;
push) echo "BUILD_PREFIX=pu" >> $GITHUB_ENV ;;
merge_group) echo "BUILD_PREFIX=mg" >> $GITHUB_ENV ;;
workflow_dispatch) echo "BUILD_PREFIX=wd" >> $GITHUB_ENV ;;
workflow_call) echo "BUILD_PREFIX=wc" >> $GITHUB_ENV ;;
schedule) echo "BUILD_PREFIX=sc" >> $GITHUB_ENV ;;
*) echo "BUILD_PREFIX=gn" >> $GITHUB_ENV ;;
esac
# Will run always (even if failing)
- name: Upload cloud logs
if: always()
uses: actions/upload-artifact@v4
with:
name: web_unity_log
path: unity_cloud_log.log
if-no-files-found: error
# Will run always (even if failing)
- name: Print cloud logs
if: always()
run: cat unity_cloud_log.log
- name: Extract and display errors
if: always()
run: |
echo "=== Extracted Errors ==="
grep -iE "error c|fatal" unity_cloud_log.log | sed 's/^/\x1b[31m/' | sed 's/$/\x1b[0m/' || echo "No 'error c' or 'fatal' errors found in log."
# Will run on cancel or timeout only
- name: Cancel Unity Cloud build
if: ${{ cancelled() }}
env:
API_KEY: ${{ secrets.UNITY_CLOUD_API_KEY }}
ORG_ID: ${{ secrets.UNITY_CLOUD_ORG_ID }}
PROJECT_ID: ${{ secrets.UNITY_CLOUD_PROJECT_ID }}
run: python -u .github/scripts/build.py --cancel