Skip to content
Merged
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
346 changes: 340 additions & 6 deletions .github/workflows/main.yml

Large diffs are not rendered by default.

Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

GitHub Action to
[run tests](https://github.com/marketplace/actions/unity-test-runner)
for any Unity project.
for any Unity project and _some_ Unity packages.

Part of the <a href="https://game.ci">GameCI</a> open source project.
<br />
Expand Down
12 changes: 8 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ inputs:
unityVersion:
required: false
default: 'auto'
description: 'Version of unity to use for testing the project. Use "auto" to get from your ProjectSettings/ProjectVersion.txt'
description: 'Version of unity to use for testing the project. Use "auto" to get from your ProjectSettings/ProjectVersion.txt. ⚠️ If testing a Unity Package, this field is required and cannot be set to "auto".'
customImage:
required: false
default: ''
description: 'Specific docker image that should be used for testing the project'
description: 'Specific docker image that should be used for testing the project. If packageMode is true, this image must have jq installed.'
projectPath:
required: false
description: 'Path to the Unity project to be tested.'
description: 'Path to the Unity project or package to be tested.'
customParameters:
required: false
description: 'Extra parameters to configure the Unity editor run.'
Expand All @@ -23,7 +23,7 @@ inputs:
coverageOptions:
required: false
default: 'generateAdditionalMetrics;generateHtmlReport;generateBadgeReport;dontClear'
description: 'Optional coverage parameters for the -coverageOptions argument.'
description: 'Optional coverage parameters for the -coverageOptions argument. To get coverage in Package Mode, pass assemblies from the package you want covered to the assemblyFilters option.'
artifactsPath:
required: false
default: 'artifacts'
Expand All @@ -48,6 +48,10 @@ inputs:
required: false
default: 'Test Results'
description: 'Name for the check run that is created when a github token is provided.'
packageMode:
required: false
default: false
description: 'Whether the tests are being run for a Unity package instead of a Unity project. If true, the action can only be run on Linux runners, and any custom docker image passed to this action must have `jq` installed. NOTE: may not work properly for packages with dependencies outside of the Unity Registry.'
chownFilesTo:
required: false
default: ''
Expand Down
2,264 changes: 942 additions & 1,322 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sourcemap-register.js

Large diffs are not rendered by default.

65 changes: 56 additions & 9 deletions dist/steps/run_tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,52 @@ Get-ChildItem -Hidden -Path $UNITY_PROJECT_PATH
#
foreach ( $platform in ${env:TEST_PLATFORMS}.Split(";") )
{
Write-Output ""
Write-Output "###########################"
Write-Output "# Testing in $platform #"
Write-Output "###########################"
Write-Output ""

if ( $platform -ne "COMBINE_RESULTS" )
if ( "$platform" -eq "standalone" )
{
$runTests = "-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
Write-Output ""
Write-Output "###########################"
Write-Output "# Building Standalone #"
Write-Output "###########################"
Write-Output ""

# Create directories if they do not exist
if(-Not (Test-Path -Path $Env:UNITY_PROJECT_PATH\Assets\Editor))
{
# We use -Force to suppress output, doesn't overwrite anything
New-Item -ItemType Directory -Force -Path $Env:UNITY_PROJECT_PATH\Assets\Editor
}
if(-Not (Test-Path -Path $Env:UNITY_PROJECT_PATH\Assets\Player))
{
# We use -Force to suppress output, doesn't overwrite anything
New-Item -ItemType Directory -Force -Path $Env:UNITY_PROJECT_PATH\Assets\Player
}

# Copy the scripts
Copy-Item -Path "c:\UnityStandaloneScripts\Assets\Editor" -Destination $Env:UNITY_PROJECT_PATH\Assets\Editor -Recurse
Copy-Item -Path "c:\UnityStandaloneScripts\Assets\Player" -Destination $Env:UNITY_PROJECT_PATH\Assets\Player -Recurse

# Verify recursive paths
Get-ChildItem -Path $Env:UNITY_PROJECT_PATH\Assets\Editor -Recurse
Get-ChildItem -Path $Env:UNITY_PROJECT_PATH\Assets\Player -Recurse

$runTests="-runTests -testPlatform StandaloneWindows64 -builtTestRunnerPath $UNITY_PROJECT_PATH\Build\UnityTestRunner-Standalone.exe"
}
else
{
$runTests = "-quit"
Write-Output ""
Write-Output "###########################"
Write-Output "# Testing in $platform #"
Write-Output "###########################"
Write-Output ""

if ( $platform -ne "COMBINE_RESULTS" )
{
$runTests = "-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
}
else
{
$runTests = "-quit"
}
}

$TEST_OUTPUT = Start-Process -NoNewWindow -Wait -PassThru "C:\Program Files\Unity\Hub\Editor\${env:UNITY_VERSION}\editor\Unity.exe" -ArgumentList "-batchmode -logFile $FULL_ARTIFACTS_PATH\$platform.log -projectPath $UNITY_PROJECT_PATH -coverageResultsPath $FULL_COVERAGE_RESULTS_PATH $runTests -enableCodeCoverage -debugCodeOptimization -coverageOptions ${env:COVERAGE_OPTIONS} ${env:CUSTOM_PARAMETERS}"
Expand All @@ -81,6 +114,20 @@ foreach ( $platform in ${env:TEST_PLATFORMS}.Split(";") )
# Print unity log output
Get-Content "$FULL_ARTIFACTS_PATH/$platform.log"

if ( ( $TEST_EXIT_CODE -eq 0 ) -and ( "$platform" -eq "standalone" ) )
{
# Code Coverage currently only supports code ran in the Editor and not in Standalone/Player.
# https://docs.unity.cn/Packages/com.unity.testtools.codecoverage@1.1/manual/TechnicalDetails.html#how-it-works

$TEST_OUTPUT = Start-Process -NoNewWindow -Wait -PassThru "$UNITY_PROJECT_PATH\Build\UnityTestRunner-Standalone.exe" -ArgumentList "-batchmode -nographics -logFile $FULL_ARTIFACTS_PATH\$platform-player.log -testResults $FULL_ARTIFACTS_PATH\$platform-results.xml"

# Catch exit code
$TEST_EXIT_CODE = $TEST_OUTPUT.ExitCode

# Print player log output
Get-Content "$FULL_ARTIFACTS_PATH/$platform-player.log"
}

# Display results
if ($TEST_EXIT_CODE -eq 0)
{
Expand Down
131 changes: 122 additions & 9 deletions dist/steps/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,76 @@ echo "Using custom parameters $CUSTOM_PARAMETERS."

echo "Using Unity version \"$UNITY_VERSION\" to test."

#
# Create an empty project for testing if in package mode
#

if [ "$PACKAGE_MODE" = "true" ]; then
echo "Running tests on a Unity package rather than a Unity project."

if ! command -v jq &> /dev/null
then
echo "jq could not be found. This is required for package mode, and is likely the result of using a custom Docker image. Please use the default image or install jq to your custom image."
exit 1
fi

echo ""
echo "###########################"
echo "# Package Folder #"
echo "###########################"
echo ""

ls -la "$UNITY_PROJECT_PATH"
echo ""

echo "Creating an empty Unity project to add the package $PACKAGE_NAME to."

TEMP_PROJECT_PATH="./TempProject"

unity-editor \
-batchmode \
-createProject "$TEMP_PROJECT_PATH" \
-quit

# use jq to add the package to the temp project through manually modifying Packages/manifest.json
echo "Adding package to the temporary project's dependencies and testables..."
echo ""

PACKAGE_MANIFEST_PATH="$TEMP_PROJECT_PATH/Packages/manifest.json"
if [ ! -f "$PACKAGE_MANIFEST_PATH" ]; then
echo "Packages/mainfest.json was not created properly. This indicates a problem with the Action, not with your package. Logging directories and aborting..."

echo ""
echo "###########################"
echo "# Temp Project Folder #"
echo "###########################"
echo ""

ls -a "$TEMP_PROJECT_PATH"

echo ""
echo "################################"
echo "# Temp Project Packages Folder #"
echo "################################"
echo ""

ls -a "$TEMP_PROJECT_PATH/Packages"

exit 1
fi

PACKAGE_MANIFEST_JSON=$(cat "$PACKAGE_MANIFEST_PATH")
echo "$PACKAGE_MANIFEST_JSON" | \
jq \
--arg packageName "$PACKAGE_NAME" \
--arg projectPath "$UNITY_PROJECT_PATH" \
'.dependencies += {"com.unity.testtools.codecoverage": "1.1.1"} | .dependencies += {"\($packageName)": "file:\($projectPath)"} | . += {testables: ["\($packageName)"]}' \
> "$PACKAGE_MANIFEST_PATH"

UNITY_PROJECT_PATH="$TEMP_PROJECT_PATH"
fi


#
# Overall info
#
Expand All @@ -59,16 +129,36 @@ ls -alh $UNITY_PROJECT_PATH
# Testing for each platform
#
for platform in ${TEST_PLATFORMS//;/ }; do
echo ""
echo "###########################"
echo "# Testing in $platform #"
echo "###########################"
echo ""

if [[ "$platform" != "COMBINE_RESULTS" ]]; then
runTests="-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
if [[ "$platform" == "standalone" ]]; then
echo ""
echo "###########################"
echo "# Building Standalone #"
echo "###########################"
echo ""

# Create directories if they do not exist
mkdir -p "$UNITY_PROJECT_PATH/Assets/Editor/"
mkdir -p "$UNITY_PROJECT_PATH/Assets/Player/"
# Copy the scripts
cp -R "$ACTION_FOLDER/UnityStandaloneScripts/Assets/Editor/" "$UNITY_PROJECT_PATH/Assets/Editor/"
cp -R "$ACTION_FOLDER/UnityStandaloneScripts/Assets/Player/" "$UNITY_PROJECT_PATH/Assets/Player/"
# Verify recursive paths
ls -Ralph "$UNITY_PROJECT_PATH/Assets/Editor/"
ls -Ralph "$UNITY_PROJECT_PATH/Assets/Player/"

runTests="-runTests -testPlatform StandaloneLinux64 -builtTestRunnerPath $UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone"
else
runTests="-quit"
echo ""
echo "###########################"
echo "# Testing in $platform #"
echo "###########################"
echo ""

if [[ "$platform" != "COMBINE_RESULTS" ]]; then
runTests="-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
else
runTests="-quit"
fi
fi

unity-editor \
Expand All @@ -88,6 +178,29 @@ for platform in ${TEST_PLATFORMS//;/ }; do
# Print unity log output
cat "$FULL_ARTIFACTS_PATH/$platform.log"

if [[ $TEST_EXIT_CODE -eq 0 && "$platform" == "standalone" ]]; then
echo ""
echo "###########################"
echo "# Testing Standalone #"
echo "###########################"
echo ""

# Code Coverage currently only supports code ran in the Editor and not in Standalone/Player.
# https://docs.unity.cn/Packages/com.unity.testtools.codecoverage@1.1/manual/TechnicalDetails.html#how-it-works

xvfb-run -a -e /dev/stdout "$UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone" \
-batchmode \
-nographics \
-logFile "$FULL_ARTIFACTS_PATH/$platform-player.log" \
-testResults "$FULL_ARTIFACTS_PATH/$platform-results.xml"

# Catch exit code
TEST_EXIT_CODE=$?

# Print player log output
cat "$FULL_ARTIFACTS_PATH/$platform-player.log"
fi

# Display results
if [ $TEST_EXIT_CODE -eq 0 ]; then
echo "Run succeeded, no failures occurred";
Expand Down
56 changes: 56 additions & 0 deletions dist/test-standalone-scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# Note: Non default ignore file, as this only tests Builder script.
#

[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Bb]uilds/
[Ll]ogs/

# Additional ignores
[Bb]in/

# Uncomment this line if you wish to ignore the asset store tools plugin
# [Aa]ssets/AssetStoreTools*

# IDEs
.vs/
.idea/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
#*.csproj
*.unityproj
#*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

# Crashlytics generated file
crashlytics-build.properties
8 changes: 8 additions & 0 deletions dist/test-standalone-scripts/Assets/Editor.meta

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

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

Loading