-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathplaymode-linux-container.sh
More file actions
executable file
·118 lines (104 loc) · 4.1 KB
/
Copy pathplaymode-linux-container.sh
File metadata and controls
executable file
·118 lines (104 loc) · 4.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
#!/bin/bash
# Audience SDK PlayMode test runner for Linux: in-container body.
# Runs inside the unityci/editor:ubuntu-X-linux-il2cpp-3 container.
# Caller: .github/scripts/audience/playmode-linux.sh (host-side docker wrapper).
set -uo pipefail
LOG=/github/workspace/artifacts/unity.log
ACTIVATION_LOG=/github/workspace/artifacts/activation.log
RESULTS=/github/workspace/artifacts/test-results.xml
PROJECT=/github/workspace/examples/audience
test_rc=1
activate_license() {
unity-editor -batchmode -nographics -quit \
-username "$UNITY_EMAIL" \
-password "$UNITY_PASSWORD" \
-serial "$UNITY_SERIAL" \
-logFile - 2>&1 | tee "$ACTIVATION_LOG" || true
if grep -qE "License activation has failed|\[Licensing::Client\] Error: Code [0-9]+" "$ACTIVATION_LOG"; then
echo "::error::Unity license activation failed."
exit 1
fi
if ! grep -qE "Successfully activated the entitlement license" "$ACTIVATION_LOG"; then
echo "::error::Unity license activation: no success marker in log."
exit 1
fi
}
run_tests_with_watchdog() {
# xvfb-run gives Unity a virtual X display. UI Toolkit needs GLX + render;
# llvmpipe in the image provides software OpenGL so no GPU is needed.
# -force-glcore skips the Unity 6 Vulkan init and matches the Unity 2021.3 default path.
xvfb-run -a --server-args="-ac +extension GLX +render -noreset" -- \
unity-editor \
-batchmode \
-force-glcore \
-screen-fullscreen 0 \
-screen-width 320 \
-screen-height 240 \
-projectPath "$PROJECT" \
-runTests \
-testPlatform StandaloneLinux64 \
-testResults "$RESULTS" \
-logFile "$LOG" &
local unity_pid=$!
# Mirror Unity log to job stdout while the editor is alive.
tail --pid=$unity_pid -F "$LOG" 2>/dev/null &
# Watchdog (vs fixed timeout) because per-version run length varies wildly:
# Unity 2021.3 cells finish in ~2 min, Unity 6 in ~22 min, and Unity 6 has a
# known post-test shutdown hang. SIGTERM 30 s after "Test run completed" so
# each cell exits as soon as its suite finishes. 40 min hard cap as fallback.
local deadline=$((SECONDS + 2400))
local flush_deadline=0
local kill_reason=""
while kill -0 "$unity_pid" 2>/dev/null; do
if [ "$SECONDS" -ge "$deadline" ]; then
kill_reason="hard-cap-40m"
break
fi
if [ "$flush_deadline" -eq 0 ] && grep -q "Test run completed" "$LOG" 2>/dev/null; then
flush_deadline=$((SECONDS + 30))
echo "[watchdog] saw \"Test run completed\" at ${SECONDS}s; SIGTERM after 30s flush window"
fi
if [ "$flush_deadline" -gt 0 ] && [ "$SECONDS" -ge "$flush_deadline" ]; then
kill_reason="flush-window-elapsed"
break
fi
sleep 5
done
if [ -n "$kill_reason" ]; then
echo "[watchdog] sending SIGTERM to Unity (reason: $kill_reason)"
kill -TERM "$unity_pid" 2>/dev/null || true
# 15 s grace, then SIGKILL.
for _ in 1 2 3; do
kill -0 "$unity_pid" 2>/dev/null || break
sleep 5
done
if kill -0 "$unity_pid" 2>/dev/null; then
echo "[watchdog] SIGTERM not honored, sending SIGKILL"
kill -KILL "$unity_pid" 2>/dev/null || true
fi
fi
wait "$unity_pid" 2>/dev/null
test_rc=$?
if [ "$kill_reason" = "hard-cap-40m" ]; then
echo "::warning::Unity hit the 40 min hard cap without logging \"Test run completed\". Inspect Player.log."
fi
}
capture_player_log() {
# Player runs in a separate process from the editor; copy its Player.log so
# HTTP traces and OnError fires are captured. Glob across companies / products.
find /root/.config/unity3d -name "Player.log" 2>/dev/null | while IFS= read -r f; do
co=$(basename "$(dirname "$(dirname "$f")")")
pr=$(basename "$(dirname "$f")")
cp "$f" "/github/workspace/artifacts/Player-${co}-${pr}.log" 2>/dev/null || true
done
}
return_license() {
# Always return the seat to keep the activation pool from exhausting on reruns.
unity-editor -batchmode -nographics -quit -returnlicense -logFile - 2>&1 || true
}
activate_license
run_tests_with_watchdog
capture_player_log
return_license
# Unity exits 2 on test failure or inconclusive; propagate so the step fails.
exit "$test_rc"