-
Notifications
You must be signed in to change notification settings - Fork 17
428 lines (395 loc) · 19.1 KB
/
Copy pathtest-audience-sample-app.yml
File metadata and controls
428 lines (395 loc) · 19.1 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
name: Audience SDK — PlayMode (IL2CPP + Mono)
on:
pull_request:
paths:
- 'src/Packages/Audience/**'
- 'examples/audience/**'
- '.github/workflows/test-audience-sample-app.yml'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
playmode:
if: github.event.pull_request.head.repo.fork == false || github.event_name == 'workflow_dispatch'
name: ${{ matrix.target }} / ${{ matrix.backend }} / Unity ${{ matrix.unity }}
strategy:
fail-fast: false
matrix:
include:
- target: StandaloneWindows64
backend: IL2CPP
unity: 2021.3.45f2
changeset: 88f88f591b2e
runner: [self-hosted, Windows, X64]
- target: StandaloneWindows64
backend: Mono2x
unity: 2021.3.45f2
changeset: 88f88f591b2e
runner: [self-hosted, Windows, X64]
- target: StandaloneOSX
backend: IL2CPP
unity: 2021.3.45f2
changeset: 88f88f591b2e
runner: [self-hosted, macOS, ARM64]
- target: StandaloneOSX
backend: Mono2x
unity: 2021.3.45f2
changeset: 88f88f591b2e
runner: [self-hosted, macOS, ARM64]
- target: StandaloneWindows64
backend: IL2CPP
unity: 6000.4.0f1
changeset: 8cf496087c8f
runner: [self-hosted, Windows, X64]
- target: StandaloneWindows64
backend: Mono2x
unity: 6000.4.0f1
changeset: 8cf496087c8f
runner: [self-hosted, Windows, X64]
- target: StandaloneOSX
backend: IL2CPP
unity: 6000.4.0f1
changeset: 8cf496087c8f
runner: [self-hosted, macOS, ARM64]
- target: StandaloneOSX
backend: Mono2x
unity: 6000.4.0f1
changeset: 8cf496087c8f
runner: [self-hosted, macOS, ARM64]
- target: StandaloneWindows64
backend: IL2CPP
unity: 2022.3.62f2
changeset: 7670c08855a9
runner: [self-hosted, Windows, X64]
- target: StandaloneWindows64
backend: Mono2x
unity: 2022.3.62f2
changeset: 7670c08855a9
runner: [self-hosted, Windows, X64]
- target: StandaloneOSX
backend: IL2CPP
unity: 2022.3.62f2
changeset: 7670c08855a9
runner: [self-hosted, macOS, ARM64]
- target: StandaloneOSX
backend: Mono2x
unity: 2022.3.62f2
changeset: 7670c08855a9
runner: [self-hosted, macOS, ARM64]
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
steps:
- name: Kill stale Unity processes (Windows pre-checkout)
if: runner.os == 'Windows'
shell: pwsh
continue-on-error: true
run: |
# actions/checkout@v4 deletes the prior workspace before cloning. If a
# previous run's Unity Editor / IL2CPP build process is still holding
# handles inside examples/audience, checkout dies with EBUSY. Kill any
# leftover Unity-family process here so checkout's cleanup succeeds.
Get-Process | Where-Object {
$_.Name -like 'Unity*' -or
$_.Name -like 'il2cpp*' -or
$_.Name -like 'UnityShaderCompiler*' -or
$_.Name -like 'UnityCrashHandler*'
} | ForEach-Object {
Write-Host "Killing stale process: $($_.Name) (pid $($_.Id))"
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
}
Start-Sleep -Seconds 2
- uses: actions/checkout@v4
with:
lfs: true
- name: Cache Unity Library
uses: actions/cache@v4
with:
path: examples/audience/Library
key: Library-${{ matrix.backend }}-${{ matrix.target }}-${{ matrix.unity }}-${{ hashFiles('examples/audience/Assets/**', 'examples/audience/Packages/**', 'examples/audience/ProjectSettings/**', 'src/Packages/Audience/**') }}
restore-keys: |
Library-${{ matrix.backend }}-${{ matrix.target }}-${{ matrix.unity }}-
Library-${{ matrix.backend }}-${{ matrix.target }}-
- name: Ensure MSVC + Windows 10 SDK (Windows IL2CPP)
if: runner.os == 'Windows' && matrix.backend == 'IL2CPP'
shell: pwsh
run: |
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
# Match Unity's detection logic exactly: vswhere requires VC.Tools
# (any version), registry probe for any Win10 SDK at v10.0/InstallationFolder.
# Pinning a specific SDK version in -requires is too strict — VCTools
# ships with whatever Win10 SDK is current, and Unity accepts any.
function Test-Toolchain {
$vc = if (Test-Path $vswhere) {
& $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath 2>$null
} else { '' }
$sdk = (Get-ItemProperty 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' -ErrorAction SilentlyContinue).InstallationFolder
return @{ VcTools = $vc; Win10Sdk = $sdk }
}
$state = Test-Toolchain
if ($state.VcTools -and $state.Win10Sdk) {
Write-Host "VC.Tools at: $($state.VcTools)"
Write-Host "Win10 SDK at: $($state.Win10Sdk)"
exit 0
}
Write-Host "Toolchain incomplete. VC.Tools='$($state.VcTools)' Win10Sdk='$($state.Win10Sdk)'"
Write-Host "::group::Install VS 2022 Build Tools (VCTools + Win10 SDK)"
$installer = "$env:RUNNER_TEMP\vs_BuildTools.exe"
Invoke-WebRequest -Uri 'https://aka.ms/vs/17/release/vs_BuildTools.exe' -OutFile $installer
$installArgs = @(
'--quiet','--wait','--norestart','--nocache',
'--add','Microsoft.VisualStudio.Workload.VCTools',
'--add','Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'--add','Microsoft.VisualStudio.Component.Windows10SDK.20348',
'--includeRecommended'
)
$p = Start-Process -FilePath $installer -ArgumentList $installArgs -Wait -PassThru -NoNewWindow
# 3010 = success, reboot pending (tools are usable without reboot).
if ($p.ExitCode -ne 0 -and $p.ExitCode -ne 3010) {
Write-Host "::error::VS Build Tools installer exited $($p.ExitCode)"
exit $p.ExitCode
}
Write-Host "::endgroup::"
$state = Test-Toolchain
if (-not ($state.VcTools -and $state.Win10Sdk)) {
Write-Host "::group::diagnostic"
Write-Host "VC.Tools path (vswhere): '$($state.VcTools)'"
Write-Host "Win10 SDK (registry v10.0/InstallationFolder): '$($state.Win10Sdk)'"
Write-Host "--- all VS installations ---"
if (Test-Path $vswhere) { & $vswhere -all -products * -format json }
Write-Host "--- HKLM Win10 SDK roots ---"
Get-ChildItem 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows' -ErrorAction SilentlyContinue | Format-List
Write-Host "::endgroup::"
Write-Host "::error::Install reported success but VC.Tools or Win10 SDK still not detected — runner service account likely lacks admin to install system-wide. Install VS Build Tools manually on IMX_SDKBUILD: vs_BuildTools.exe --quiet --wait --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"
exit 1
}
Write-Host "Verified VC.Tools at: $($state.VcTools)"
Write-Host "Verified Win10 SDK at: $($state.Win10Sdk)"
- name: Resolve Unity ${{ matrix.unity }} (macOS)
if: runner.os == 'macOS'
shell: bash
env:
UNITY_VER: ${{ matrix.unity }}
UNITY_CS: ${{ matrix.changeset }}
run: |
set -uo pipefail
HUB="/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"
echo "::group::install editor"
"$HUB" -- --headless install \
--version "$UNITY_VER" --changeset "$UNITY_CS" --architecture arm64 \
|| echo "(install non-zero — OK if 'Editor already installed in this location')"
echo "::endgroup::"
if [ "${{ matrix.backend }}" = "IL2CPP" ]; then
echo "::group::install mac-il2cpp module"
"$HUB" -- --headless install-modules \
--version "$UNITY_VER" --changeset "$UNITY_CS" --architecture arm64 \
--module mac-il2cpp \
|| echo "(install-modules non-zero — OK if 'No modules found to install')"
echo "::endgroup::"
fi
EDITOR_APP=""
for cand in \
"/Applications/Unity/Hub/Editor/$UNITY_VER-arm64/Unity.app" \
"/Applications/Unity/Hub/Editor/$UNITY_VER/Unity.app"; do
if [ -x "$cand/Contents/MacOS/Unity" ]; then EDITOR_APP="$cand"; break; fi
done
IL2CPP_DIR=""
if [ "${{ matrix.backend }}" = "IL2CPP" ] && [ -n "$EDITOR_APP" ]; then
for d in \
"$EDITOR_APP/Contents/PlaybackEngines/MacStandaloneSupport/Variations/macos_arm64_player_nondevelopment_il2cpp" \
"$EDITOR_APP/Contents/PlaybackEngines/MacStandaloneSupport/Variations/macos_x64_player_nondevelopment_il2cpp"; do
if [ -d "$d" ]; then IL2CPP_DIR="$d"; break; fi
done
fi
MISSING=""
[ -z "$EDITOR_APP" ] && MISSING="editor"
[ "${{ matrix.backend }}" = "IL2CPP" ] && [ -z "$IL2CPP_DIR" ] && MISSING="${MISSING:+$MISSING+}mac-il2cpp"
if [ -n "$MISSING" ]; then
echo "::error::Unity $UNITY_VER missing: $MISSING"
ls -la /Applications/Unity/Hub/Editor/ 2>&1 || true
"$HUB" -- --headless editors --installed 2>&1 || true
exit 1
fi
echo "Found Unity: $EDITOR_APP/Contents/MacOS/Unity"
[ -n "$IL2CPP_DIR" ] && echo "Found IL2CPP: $IL2CPP_DIR"
echo "UNITY_PATH=$EDITOR_APP/Contents/MacOS/Unity" >> "$GITHUB_ENV"
- name: Resolve Unity ${{ matrix.unity }} (Windows)
if: runner.os == 'Windows'
shell: pwsh
env:
UNITY_VER: ${{ matrix.unity }}
UNITY_CS: ${{ matrix.changeset }}
run: |
$hub = "C:\Program Files\Unity Hub\Unity Hub.exe"
Write-Host "::group::install editor"
$installArgs = @('--','--headless','install','--version',$env:UNITY_VER,'--changeset',$env:UNITY_CS,'--architecture','x86_64')
& $hub @installArgs 2>&1 | Write-Host
if ($LASTEXITCODE -ne 0) { Write-Host "(install non-zero — OK if 'Editor already installed in this location')" }
$global:LASTEXITCODE = 0
Write-Host "::endgroup::"
if ('${{ matrix.backend }}' -eq 'IL2CPP') {
Write-Host "::group::install windows-il2cpp module"
$modArgs = @('--','--headless','install-modules','--version',$env:UNITY_VER,'--changeset',$env:UNITY_CS,'--architecture','x86_64','--module','windows-il2cpp')
& $hub @modArgs 2>&1 | Write-Host
if ($LASTEXITCODE -ne 0) { Write-Host "(install-modules non-zero — OK if 'No modules found to install')" }
$global:LASTEXITCODE = 0
Write-Host "::endgroup::"
}
$editor = "C:\Program Files\Unity\Hub\Editor\$env:UNITY_VER\Editor\Unity.exe"
$il2cpp = "C:\Program Files\Unity\Hub\Editor\$env:UNITY_VER\Editor\Data\PlaybackEngines\windowsstandalonesupport\Variations\win64_player_nondevelopment_il2cpp"
$missing = @()
if (-not (Test-Path $editor)) { $missing += 'editor' }
if ('${{ matrix.backend }}' -eq 'IL2CPP' -and -not (Test-Path $il2cpp)) { $missing += 'windows-il2cpp' }
if ($missing.Count -gt 0) {
Write-Host "::error::Unity $env:UNITY_VER missing: $($missing -join '+')"
Get-ChildItem "C:\Program Files\Unity\Hub\Editor\" -ErrorAction SilentlyContinue | Format-Table
& $hub -- --headless editors --installed
exit 1
}
Write-Host "Found Unity: $editor"
if ('${{ matrix.backend }}' -eq 'IL2CPP') { Write-Host "Found IL2CPP: $il2cpp" }
"UNITY_PATH=$editor" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
- name: Run PlayMode tests (macOS)
if: runner.os == 'macOS'
shell: bash
env:
AUDIENCE_TEST_PUBLISHABLE_KEY: ${{ secrets.AUDIENCE_TEST_PUBLISHABLE_KEY }}
AUDIENCE_SCRIPTING_BACKEND: ${{ matrix.backend }}
run: |
set -euo pipefail
mkdir -p artifacts
# Tee Unity's stdout to artifacts/unity.log so the annotation step has a
# file to scan, while still streaming progress to the job log. pipefail
# propagates Unity's exit code through tee. The annotation step reads this
# file in-job; the actions/upload-artifact step below also uploads it so
# compile failures retain a full post-mortem (annotations are matched-line
# only and drop IL2CPP linker output, build config dumps, etc).
"$UNITY_PATH" \
-batchmode -nographics \
-projectPath examples/audience \
-runTests \
-testPlatform ${{ matrix.target }} \
-testResults "$(pwd)/artifacts/test-results.xml" \
-logFile - 2>&1 | tee "$(pwd)/artifacts/unity.log"
- name: Run PlayMode tests (Windows)
if: runner.os == 'Windows'
shell: pwsh
env:
AUDIENCE_TEST_PUBLISHABLE_KEY: ${{ secrets.AUDIENCE_TEST_PUBLISHABLE_KEY }}
AUDIENCE_SCRIPTING_BACKEND: ${{ matrix.backend }}
run: |
New-Item -ItemType Directory -Force -Path artifacts | Out-Null
$logFile = "$pwd\artifacts\unity.log"
$unityArgs = @(
'-batchmode','-nographics',
'-projectPath','examples/audience',
'-runTests',
'-testPlatform','${{ matrix.target }}',
'-testResults',"$pwd\artifacts\test-results.xml",
'-logFile',$logFile
)
Write-Host "Launching Unity: $env:UNITY_PATH $($unityArgs -join ' ')"
$p = Start-Process -FilePath $env:UNITY_PATH -ArgumentList $unityArgs -Wait -PassThru -NoNewWindow
$exit = $p.ExitCode
Write-Host "::group::Unity log"
Get-Content $logFile -ErrorAction SilentlyContinue | Write-Host
Write-Host "::endgroup::"
Write-Host "Unity exited with code $exit"
if ($exit -ne 0) { exit $exit }
- name: Mark workspace safe for git (Windows)
if: always() && runner.os == 'Windows'
shell: pwsh
run: |
git config --global --add safe.directory $env:GITHUB_WORKSPACE.Replace('\','/')
- name: Capture player log (macOS)
if: always() && runner.os == 'macOS'
shell: bash
run: |
# The test-runner builds + launches a player binary that writes its own
# log separately from Unity's editor log. When the editor reports
# "Test execution timed out. No activity received from the player ..."
# the editor unity.log alone cannot tell us whether the player crashed,
# hung, or never started. Copy whatever Player.log files Unity wrote
# into artifacts/ so the upload-artifact step preserves them.
mkdir -p artifacts
src="$HOME/Library/Logs"
if [ -d "$src" ]; then
find "$src" -name "Player.log" 2>/dev/null | while IFS= read -r f; do
cp "$f" "artifacts/Player-$(basename "$(dirname "$f")").log" 2>/dev/null || true
done
fi
- name: Capture player log (Windows)
if: always() && runner.os == 'Windows'
shell: pwsh
run: |
# See macOS counterpart for rationale. Windows player log location:
# %USERPROFILE%\AppData\LocalLow\<CompanyName>\<ProductName>\Player.log
New-Item -ItemType Directory -Force -Path artifacts | Out-Null
$src = "$env:USERPROFILE\AppData\LocalLow"
if (Test-Path $src) {
Get-ChildItem -Path $src -Recurse -Filter "Player.log" -ErrorAction SilentlyContinue |
ForEach-Object {
$name = $_.Directory.Name
Copy-Item -Path $_.FullName -Destination "artifacts/Player-$name.log" -ErrorAction SilentlyContinue
}
}
- name: Surface Unity compile errors as annotations (macOS)
if: always() && runner.os == 'macOS'
shell: bash
run: |
set -uo pipefail
# Unity writes compile errors as 'error CS####:' or 'Compilation failed: <n>'.
# When a cell fails compile (vs fails a test), the test-results.xml is empty
# and the only signal otherwise is the artifact zip. Promote those lines to
# ::error:: annotations so the PR UI shows the cause inline.
LOG_FILE="artifacts/unity.log"
if [ ! -f "$LOG_FILE" ]; then
echo "::notice::No Unity log file at $LOG_FILE."
exit 0
fi
# `|| true` guards the success path: with `pipefail`, grep exits 1 when no
# matches (the clean-build case), which would otherwise propagate as the
# step's exit code and falsely mark every green cell red.
grep -E '(error CS[0-9]+:|Compilation failed:)' "$LOG_FILE" | sort -u | while IFS= read -r line; do
trimmed="${line#"${line%%[![:space:]]*}"}"
# Sanitize '::' so log lines containing workflow commands (e.g. ::endgroup::)
# cannot terminate the annotation early or inject other commands.
sanitized="${trimmed//::/%3A%3A}"
echo "::error::$sanitized"
done || true
- name: Surface Unity compile errors as annotations (Windows)
if: always() && runner.os == 'Windows'
shell: pwsh
run: |
$logFile = "artifacts\unity.log"
if (-not (Test-Path $logFile)) {
Write-Host "::notice::No Unity log file at $logFile."
exit 0
}
Get-Content $logFile |
Select-String -Pattern '(error CS\d+:|Compilation failed:)' |
ForEach-Object { $_.Line.Trim() } |
Sort-Object -Unique |
ForEach-Object {
# Sanitize '::' so log lines containing workflow commands cannot
# terminate the annotation early or inject other commands.
$sanitized = $_ -replace '::', '%3A%3A'
Write-Host "::error::$sanitized"
}
- name: Publish test report
uses: dorny/test-reporter@v3
if: always()
with:
name: PlayMode (${{ matrix.backend }} / ${{ matrix.target }})
path: artifacts/test-results.xml
reporter: dotnet-nunit
fail-on-error: true
- uses: actions/upload-artifact@v4
if: always()
with:
name: playmode-${{ matrix.backend }}-${{ matrix.target }}-${{ matrix.unity }}
path: |
artifacts/test-results.xml
artifacts/unity.log
artifacts/Player-*.log
examples/audience/Logs/**