Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions .github/actions/run-unity-test-batch/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: Run Unity UTP Test Batch
description: Runs a batch of Unity UTP tests in a given Unity project.
inputs:
unity-project-path:
description: Absolute path to the Unity project.
required: true
build-target:
description: Build target to use.
required: true
build-args:
description: Additional build args.
required: true
runs:
using: composite
steps:
- name: Prepare test list and install packages
shell: bash
working-directory: ${{ inputs.unity-project-path }}
run: |
set -euo pipefail
tests_input="CompilerWarnings,CompilerErrors,BuildWarnings,BuildErrors,PlaymodeTestsErrors,EditmodeTestsErrors"
echo "TESTS_INPUT=$tests_input" >> $GITHUB_ENV

needs_test_framework=false
if [[ "$tests_input" == *"PlaymodeTestsErrors"* || "$tests_input" == *"EditmodeTestsErrors"* ]]; then
needs_test_framework=true
fi

npm install -g openupm-cli
openupm add com.utilities.buildpipeline
if [ "$needs_test_framework" = true ]; then
openupm add com.unity.test-framework
fi

- name: Run tests sequentially
shell: bash
env:
UNITY_PROJECT_PATH: ${{ inputs.unity-project-path }}
BUILD_TARGET: ${{ inputs.build-target }}
BUILD_ARGS: ${{ inputs.build-args }}
run: |
set -euo pipefail

tests_input="$TESTS_INPUT"
IFS=',' read -ra tests <<< "$tests_input"
failures=0

