Skip to content

Support Unity 6.5 EntityId asset callbacks #4

Support Unity 6.5 EntityId asset callbacks

Support Unity 6.5 EntityId asset callbacks #4

Workflow file for this run

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"