Skip to content

Commit 53cbed3

Browse files
committed
Merge remote-tracking branch 'upstream/main'
1 parent ee63777 commit 53cbed3

File tree

80 files changed

+4941
-2708
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+4941
-2708
lines changed

.github/workflows/main.yml

+340-6
Large diffs are not rendered by default.

.husky/pre-commit

100644100755
File mode changed.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

99
Part of the <a href="https://game.ci">GameCI</a> open source project.
1010
<br />

action.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ inputs:
55
unityVersion:
66
required: false
77
default: 'auto'
8-
description: 'Version of unity to use for testing the project. Use "auto" to get from your ProjectSettings/ProjectVersion.txt'
8+
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".'
99
customImage:
1010
required: false
1111
default: ''
12-
description: 'Specific docker image that should be used for testing the project'
12+
description: 'Specific docker image that should be used for testing the project. If packageMode is true, this image must have jq installed.'
1313
projectPath:
1414
required: false
15-
description: 'Path to the Unity project to be tested.'
15+
description: 'Path to the Unity project or package to be tested.'
1616
customParameters:
1717
required: false
1818
description: 'Extra parameters to configure the Unity editor run.'
@@ -23,7 +23,7 @@ inputs:
2323
coverageOptions:
2424
required: false
2525
default: 'generateAdditionalMetrics;generateHtmlReport;generateBadgeReport;dontClear'
26-
description: 'Optional coverage parameters for the -coverageOptions argument.'
26+
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.'
2727
artifactsPath:
2828
required: false
2929
default: 'artifacts'
@@ -48,6 +48,10 @@ inputs:
4848
required: false
4949
default: 'Test Results'
5050
description: 'Name for the check run that is created when a github token is provided.'
51+
packageMode:
52+
required: false
53+
default: false
54+
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.'
5155
chownFilesTo:
5256
required: false
5357
default: ''

dist/index.js

+942-1,322
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/sourcemap-register.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/steps/run_tests.ps1

+56-9
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,52 @@ Get-ChildItem -Hidden -Path $UNITY_PROJECT_PATH
5858
#
5959
foreach ( $platform in ${env:TEST_PLATFORMS}.Split(";") )
6060
{
61-
Write-Output ""
62-
Write-Output "###########################"
63-
Write-Output "# Testing in $platform #"
64-
Write-Output "###########################"
65-
Write-Output ""
66-
67-
if ( $platform -ne "COMBINE_RESULTS" )
61+
if ( "$platform" -eq "standalone" )
6862
{
69-
$runTests = "-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
63+
Write-Output ""
64+
Write-Output "###########################"
65+
Write-Output "# Building Standalone #"
66+
Write-Output "###########################"
67+
Write-Output ""
68+
69+
# Create directories if they do not exist
70+
if(-Not (Test-Path -Path $Env:UNITY_PROJECT_PATH\Assets\Editor))
71+
{
72+
# We use -Force to suppress output, doesn't overwrite anything
73+
New-Item -ItemType Directory -Force -Path $Env:UNITY_PROJECT_PATH\Assets\Editor
74+
}
75+
if(-Not (Test-Path -Path $Env:UNITY_PROJECT_PATH\Assets\Player))
76+
{
77+
# We use -Force to suppress output, doesn't overwrite anything
78+
New-Item -ItemType Directory -Force -Path $Env:UNITY_PROJECT_PATH\Assets\Player
79+
}
80+
81+
# Copy the scripts
82+
Copy-Item -Path "c:\UnityStandaloneScripts\Assets\Editor" -Destination $Env:UNITY_PROJECT_PATH\Assets\Editor -Recurse
83+
Copy-Item -Path "c:\UnityStandaloneScripts\Assets\Player" -Destination $Env:UNITY_PROJECT_PATH\Assets\Player -Recurse
84+
85+
# Verify recursive paths
86+
Get-ChildItem -Path $Env:UNITY_PROJECT_PATH\Assets\Editor -Recurse
87+
Get-ChildItem -Path $Env:UNITY_PROJECT_PATH\Assets\Player -Recurse
88+
89+
$runTests="-runTests -testPlatform StandaloneWindows64 -builtTestRunnerPath $UNITY_PROJECT_PATH\Build\UnityTestRunner-Standalone.exe"
7090
}
7191
else
7292
{
73-
$runTests = "-quit"
93+
Write-Output ""
94+
Write-Output "###########################"
95+
Write-Output "# Testing in $platform #"
96+
Write-Output "###########################"
97+
Write-Output ""
98+
99+
if ( $platform -ne "COMBINE_RESULTS" )
100+
{
101+
$runTests = "-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
102+
}
103+
else
104+
{
105+
$runTests = "-quit"
106+
}
74107
}
75108

76109
$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}"
@@ -81,6 +114,20 @@ foreach ( $platform in ${env:TEST_PLATFORMS}.Split(";") )
81114
# Print unity log output
82115
Get-Content "$FULL_ARTIFACTS_PATH/$platform.log"
83116