clean_tests() {
rm -f "$UNITY_PROJECT_PATH/Assets/UnityCliTests"/*.cs 2>/dev/null || true
rm -f "$UNITY_PROJECT_PATH/Assets/Editor/UnityCliTests"/*.cs 2>/dev/null || true
rm -f "$UNITY_PROJECT_PATH/Assets/Tests/PlayMode/UnityCliTests"/*.cs 2>/dev/null || true
rm -f "$UNITY_PROJECT_PATH/Assets/Tests/EditMode/UnityCliTests"/*.cs 2>/dev/null || true
}

mkdir -p "$GITHUB_WORKSPACE/utp-artifacts"

for raw_test in "${tests[@]}"; do
test_name="$(echo "$raw_test" | xargs)"
if [ -z "$test_name" ] || [ "$test_name" = "None" ]; then
echo "Skipping empty/None test entry"
continue
fi

src="$GITHUB_WORKSPACE/unity-tests/${test_name}.cs"
if [ ! -f "$src" ]; then
echo "::error::Requested test '$test_name' not found at $src"
failures=$((failures+1))
continue
fi

clean_tests

case "$test_name" in
CompilerWarnings|CompilerErrors)
dest="$UNITY_PROJECT_PATH/Assets/UnityCliTests"
;;
BuildWarnings|BuildErrors)
dest="$UNITY_PROJECT_PATH/Assets/Editor/UnityCliTests"
;;
PlaymodeTestsErrors)
dest="$UNITY_PROJECT_PATH/Assets/Tests/PlayMode/UnityCliTests"
;;
EditmodeTestsErrors)
dest="$UNITY_PROJECT_PATH/Assets/Tests/EditMode/UnityCliTests"
;;
*)
echo "::error::Unknown test selection '$test_name'"
failures=$((failures+1))
continue
;;
esac

mkdir -p "$dest"
cp "$src" "$dest/"
echo "Running test: $test_name (copied to $dest)"

if unity-cli run --log-name "${test_name}-Validate" -quit -executeMethod Utilities.Editor.BuildPipeline.UnityPlayerBuildTools.ValidateProject -importTMProEssentialsAsset && \
unity-cli run --log-name "${test_name}-Build" -buildTarget "$BUILD_TARGET" -quit -executeMethod Utilities.Editor.BuildPipeline.UnityPlayerBuildTools.StartCommandLineBuild -sceneList Assets/Scenes/SampleScene.unity $BUILD_ARGS; then
echo "::notice::Test $test_name succeeded"
else
echo "::error::Test $test_name failed"
failures=$((failures+1))
fi

# Collect logs for this test
test_artifacts="$GITHUB_WORKSPACE/utp-artifacts/$test_name"
mkdir -p "$test_artifacts"
find "$GITHUB_WORKSPACE" -type f -name "*${test_name}*-utp-json.log" -print -exec cp {} "$test_artifacts" \; || true

# Reset the Unity project to a clean state before the next test
if git -C "$GITHUB_WORKSPACE" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
git -C "$GITHUB_WORKSPACE" clean -fdx
git -C "$GITHUB_WORKSPACE" reset --hard
else
echo "::warning::GITHUB_WORKSPACE is not a git repository; skipping git clean/reset"
fi
done

if [ "$failures" -gt 0 ]; then
echo "::error::One or more tests failed in batch ($failures)"
exit 1
fi

- name: Upload UTP logs
uses: actions/upload-artifact@v6
with:
name: unity-tests-batch-utp-logs
path: utp-artifacts/**/*-utp-json.log
if-no-files-found: ignore
2 changes: 2 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: read
checks: write # to publish unit test results via checks github api
steps:
- uses: actions/checkout@v6
with:
Expand All @@ -32,6 +33,7 @@ jobs:
name: build ${{ matrix.jobs.name }}
permissions:
contents: read
checks: write # required by nested unity-build workflow
strategy:
matrix: ${{ fromJSON(needs.setup.outputs.jobs) }}
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish
name: publish
on:
push:
branches: [main]
Expand Down
52 changes: 35 additions & 17 deletions .github/workflows/unity-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
strategy:
matrix: ${{ fromJSON(inputs.matrix) }}
fail-fast: false
permissions:
contents: read
checks: write # to publish unit test results via checks github api
defaults:
run:
shell: bash
Expand Down Expand Up @@ -97,26 +100,20 @@ jobs:
else
echo "Skipping build: Unity version $version does not support the build pipeline package (requires 2019.4+)"
fi
- name: Install OpenUPM and build pipeline package
- name: Run Unity UTP test batches
if: ${{ steps.verify-project-path.outputs.RUN_BUILD == 'true' }}
working-directory: ${{ env.UNITY_PROJECT_PATH }}
run: |
npm install -g openupm-cli
openupm add com.utilities.buildpipeline
uses: ./.github/actions/run-unity-test-batch
with:
unity-project-path: ${{ env.UNITY_PROJECT_PATH }}
build-target: ${{ matrix.build-target }}
build-args: ${{ matrix.build-args }}
- name: Update Android Target Sdk Version
if: ${{ matrix.build-target == 'Android' }}
run: |
# update AndroidTargetSdkVersion to 32 in ProjectSettings/ProjectSettings.asset
sed -i 's/AndroidTargetSdkVersion: [0-9]*/AndroidTargetSdkVersion: 32/' "${UNITY_PROJECT_PATH}/ProjectSettings/ProjectSettings.asset"
# ensure android dependencies are installed
unity-cli setup-unity -p "${UNITY_PROJECT_PATH}" -m android
- name: Build Project
if: ${{ steps.verify-project-path.outputs.RUN_BUILD == 'true' }}
timeout-minutes: 60
run: |
# we don't have to specify the project path or unity editor path as unity-cli will use the environment variables
unity-cli run --log-name Validate -quit -executeMethod Utilities.Editor.BuildPipeline.UnityPlayerBuildTools.ValidateProject -importTMProEssentialsAsset
unity-cli run --log-name Build -buildTarget ${{ matrix.build-target }} -quit -executeMethod Utilities.Editor.BuildPipeline.UnityPlayerBuildTools.StartCommandLineBuild -sceneList Assets/Scenes/SampleScene.unity ${{ matrix.build-args }}
- name: Uninstall Editor
if: ${{ matrix.unity-version != 'none' }}
run: |
Expand All @@ -132,12 +129,12 @@ jobs:
PACKAGE_MANAGER_LOG_PATH=$(unity-cli package-manager-logs)
LICENSING_CLIENT_LOG_PATH=$(unity-cli licensing-client-logs)
LICENSING_AUDIT_LOG_PATH=$(unity-cli licensing-audit-logs)

echo "Hub Log Path: ${HUB_LOG_PATH}"
echo "Package Manager Log Path: ${PACKAGE_MANAGER_LOG_PATH}"
echo "Licensing Client Log Path: ${LICENSING_CLIENT_LOG_PATH}"
echo "Licensing Audit Log Path: ${LICENSING_AUDIT_LOG_PATH}"

if [ ! -f "${HUB_LOG_PATH}" ]; then
echo "::warning:: Hub log file does not exist at ${HUB_LOG_PATH}"
# find all info-log.json files in ~/.config/unity3d/ - print their paths
Expand All @@ -151,18 +148,39 @@ jobs:
find ~/.config/ -type f -exec echo "{}" \;
echo "::warning:: Hub log file does not exist at any known location"
fi

if [ ! -f "${PACKAGE_MANAGER_LOG_PATH}" ]; then
echo "::warning::Package Manager log file does not exist at ${PACKAGE_MANAGER_LOG_PATH}"
fi

if [ ! -f "${LICENSING_CLIENT_LOG_PATH}" ]; then
echo "::error::Licensing Client log file does not exist at ${LICENSING_CLIENT_LOG_PATH}"
fi

if [ ! -f "${LICENSING_AUDIT_LOG_PATH}" ]; then
echo "::error::Licensing Audit log file does not exist at ${LICENSING_AUDIT_LOG_PATH}"
fi
- name: Compute UTP artifact name
if: always()
id: utp-artifact-name
env:
MATRIX_OS: ${{ matrix.os }}
MATRIX_UNITY_VERSION: ${{ matrix.unity-version }}
MATRIX_BUILD_TARGET: ${{ matrix.build-target }}
run: |
set -euo pipefail
unity_version="$MATRIX_UNITY_VERSION"
unity_version="${unity_version//\*/x}"
artifact_name="${MATRIX_OS}-${unity_version}-${MATRIX_BUILD_TARGET}-tests-batch-utp-logs"
echo "name=$artifact_name" >> $GITHUB_OUTPUT
shell: bash
- name: Upload UTP logs artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: ${{ steps.utp-artifact-name.outputs.name }}
path: '**/*-utp-json.log'
if-no-files-found: ignore
- name: Return License
if: always()
run: unity-cli return-license --license personal
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,5 @@ dist
# Vite logs files
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

.artifacts/
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rage-against-the-pixel/unity-cli",
"version": "1.8.1",
"version": "1.8.2",
"description": "A command line utility for the Unity Game Engine.",
"author": "RageAgainstThePixel",
"license": "MIT",
Expand Down
Loading
Loading