-
-
Notifications
You must be signed in to change notification settings - Fork 2
291 lines (254 loc) · 9.46 KB
/
Copy pathunity-beta-test.yml
File metadata and controls
291 lines (254 loc) · 9.46 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
name: UPM Test (Unity Beta)
on:
workflow_dispatch:
push:
permissions:
contents: read
env:
UNITY_EMAIL: ci@litefeel.com
UNITY_PASSWORD: 123456Qq
UNITY_NON_INTERACTIVE: "true"
UNITY_NO_BANNER: "true"
jobs:
test:
name: Test latest Unity Beta
runs-on: ubuntu-latest
timeout-minutes: 45
continue-on-error: true
steps:
- name: Checkout Personal license source
uses: actions/checkout@v6
with:
repository: litefeel/UnityEmptyProject
path: EmptyProject
sparse-checkout: UnityLicense/Unity_lic.ulf
sparse-checkout-cone-mode: false
- name: Checkout repository
uses: actions/checkout@v6
with:
lfs: true
path: MyPlugin
- name: Resolve latest Unity Beta
shell: bash
run: |
release_api="https://services.api.unity.com/unity/editor/release/v1/releases?limit=1&stream=BETA&platform=LINUX&architecture=X86_64"
release_json="$(
curl -fsSL \
--retry 5 \
--retry-all-errors \
--retry-delay 10 \
"$release_api"
)"
unity_version="$(jq -r '.results[0].version // empty' <<<"$release_json")"
editor_url="$(
jq -r '
[
.results[0].downloads[]
| select(
.platform == "LINUX"
and .architecture == "X86_64"
and .type == "TAR_XZ"
)
][0].url // empty
' <<<"$release_json"
)"
if [[ -z "$unity_version" || -z "$editor_url" ]]; then
echo "::error::Unity Release API did not return a Linux x86_64 Beta Editor."
exit 1
fi
echo "Resolved latest Unity Beta: $unity_version"
echo "UNITY_VERSION=$unity_version" >> "$GITHUB_ENV"
echo "UNITY_EDITOR_URL=$editor_url" >> "$GITHUB_ENV"
- name: Download latest Unity Beta Editor
shell: bash
run: |
editor_root="$RUNNER_TEMP/Unity-$UNITY_VERSION"
editor_archive="$RUNNER_TEMP/Unity-$UNITY_VERSION.tar.xz"
mkdir -p "$editor_root"
curl -fsSL \
--retry 5 \
--retry-all-errors \
--retry-delay 10 \
"$UNITY_EDITOR_URL" \
-o "$editor_archive"
tar -xJf "$editor_archive" -C "$editor_root"
editor_path="$editor_root/Editor/Unity"
if [[ ! -x "$editor_path" ]]; then
echo "::error::Cannot find the Unity Beta Editor at $editor_path."
exit 1
fi
xvfb-run -ae /dev/stdout "$editor_path" -version -batchmode -quit
echo "UNITY_EDITOR_PATH=$editor_path" >> "$GITHUB_ENV"
- name: Prepare Personal license
shell: bash
run: |
dbus-uuidgen | sudo tee /etc/machine-id >/dev/null
sudo mkdir -p /var/lib/dbus
sudo ln -sf /etc/machine-id /var/lib/dbus/machine-id
developer_data="$(
sed -n 's/.*<DeveloperData Value="\([^"]*\)".*/\1/p' \
EmptyProject/UnityLicense/Unity_lic.ulf
)"
if [[ -z "$developer_data" ]]; then
echo "::error::Cannot read DeveloperData from the Unity license file."
exit 1
fi
unity_serial="$(
printf '%s' "$developer_data" | base64 --decode | cut -c 5-
)"
if [[ -z "$unity_serial" ]]; then
echo "::error::Cannot decode the Unity Personal license serial."
exit 1
fi
echo "::add-mask::$unity_serial"
echo "UNITY_SERIAL=$unity_serial" >> "$GITHUB_ENV"
- name: Activate Unity Personal license
shell: bash
run: |
license_project="$RUNNER_TEMP/UnityLicenseProject"
mkdir -p "$license_project/Assets"
attempt=1
delay=15
until timeout --preserve-status 3m \
xvfb-run -ae /dev/stdout \
"$UNITY_EDITOR_PATH" -batchmode \
-logFile - \
-quit \
-serial "$UNITY_SERIAL" \
-username "$UNITY_EMAIL" \
-password "$UNITY_PASSWORD" \
-projectPath "$license_project"
do
if [[ "$attempt" -ge 5 ]]; then
echo "::error::License activation failed after $attempt attempts."
exit 1
fi
echo "Activation attempt $attempt failed; retrying in ${delay}s."
sleep "$delay"
delay=$((delay * 2))
attempt=$((attempt + 1))
done
echo "UNITY_LICENSE_ACTIVATED=true" >> "$GITHUB_ENV"
- name: Create default Unity project
shell: bash
run: |
test_project=/tmp/UnityTestProject
xvfb-run -ae /dev/stdout \
"$UNITY_EDITOR_PATH" -batchmode \
-quit \
-createProject "$test_project" \
-logFile -
echo "UNITY_TEST_PROJECT=$test_project" >> "$GITHUB_ENV"
- name: Resolve Unity package defaults
shell: bash
run: |
resolver_dir="$UNITY_TEST_PROJECT/Assets/Editor"
resolver_file="$resolver_dir/ResolveDefaultPackages.cs"
mkdir -p "$resolver_dir"
cat > "$resolver_file" <<'CSHARP'
using System;
using System.Threading;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
using UnityEngine;
public static class ResolveDefaultPackages
{
public static void Run()
{
AddLatestCompatible("com.unity.test-framework");
AddLatestCompatible("com.unity.ugui");
}
private static void AddLatestCompatible(string packageName)
{
AddRequest request = Client.Add(packageName);
DateTime deadline = DateTime.UtcNow.AddMinutes(10);
while (!request.IsCompleted)
{
if (DateTime.UtcNow >= deadline)
{
throw new TimeoutException(
"Timed out resolving " + packageName + ".");
}
Thread.Sleep(100);
}
if (request.Status != StatusCode.Success)
{
throw new InvalidOperationException(
"Cannot resolve " + packageName + ": "
+ request.Error.message);
}
Debug.Log("Resolved Unity default package: "
+ request.Result.packageId);
}
}
CSHARP
xvfb-run -ae /dev/stdout \
"$UNITY_EDITOR_PATH" -batchmode \
-projectPath "$UNITY_TEST_PROJECT" \
-quit \
-executeMethod ResolveDefaultPackages.Run \
-logFile -
rm -f "$resolver_file" "$resolver_file.meta"
jq -e '
.dependencies["com.unity.test-framework"] as $testFramework
| .dependencies["com.unity.ugui"] as $ugui
| select($testFramework != null and $ugui != null)
| {
"com.unity.test-framework": $testFramework,
"com.unity.ugui": $ugui
}
' "$UNITY_TEST_PROJECT/Packages/manifest.json"
- name: Prepare test project
shell: bash
run: |
package_root="$GITHUB_WORKSPACE/MyPlugin"
if [[ ! -f "$package_root/package.json" ]]; then
echo "::error::Cannot find package.json at the UPM package root."
exit 1
fi
package_name="$(jq -er '.name' "$package_root/package.json")"
jq \
--arg packageName "$package_name" \
--arg pluginPath "file:$package_root" \
'.dependencies[$packageName] = $pluginPath
| .testables = (
((.testables // []) + [$packageName]) | unique
)' \
"$UNITY_TEST_PROJECT/Packages/manifest.json" \
> "$UNITY_TEST_PROJECT/Packages/manifest.json.tmp"
mv "$UNITY_TEST_PROJECT/Packages/manifest.json.tmp" \
"$UNITY_TEST_PROJECT/Packages/manifest.json"
rm -f "$UNITY_TEST_PROJECT/Packages/packages-lock.json"
mkdir -p artifacts
cat "$UNITY_TEST_PROJECT/Packages/manifest.json"
- name: Run EditMode tests
shell: bash
run: |
timeout --preserve-status 15m \
xvfb-run -ae /dev/stdout \
"$UNITY_EDITOR_PATH" -batchmode \
-projectPath "$UNITY_TEST_PROJECT" \
-runTests \
-testPlatform editmode \
-testResults "$GITHUB_WORKSPACE/artifacts/test-results.xml" \
-logFile -
- name: Upload test results
if: always()
uses: actions/upload-artifact@v7
with:
name: Test results on Unity Beta ${{ env.UNITY_VERSION }}
path: artifacts
if-no-files-found: warn
- name: Return Unity license
if: always() && env.UNITY_LICENSE_ACTIVATED == 'true'
continue-on-error: true
shell: bash
run: |
xvfb-run -ae /dev/stdout \
"$UNITY_EDITOR_PATH" -batchmode \
-logFile - \
-quit \
-returnlicense \
-username "$UNITY_EMAIL" \
-password "$UNITY_PASSWORD" \
-projectPath "$RUNNER_TEMP/UnityLicenseProject"