117+
if ( ( $TEST_EXIT_CODE -eq 0 ) -and ( "$platform" -eq "standalone" ) )
118+
{
119+
# Code Coverage currently only supports code ran in the Editor and not in Standalone/Player.
120+
# https://docs.unity.cn/Packages/[email protected]/manual/TechnicalDetails.html#how-it-works
121+
122+
$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"
123+
124+
# Catch exit code
125+
$TEST_EXIT_CODE = $TEST_OUTPUT.ExitCode
126+
127+
# Print player log output
128+
Get-Content "$FULL_ARTIFACTS_PATH/$platform-player.log"
129+
}
130+
84131
# Display results
85132
if ($TEST_EXIT_CODE -eq 0)
86133
{

dist/steps/run_tests.sh

+122-9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,76 @@ echo "Using custom parameters $CUSTOM_PARAMETERS."
3636

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

39+
#
40+
# Create an empty project for testing if in package mode
41+
#
42+
43+
if [ "$PACKAGE_MODE" = "true" ]; then
44+
echo "Running tests on a Unity package rather than a Unity project."
45+
46+
if ! command -v jq &> /dev/null
47+
then
48+
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."
49+
exit 1
50+
fi
51+
52+
echo ""
53+
echo "###########################"
54+
echo "# Package Folder #"
55+
echo "###########################"
56+
echo ""
57+
58+
ls -la "$UNITY_PROJECT_PATH"
59+
echo ""
60+
61+
echo "Creating an empty Unity project to add the package $PACKAGE_NAME to."
62+
63+
TEMP_PROJECT_PATH="./TempProject"
64+
65+
unity-editor \
66+
-batchmode \
67+
-createProject "$TEMP_PROJECT_PATH" \
68+
-quit
69+
70+
# use jq to add the package to the temp project through manually modifying Packages/manifest.json
71+
echo "Adding package to the temporary project's dependencies and testables..."
72+
echo ""
73+
74+
PACKAGE_MANIFEST_PATH="$TEMP_PROJECT_PATH/Packages/manifest.json"
75+
if [ ! -f "$PACKAGE_MANIFEST_PATH" ]; then
76+
echo "Packages/mainfest.json was not created properly. This indicates a problem with the Action, not with your package. Logging directories and aborting..."
77+
78+
echo ""
79+
echo "###########################"
80+
echo "# Temp Project Folder #"
81+
echo "###########################"
82+
echo ""
83+
84+
ls -a "$TEMP_PROJECT_PATH"
85+
86+
echo ""
87+
echo "################################"
88+
echo "# Temp Project Packages Folder #"
89+
echo "################################"
90+
echo ""
91+
92+
ls -a "$TEMP_PROJECT_PATH/Packages"
93+
94+
exit 1
95+
fi
96+
97+
PACKAGE_MANIFEST_JSON=$(cat "$PACKAGE_MANIFEST_PATH")
98+
echo "$PACKAGE_MANIFEST_JSON" | \
99+
jq \
100+
--arg packageName "$PACKAGE_NAME" \
101+
--arg projectPath "$UNITY_PROJECT_PATH" \
102+
'.dependencies += {"com.unity.testtools.codecoverage": "1.1.1"} | .dependencies += {"\($packageName)": "file:\($projectPath)"} | . += {testables: ["\($packageName)"]}' \
103+
> "$PACKAGE_MANIFEST_PATH"
104+
105+
UNITY_PROJECT_PATH="$TEMP_PROJECT_PATH"
106+
fi
107+
108+
39109
#
40110
# Overall info
41111
#
@@ -59,16 +129,36 @@ ls -alh $UNITY_PROJECT_PATH
59129
# Testing for each platform
60130
#
61131
for platform in ${TEST_PLATFORMS//;/ }; do
62-
echo ""
63-
echo "###########################"
64-
echo "# Testing in $platform #"
65-
echo "###########################"
66-
echo ""
67-
68-
if [[ "$platform" != "COMBINE_RESULTS" ]]; then
69-
runTests="-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
132+
if [[ "$platform" == "standalone" ]]; then
133+
echo ""
134+
echo "###########################"
135+
echo "# Building Standalone #"
136+
echo "###########################"
137+
echo ""
138+
139+
# Create directories if they do not exist
140+
mkdir -p "$UNITY_PROJECT_PATH/Assets/Editor/"
141+
mkdir -p "$UNITY_PROJECT_PATH/Assets/Player/"
142+
# Copy the scripts
143+
cp -R "$ACTION_FOLDER/UnityStandaloneScripts/Assets/Editor/" "$UNITY_PROJECT_PATH/Assets/Editor/"
144+
cp -R "$ACTION_FOLDER/UnityStandaloneScripts/Assets/Player/" "$UNITY_PROJECT_PATH/Assets/Player/"
145+
# Verify recursive paths
146+
ls -Ralph "$UNITY_PROJECT_PATH/Assets/Editor/"
147+
ls -Ralph "$UNITY_PROJECT_PATH/Assets/Player/"
148+
149+
runTests="-runTests -testPlatform StandaloneLinux64 -builtTestRunnerPath $UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone"
70150
else
71-
runTests="-quit"
151+
echo ""
152+
echo "###########################"
153+
echo "# Testing in $platform #"
154+
echo "###########################"
155+
echo ""
156+
157+
if [[ "$platform" != "COMBINE_RESULTS" ]]; then
158+
runTests="-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
159+
else
160+
runTests="-quit"
161+
fi
72162
fi
73163

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

181+
if [[ $TEST_EXIT_CODE -eq 0 && "$platform" == "standalone" ]]; then
182+
echo ""
183+
echo "###########################"
184+
echo "# Testing Standalone #"
185+
echo "###########################"
186+
echo ""
187+
188+
# Code Coverage currently only supports code ran in the Editor and not in Standalone/Player.
189+
# https://docs.unity.cn/Packages/[email protected]/manual/TechnicalDetails.html#how-it-works
190+
191+
xvfb-run -a -e /dev/stdout "$UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone" \
192+
-batchmode \
193+
-nographics \
194+
-logFile "$FULL_ARTIFACTS_PATH/$platform-player.log" \
195+
-testResults "$FULL_ARTIFACTS_PATH/$platform-results.xml"
196+
197+
# Catch exit code
198+
TEST_EXIT_CODE=$?
199+
200+
# Print player log output
201+
cat "$FULL_ARTIFACTS_PATH/$platform-player.log"
202+
fi
203+
91204
# Display results
92205
if [ $TEST_EXIT_CODE -eq 0 ]; then
93206
echo "Run succeeded, no failures occurred";
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#
2+
# Note: Non default ignore file, as this only tests Builder script.
3+
#
4+
5+
[Ll]ibrary/
6+
[Tt]emp/
7+
[Oo]bj/
8+
[Bb]uild/
9+
[Bb]uilds/
10+
[Ll]ogs/
11+
12+
# Additional ignores
13+
[Bb]in/
14+
15+
# Uncomment this line if you wish to ignore the asset store tools plugin
16+
# [Aa]ssets/AssetStoreTools*
17+
18+
# IDEs
19+
.vs/
20+
.idea/
21+
22+
# Gradle cache directory
23+
.gradle/
24+
25+
# Autogenerated VS/MD/Consulo solution and project files
26+
ExportedObj/
27+
.consulo/
28+
#*.csproj
29+
*.unityproj
30+
#*.sln
31+
*.suo
32+
*.tmp
33+
*.user
34+
*.userprefs
35+
*.pidb
36+
*.booproj
37+
*.svd
38+
*.pdb
39+
*.mdb
40+
*.opendb
41+
*.VC.db
42+
43+
# Unity3D generated meta files
44+
*.pidb.meta
45+
*.pdb.meta
46+
*.mdb.meta
47+
48+
# Unity3D generated file on crash reports
49+
sysinfo.txt
50+
51+
# Builds
52+
*.apk
53+
*.unitypackage
54+
55+
# Crashlytics generated file
56+
crashlytics-build.properties

dist/test-standalone-scripts/Assets/Editor.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test-standalone-scripts/Assets/Editor/UnityTestRunnerAction.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)