-
-
Notifications
You must be signed in to change notification settings - Fork 2
286 lines (249 loc) · 9.18 KB
/
Copy pathunity-test.yml
File metadata and controls
286 lines (249 loc) · 9.18 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
name: UPM Test (Unity Docker)
on:
workflow_dispatch:
push:
permissions:
contents: read
env:
UNITY_EMAIL: ci@litefeel.com
UNITY_PASSWORD: 123456Qq
UNITY_NON_INTERACTIVE: "true"
UNITY_NO_BANNER: "true"
UNITY_VERSIONS_JSON: >-
["2019.4.41f2", "2022.3.62f2", "6000.3.1f1", "6000.5.5f1"]
jobs:
select-versions:
name: Select supported Unity versions
runs-on: ubuntu-latest
outputs:
unityVersions: ${{ steps.matrix.outputs.unityVersions }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
path: MyPlugin
- name: Filter versions by package minimum
id: matrix
shell: bash
run: |
manifest=MyPlugin/package.json
declared_unity="$(jq -r '.unity // "2019.4"' "$manifest")"
declared_release="$(jq -r '.unityRelease // empty' "$manifest")"
if [[ ! "$declared_unity" =~ ^([0-9]+)\.([0-9]+)(\.([0-9]+))?$ ]]; then
echo "::error::Invalid package.json unity version: $declared_unity"
exit 1
fi
minimum="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[4]:-0}${declared_release}"
mapfile -t candidates < <(jq -r '.[]' <<<"$UNITY_VERSIONS_JSON")
supported=()
for version in "${candidates[@]}"; do
if [[ "$(printf '%s\n%s\n' "$minimum" "$version" | sort -V | head -n 1)" == "$minimum" ]]; then
supported+=("$version")
else
echo "Skipping Unity $version; package minimum is $minimum."
fi
done
if [[ "${#supported[@]}" -eq 0 ]]; then
echo "::error::No configured Unity version supports package minimum $minimum."
exit 1
fi
versions_json="$(
printf '%s\n' "${supported[@]}" |
jq -R . |
jq -sc .
)"
echo "Selected Unity versions: $versions_json"
echo "unityVersions=$versions_json" >> "$GITHUB_OUTPUT"
test:
name: Test Unity ${{ matrix.unityVersion }} in Docker
needs: select-versions
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
unityVersion: ${{ fromJSON(needs.select-versions.outputs.unityVersions) }}
container:
image: unityci/editor:ubuntu-${{ matrix.unityVersion }}-base-3.2.2
timeout-minutes: 30
env:
UNITY_VERSION: ${{ matrix.unityVersion }}
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: Prepare Personal license
shell: bash
run: |
dbus-uuidgen > /etc/machine-id
mkdir -p /var/lib/dbus
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 unity-editor \
-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
unity-editor \
-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
unity-editor \
-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 \
unity-editor \
-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 ${{ 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: |
unity-editor \
-logFile - \
-quit \
-returnlicense \
-username "$UNITY_EMAIL" \
-password "$UNITY_PASSWORD" \
-projectPath "$RUNNER_TEMP/UnityLicenseProject"