@@ -113,86 +113,86 @@ jobs:
113113 -logFile -
114114 echo "UNITY_TEST_PROJECT=$test_project" >> "$GITHUB_ENV"
115115
116- - name : Read Unity package defaults
116+ - name : Resolve Unity package defaults
117117 shell : bash
118118 run : |
119- built_in_packages="$(dirname "$UNITY_EDITOR_PATH")/Data/Resources/PackageManager/BuiltInPackages"
120- test_framework_manifest="$(
121- find "$built_in_packages" -type f \
122- -path '*/com.unity.test-framework/package.json' \
123- -print -quit 2>/dev/null || true
124- )"
125- ugui_manifest="$(
126- find "$built_in_packages" -type f \
127- -path '*/com.unity.ugui/package.json' \
128- -print -quit 2>/dev/null || true
129- )"
130-
131- if [[ -n "$test_framework_manifest" && -n "$ugui_manifest" ]]; then
132- jq -n \
133- --arg testFrameworkVersion \
134- "$(jq -er '.version' "$test_framework_manifest")" \
135- --arg uguiVersion \
136- "$(jq -er '.version' "$ugui_manifest")" \
137- '{
138- dependencies: {
139- "com.unity.test-framework": $testFrameworkVersion,
140- "com.unity.ugui": $uguiVersion
141- }
142- }' > /tmp/unity-default-packages.json
143- else
144- template_dir="$(dirname "$UNITY_EDITOR_PATH")/Data/Resources/PackageManager/ProjectTemplates"
145- template_archive="$(
146- find "$template_dir" -type f \
147- -name 'com.unity.template.3d-*.tgz' -print -quit \
148- 2>/dev/null || true
149- )"
150- if [[ -z "$template_archive" ]]; then
151- echo "::error::Cannot find Unity's built-in package metadata or 3D template."
152- exit 1
153- fi
119+ resolver_dir="$UNITY_TEST_PROJECT/Assets/Editor"
120+ resolver_file="$resolver_dir/ResolveDefaultPackages.cs"
121+ mkdir -p "$resolver_dir"
122+ cat > "$resolver_file" <<'CSHARP'
123+ using System;
124+ using System.Threading;
125+ using UnityEditor.PackageManager;
126+ using UnityEditor.PackageManager.Requests;
127+ using UnityEngine;
128+
129+ public static class ResolveDefaultPackages
130+ {
131+ public static void Run()
132+ {
133+ AddLatestCompatible("com.unity.test-framework");
134+ AddLatestCompatible("com.unity.ugui");
135+ }
136+
137+ private static void AddLatestCompatible(string packageName)
138+ {
139+ AddRequest request = Client.Add(packageName);
140+ DateTime deadline = DateTime.UtcNow.AddMinutes(10);
141+
142+ while (!request.IsCompleted)
143+ {
144+ if (DateTime.UtcNow >= deadline)
145+ {
146+ throw new TimeoutException(
147+ "Timed out resolving " + packageName + ".");
148+ }
149+
150+ Thread.Sleep(100);
151+ }
152+
153+ if (request.Status != StatusCode.Success)
154+ {
155+ throw new InvalidOperationException(
156+ "Cannot resolve " + packageName + ": "
157+ + request.Error.message);
158+ }
159+
160+ Debug.Log("Resolved Unity default package: "
161+ + request.Result.packageId);
162+ }
163+ }
164+ CSHARP
154165
155- manifest_entry="$(
156- tar -tzf "$template_archive" \
157- | grep '/Packages/manifest.json$' \
158- | head -n 1
159- )"
160- if [[ -z "$manifest_entry" ]]; then
161- echo "::error::Cannot find Packages/manifest.json in $template_archive."
162- exit 1
163- fi
164-
165- tar -xOzf "$template_archive" "$manifest_entry" \
166- > /tmp/unity-default-packages.json
167- fi
166+ "$UNITY_EDITOR_PATH" \
167+ -projectPath "$UNITY_TEST_PROJECT" \
168+ -batchmode \
169+ -nographics \
170+ -quit \
171+ -executeMethod ResolveDefaultPackages.Run \
172+ -logFile -
168173
169- if ! jq -e '
170- .dependencies["com.unity.test-framework"] != null
171- and .dependencies["com.unity.ugui"] != null
172- ' /tmp/unity-default-packages.json >/dev/null
173- then
174- echo "::error::Unity defaults do not define test-framework and ugui."
175- exit 1
176- fi
177- cat /tmp/unity-default-packages.json
174+ rm -f "$resolver_file" "$resolver_file.meta"
175+ jq -e '
176+ .dependencies["com.unity.test-framework"] as $testFramework
177+ | .dependencies["com.unity.ugui"] as $ugui
178+ | select($testFramework != null and $ugui != null)
179+ | {
180+ "com.unity.test-framework": $testFramework,
181+ "com.unity.ugui": $ugui
182+ }
183+ ' "$UNITY_TEST_PROJECT/Packages/manifest.json"
178184
179185 - name : Prepare test project
180186 shell : bash
181187 run : |
188+ package_name="$(jq -er '.name' MyPlugin/package.json)"
182189 jq \
183- --slurpfile unityDefaults /tmp/unity-default-packages.json \
184- --arg packageName "com.litefeel.aligntools" \
190+ --arg packageName "$package_name" \
185191 --arg pluginPath "file:$GITHUB_WORKSPACE/MyPlugin" \
186- '{
187- dependencies: {
188- "com.unity.test-framework":
189- $unityDefaults[0].dependencies["com.unity.test-framework"],
190- "com.unity.ugui":
191- $unityDefaults[0].dependencies["com.unity.ugui"],
192- ($packageName): $pluginPath
193- },
194- testables: [$packageName]
195- }' \
192+ '.dependencies[$packageName] = $pluginPath
193+ | .testables = (
194+ ((.testables // []) + [$packageName]) | unique
195+ )' \
196196 "$UNITY_TEST_PROJECT/Packages/manifest.json" \
197197 > "$UNITY_TEST_PROJECT/Packages/manifest.json.tmp"
198198 mv "$UNITY_TEST_PROJECT/Packages/manifest.json.tmp" \
0 commit comments