2020-01-29 22:37:11 +00:00
#!/usr/bin/env bash
2020-01-29 22:42:41 +00:00
#
# Set and display project path
#
2020-01-30 07:46:02 +00:00
UNITY_PROJECT_PATH = " $GITHUB_WORKSPACE / $PROJECT_PATH "
2020-01-29 22:37:11 +00:00
echo " Using project path \" $UNITY_PROJECT_PATH \". "
2021-10-21 04:10:08 +00:00
#
# 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."
2022-05-11 03:47:07 +00:00
ACTIVATE_LICENSE_FILE_NAME = "_activate-license"
2022-05-11 04:00:54 +00:00
#if [ -f "$UNITY_PROJECT_PATH/$ACTIVATE_LICENSE_FILE_NAME" ]; then
2022-05-11 03:47:07 +00:00
echo "Package is in repository root. Copying package to temporary directory to avoid Unity Errors."
ROOT_FOLDER_NAME = $( echo " ${ PWD ##*/ } " )
COPIED_PACKAGE_DIR_NAME = "copiedPackage"
rsync -r " $GITHUB_WORKSPACE " " $COPIED_PACKAGE_DIR_NAME " --exclude "ACTIVATE_LICENSE_FILE_NAME"
UNITY_PROJECT_PATH = " $COPIED_PACKAGE_DIR_NAME / $ROOT_FOLDER_NAME "
2022-05-11 04:00:54 +00:00
#fi
2022-05-11 03:47:07 +00:00
2021-10-21 04:10:08 +00:00
echo ""
echo "###########################"
echo "# Package Folder #"
echo "###########################"
echo ""
2021-10-21 04:53:09 +00:00
ls " $UNITY_PROJECT_PATH "
2022-01-27 05:51:03 +00:00
echo ""
2021-10-21 04:10:08 +00:00
2022-03-01 03:26:50 +00:00
echo " Creating an empty Unity project to add the package $PACKAGE_NAME to. "
2021-10-21 04:42:24 +00:00
2022-03-01 03:26:50 +00:00
TEMP_PROJECT_PATH = "./TempProject"
2021-10-21 04:10:08 +00:00
2021-10-21 05:30:00 +00:00
unity-editor \
2022-01-17 19:45:35 +00:00
-batchmode \
2022-03-01 03:26:50 +00:00
-createProject " $TEMP_PROJECT_PATH " \
2021-10-21 04:53:09 +00:00
-quit
2022-01-27 06:22:28 +00:00
# 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..."
2022-01-27 07:32:02 +00:00
echo ""
2022-01-27 05:51:03 +00:00
2022-03-01 03:26:50 +00:00
PACKAGE_MANIFEST_PATH = " $TEMP_PROJECT_PATH /Packages/manifest.json "
2022-01-27 05:51:03 +00:00
if [ ! -f " $PACKAGE_MANIFEST_PATH " ] ; then
2022-03-01 03:47:29 +00:00
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 "
2022-01-27 05:51:03 +00:00
exit 1
fi
PACKAGE_MANIFEST_JSON = $( cat " $PACKAGE_MANIFEST_PATH " )
2022-01-27 06:12:50 +00:00
echo " $PACKAGE_MANIFEST_JSON " | \
2022-01-27 06:29:46 +00:00
jq \
--arg packageName " $PACKAGE_NAME " \
--arg projectPath " $UNITY_PROJECT_PATH " \
2022-04-26 17:21:43 +00:00
'.dependencies += {"com.unity.testtools.codecoverage": "1.1.1"} | .dependencies += {"\($packageName)": "file:\($projectPath)"} | . += {testables: ["\($packageName)"]}' \
2022-01-27 06:22:28 +00:00
> " $PACKAGE_MANIFEST_PATH "
2022-01-27 05:51:03 +00:00
2022-03-01 03:26:50 +00:00
UNITY_PROJECT_PATH = " $TEMP_PROJECT_PATH "
2021-10-21 04:10:08 +00:00
fi
2020-01-29 22:42:41 +00:00
#
# Set and display the artifacts path
#
2020-01-30 23:35:41 +00:00
echo " Using artifacts path \" $ARTIFACTS_PATH \" to save test results. "
2020-01-29 22:37:11 +00:00
FULL_ARTIFACTS_PATH = $GITHUB_WORKSPACE /$ARTIFACTS_PATH
2022-04-21 08:50:37 +00:00
#
# Set and display the coverage results path
#
echo " Using coverage results path \" $COVERAGE_RESULTS_PATH \" to save test coverage results. "
FULL_COVERAGE_RESULTS_PATH = $GITHUB_WORKSPACE /$COVERAGE_RESULTS_PATH
2020-01-29 22:54:44 +00:00
#
# Display custom parameters
#
2022-04-21 08:50:37 +00:00
echo " Using custom parameters $CUSTOM_PARAMETERS . "
2020-01-29 22:37:11 +00:00
# The following tests are 2019 mode (requires Unity 2019.2.11f1 or later)
# Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html
#
# Display the unity version
#
echo " Using Unity version \" $UNITY_VERSION \" to test. "
#
# Overall info
#
echo ""
echo "###########################"
echo "# Artifacts folder #"
echo "###########################"
echo ""
echo " Creating \" $FULL_ARTIFACTS_PATH \" if it does not exist. "
mkdir -p $FULL_ARTIFACTS_PATH
echo ""
echo "###########################"
echo "# Project directory #"
echo "###########################"
echo ""
ls -alh $UNITY_PROJECT_PATH
#
2022-04-21 08:50:37 +00:00
# Testing for each platform
2020-01-29 22:37:11 +00:00
#
2022-04-21 08:50:37 +00:00
for platform in ${ TEST_PLATFORMS //;/ } ; do
2020-01-29 22:37:11 +00:00
echo ""
echo "###########################"
2022-04-21 08:50:37 +00:00
echo " # Testing in $platform # "
2020-01-29 22:37:11 +00:00
echo "###########################"
echo ""
2020-11-26 17:19:17 +00:00
2022-04-21 08:50:37 +00:00
if [ [ " $platform " != "COMBINE_RESULTS" ] ] ; then
runTests = " -runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH / $platform -results.xml "
2020-01-29 22:37:11 +00:00
else
2022-04-21 08:50:37 +00:00
runTests = "-quit"
2020-01-29 22:37:11 +00:00
fi
2020-11-26 17:19:17 +00:00
unity-editor \
-batchmode \
2022-04-21 08:50:37 +00:00
-logFile " $FULL_ARTIFACTS_PATH / $platform .log " \
2020-11-26 17:19:17 +00:00
-projectPath " $UNITY_PROJECT_PATH " \
2022-04-21 08:50:37 +00:00
-coverageResultsPath " $FULL_COVERAGE_RESULTS_PATH " \
$runTests \
-enableCodeCoverage \
-debugCodeOptimization \
-coverageOptions " $COVERAGE_OPTIONS " \
2020-11-26 17:19:17 +00:00
$CUSTOM_PARAMETERS
2020-02-14 21:26:26 +00:00
# Catch exit code
2022-04-21 08:50:37 +00:00
TEST_EXIT_CODE = $?
2020-01-29 22:37:11 +00:00
2020-02-13 19:53:30 +00:00
# Print unity log output
2022-04-21 08:50:37 +00:00
cat " $FULL_ARTIFACTS_PATH / $platform .log "
2020-02-13 19:53:30 +00:00
2020-01-29 22:37:11 +00:00
# Display results
2022-04-21 08:50:37 +00:00
if [ $TEST_EXIT_CODE -eq 0 ] ; then
2020-01-29 22:37:11 +00:00
echo "Run succeeded, no failures occurred" ;
2022-04-21 08:50:37 +00:00
elif [ $TEST_EXIT_CODE -eq 2 ] ; then
2020-01-29 22:37:11 +00:00
echo "Run succeeded, some tests failed" ;
2022-04-21 08:50:37 +00:00
elif [ $TEST_EXIT_CODE -eq 3 ] ; then
2020-01-29 22:37:11 +00:00
echo "Run failure (other failure)" ;
else
2022-04-21 08:50:37 +00:00
echo " Unexpected exit code $TEST_EXIT_CODE " ;
2020-01-29 22:37:11 +00:00
fi
2022-04-21 08:50:37 +00:00
if [ $TEST_EXIT_CODE -ne 0 ] ; then
TEST_RUNNER_EXIT_CODE = $TEST_EXIT_CODE
fi
2020-01-29 22:37:11 +00:00
echo ""
echo "###########################"
2022-04-21 08:50:37 +00:00
echo " # $platform Results # "
2020-01-29 22:37:11 +00:00
echo "###########################"
echo ""
2022-04-21 08:50:37 +00:00
if [ [ " $platform " != "COMBINE_RESULTS" ] ] ; then
cat " $FULL_ARTIFACTS_PATH / $platform -results.xml "
cat " $FULL_ARTIFACTS_PATH / $platform -results.xml " | grep test-run | grep Passed
fi
done