Revert "fix documentation and add error message for missing jq"

This reverts commit 0df3ab6b88.
pull/164/head
Aaron Trudeau 2023-06-10 15:15:57 -04:00
parent ed7bbc6831
commit 22d5420ebc
No known key found for this signature in database
GPG Key ID: 5EA8D416A3C71A20
2 changed files with 240 additions and 247 deletions

View File

@ -9,7 +9,7 @@ inputs:
customImage: customImage:
required: false required: false
default: '' default: ''
description: 'Specific docker image that should be used for testing the project. If packageMode is true, this image must have jq installed.' description: 'Specific docker image that should be used for testing the project. If packageMode is true, this image must be compatible with apt-get.'
projectPath: projectPath:
required: false required: false
description: 'Path to the Unity project or package to be tested.' description: 'Path to the Unity project or package to be tested.'

View File

@ -1,246 +1,239 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# Set and display project path # Set and display project path
# #
UNITY_PROJECT_PATH="$GITHUB_WORKSPACE/$PROJECT_PATH" UNITY_PROJECT_PATH="$GITHUB_WORKSPACE/$PROJECT_PATH"
echo "Using project path \"$UNITY_PROJECT_PATH\"." echo "Using project path \"$UNITY_PROJECT_PATH\"."
# #
# Set and display the artifacts path # Set and display the artifacts path
# #
echo "Using artifacts path \"$ARTIFACTS_PATH\" to save test results." echo "Using artifacts path \"$ARTIFACTS_PATH\" to save test results."
FULL_ARTIFACTS_PATH=$GITHUB_WORKSPACE/$ARTIFACTS_PATH FULL_ARTIFACTS_PATH=$GITHUB_WORKSPACE/$ARTIFACTS_PATH
# #
# Set and display the coverage results path # Set and display the coverage results path
# #
echo "Using coverage results path \"$COVERAGE_RESULTS_PATH\" to save test coverage results." echo "Using coverage results path \"$COVERAGE_RESULTS_PATH\" to save test coverage results."
FULL_COVERAGE_RESULTS_PATH=$GITHUB_WORKSPACE/$COVERAGE_RESULTS_PATH FULL_COVERAGE_RESULTS_PATH=$GITHUB_WORKSPACE/$COVERAGE_RESULTS_PATH
# #
# Display custom parameters # Display custom parameters
# #
echo "Using custom parameters $CUSTOM_PARAMETERS." echo "Using custom parameters $CUSTOM_PARAMETERS."
# The following tests are 2019 mode (requires Unity 2019.2.11f1 or later) # The following tests are 2019 mode (requires Unity 2019.2.11f1 or later)
# Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html # Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html
# #
# Display the unity version # Display the unity version
# #
echo "Using Unity version \"$UNITY_VERSION\" to test." echo "Using Unity version \"$UNITY_VERSION\" to test."
# #
# Create an empty project for testing if in package mode # Create an empty project for testing if in package mode
# #
if [ "$PACKAGE_MODE" = "true" ]; then if [ "$PACKAGE_MODE" = "true" ]; then
echo "Running tests on a Unity package rather than a Unity project." echo "Running tests on a Unity package rather than a Unity project."
if ! command -v jq &> /dev/null echo ""
then echo "###########################"
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." echo "# Package Folder #"
exit echo "###########################"
fi echo ""
ls -la "$UNITY_PROJECT_PATH"
echo "" echo ""
echo "###########################"
echo "# Package Folder #" echo "Creating an empty Unity project to add the package $PACKAGE_NAME to."
echo "###########################"
echo "" TEMP_PROJECT_PATH="./TempProject"
ls -la "$UNITY_PROJECT_PATH" unity-editor \
echo "" -batchmode \
-createProject "$TEMP_PROJECT_PATH" \
echo "Creating an empty Unity project to add the package $PACKAGE_NAME to." -quit
TEMP_PROJECT_PATH="./TempProject" # 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..."
unity-editor \ echo ""
-batchmode \
-createProject "$TEMP_PROJECT_PATH" \ PACKAGE_MANIFEST_PATH="$TEMP_PROJECT_PATH/Packages/manifest.json"
-quit 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..."
# 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 ""
echo "" echo "###########################"
echo "# Temp Project Folder #"
PACKAGE_MANIFEST_PATH="$TEMP_PROJECT_PATH/Packages/manifest.json" echo "###########################"
if [ ! -f "$PACKAGE_MANIFEST_PATH" ]; then echo ""
echo "Packages/mainfest.json was not created properly. This indicates a problem with the Action, not with your package. Logging directories and aborting..."
ls -a "$TEMP_PROJECT_PATH"
echo ""
echo "###########################" echo ""
echo "# Temp Project Folder #" echo "################################"
echo "###########################" echo "# Temp Project Packages Folder #"
echo "" echo "################################"
echo ""
ls -a "$TEMP_PROJECT_PATH"
ls -a "$TEMP_PROJECT_PATH/Packages"
echo ""
echo "################################" exit 1
echo "# Temp Project Packages Folder #" fi
echo "################################"
echo "" PACKAGE_MANIFEST_JSON=$(cat "$PACKAGE_MANIFEST_PATH")
echo "$PACKAGE_MANIFEST_JSON" | \
ls -a "$TEMP_PROJECT_PATH/Packages" jq \
--arg packageName "$PACKAGE_NAME" \
exit 1 --arg projectPath "$UNITY_PROJECT_PATH" \
fi '.dependencies += {"com.unity.testtools.codecoverage": "1.1.1"} | .dependencies += {"\($packageName)": "file:\($projectPath)"} | . += {testables: ["\($packageName)"]}' \
> "$PACKAGE_MANIFEST_PATH"
PACKAGE_MANIFEST_JSON=$(cat "$PACKAGE_MANIFEST_PATH")
echo "$PACKAGE_MANIFEST_JSON" | \ UNITY_PROJECT_PATH="$TEMP_PROJECT_PATH"
jq \ fi
--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" # Overall info
#
UNITY_PROJECT_PATH="$TEMP_PROJECT_PATH"
fi echo ""
echo "###########################"
echo "# Artifacts folder #"
# echo "###########################"
# Overall info echo ""
# echo "Creating \"$FULL_ARTIFACTS_PATH\" if it does not exist."
mkdir -p $FULL_ARTIFACTS_PATH
echo ""
echo "###########################" echo ""
echo "# Artifacts folder #" echo "###########################"
echo "###########################" echo "# Project directory #"
echo "" echo "###########################"
echo "Creating \"$FULL_ARTIFACTS_PATH\" if it does not exist." echo ""
mkdir -p $FULL_ARTIFACTS_PATH ls -alh $UNITY_PROJECT_PATH
echo "" #
echo "###########################" # Testing for each platform
echo "# Project directory #" #
echo "###########################" for platform in ${TEST_PLATFORMS//;/ }; do
echo "" if [[ "$platform" == "standalone" ]]; then
ls -alh $UNITY_PROJECT_PATH echo ""
echo "###########################"
# echo "# Building Standalone #"
# Testing for each platform echo "###########################"
# echo ""
for platform in ${TEST_PLATFORMS//;/ }; do
if [[ "$platform" == "standalone" ]]; then # Create directories if they do not exist
echo "" mkdir -p "$UNITY_PROJECT_PATH/Assets/Editor/"
echo "###########################" mkdir -p "$UNITY_PROJECT_PATH/Assets/Player/"
echo "# Building Standalone #" # Copy the scripts
echo "###########################" cp -R "$ACTION_FOLDER/UnityStandaloneScripts/Assets/Editor/" "$UNITY_PROJECT_PATH/Assets/Editor/"
echo "" cp -R "$ACTION_FOLDER/UnityStandaloneScripts/Assets/Player/" "$UNITY_PROJECT_PATH/Assets/Player/"
# Verify recursive paths
# Create directories if they do not exist ls -Ralph "$UNITY_PROJECT_PATH/Assets/Editor/"
mkdir -p "$UNITY_PROJECT_PATH/Assets/Editor/" ls -Ralph "$UNITY_PROJECT_PATH/Assets/Player/"
mkdir -p "$UNITY_PROJECT_PATH/Assets/Player/"
# Copy the scripts runTests="-runTests -testPlatform StandaloneLinux64 -builtTestRunnerPath $UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone"
cp -R "$ACTION_FOLDER/UnityStandaloneScripts/Assets/Editor/" "$UNITY_PROJECT_PATH/Assets/Editor/" else
cp -R "$ACTION_FOLDER/UnityStandaloneScripts/Assets/Player/" "$UNITY_PROJECT_PATH/Assets/Player/" echo ""
# Verify recursive paths echo "###########################"
ls -Ralph "$UNITY_PROJECT_PATH/Assets/Editor/" echo "# Testing in $platform #"
ls -Ralph "$UNITY_PROJECT_PATH/Assets/Player/" echo "###########################"
echo ""
runTests="-runTests -testPlatform StandaloneLinux64 -builtTestRunnerPath $UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone"
else if [[ "$platform" != "COMBINE_RESULTS" ]]; then
echo "" runTests="-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
echo "###########################" else
echo "# Testing in $platform #" runTests="-quit"
echo "###########################" fi
echo "" fi
if [[ "$platform" != "COMBINE_RESULTS" ]]; then unity-editor \
runTests="-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml" -batchmode \
else -logFile "$FULL_ARTIFACTS_PATH/$platform.log" \
runTests="-quit" -projectPath "$UNITY_PROJECT_PATH" \
fi -coverageResultsPath "$FULL_COVERAGE_RESULTS_PATH" \
fi $runTests \
-enableCodeCoverage \
unity-editor \ -debugCodeOptimization \
-batchmode \ -coverageOptions "$COVERAGE_OPTIONS" \
-logFile "$FULL_ARTIFACTS_PATH/$platform.log" \ $CUSTOM_PARAMETERS
-projectPath "$UNITY_PROJECT_PATH" \
-coverageResultsPath "$FULL_COVERAGE_RESULTS_PATH" \ # Catch exit code
$runTests \ TEST_EXIT_CODE=$?
-enableCodeCoverage \
-debugCodeOptimization \ # Print unity log output
-coverageOptions "$COVERAGE_OPTIONS" \ cat "$FULL_ARTIFACTS_PATH/$platform.log"
$CUSTOM_PARAMETERS
if [[ $TEST_EXIT_CODE -eq 0 && "$platform" == "standalone" ]]; then
# Catch exit code echo ""
TEST_EXIT_CODE=$? echo "###########################"
echo "# Testing Standalone #"
# Print unity log output echo "###########################"
cat "$FULL_ARTIFACTS_PATH/$platform.log" echo ""
if [[ $TEST_EXIT_CODE -eq 0 && "$platform" == "standalone" ]]; then # Code Coverage currently only supports code ran in the Editor and not in Standalone/Player.
echo "" # https://docs.unity.cn/Packages/com.unity.testtools.codecoverage@1.1/manual/TechnicalDetails.html#how-it-works
echo "###########################"
echo "# Testing Standalone #" xvfb-run -a -e /dev/stdout "$UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone" \
echo "###########################" -batchmode \
echo "" -nographics \
-logFile "$FULL_ARTIFACTS_PATH/$platform-player.log" \
# Code Coverage currently only supports code ran in the Editor and not in Standalone/Player. -testResults "$FULL_ARTIFACTS_PATH/$platform-results.xml"
# https://docs.unity.cn/Packages/com.unity.testtools.codecoverage@1.1/manual/TechnicalDetails.html#how-it-works
# Catch exit code
xvfb-run -a -e /dev/stdout "$UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone" \ TEST_EXIT_CODE=$?
-batchmode \
-nographics \ # Print player log output
-logFile "$FULL_ARTIFACTS_PATH/$platform-player.log" \ cat "$FULL_ARTIFACTS_PATH/$platform-player.log"
-testResults "$FULL_ARTIFACTS_PATH/$platform-results.xml" fi
# Catch exit code # Display results
TEST_EXIT_CODE=$? if [ $TEST_EXIT_CODE -eq 0 ]; then
echo "Run succeeded, no failures occurred";
# Print player log output elif [ $TEST_EXIT_CODE -eq 2 ]; then
cat "$FULL_ARTIFACTS_PATH/$platform-player.log" echo "Run succeeded, some tests failed";
fi elif [ $TEST_EXIT_CODE -eq 3 ]; then
echo "Run failure (other failure)";
# Display results else
if [ $TEST_EXIT_CODE -eq 0 ]; then echo "Unexpected exit code $TEST_EXIT_CODE";
echo "Run succeeded, no failures occurred"; fi
elif [ $TEST_EXIT_CODE -eq 2 ]; then
echo "Run succeeded, some tests failed"; if [ $TEST_EXIT_CODE -ne 0 ]; then
elif [ $TEST_EXIT_CODE -eq 3 ]; then TEST_RUNNER_EXIT_CODE=$TEST_EXIT_CODE
echo "Run failure (other failure)"; fi
else
echo "Unexpected exit code $TEST_EXIT_CODE"; echo ""
fi echo "###########################"
echo "# $platform Results #"
if [ $TEST_EXIT_CODE -ne 0 ]; then echo "###########################"
TEST_RUNNER_EXIT_CODE=$TEST_EXIT_CODE echo ""
fi
if [[ "$platform" != "COMBINE_RESULTS" ]]; then
echo "" cat "$FULL_ARTIFACTS_PATH/$platform-results.xml"
echo "###########################" cat "$FULL_ARTIFACTS_PATH/$platform-results.xml" | grep test-run | grep Passed
echo "# $platform Results #" fi
echo "###########################" done
echo ""
#
if [[ "$platform" != "COMBINE_RESULTS" ]]; then # Permissions
cat "$FULL_ARTIFACTS_PATH/$platform-results.xml" #
cat "$FULL_ARTIFACTS_PATH/$platform-results.xml" | grep test-run | grep Passed
fi # Make a given user owner of all artifacts
done if [[ -n "$CHOWN_FILES_TO" ]]; then
chown -R "$CHOWN_FILES_TO" "$UNITY_PROJECT_PATH"
# chown -R "$CHOWN_FILES_TO" "$FULL_ARTIFACTS_PATH"
# Permissions chown -R "$CHOWN_FILES_TO" "$FULL_COVERAGE_RESULTS_PATH"
# fi
# Make a given user owner of all artifacts # Add read permissions for everyone to all artifacts
if [[ -n "$CHOWN_FILES_TO" ]]; then chmod -R a+r "$UNITY_PROJECT_PATH"
chown -R "$CHOWN_FILES_TO" "$UNITY_PROJECT_PATH" chmod -R a+r "$FULL_ARTIFACTS_PATH"
chown -R "$CHOWN_FILES_TO" "$FULL_ARTIFACTS_PATH" chmod -R a+r "$FULL_COVERAGE_RESULTS_PATH"
chown -R "$CHOWN_FILES_TO" "$FULL_COVERAGE_RESULTS_PATH"
fi
# Add read permissions for everyone to all artifacts
chmod -R a+r "$UNITY_PROJECT_PATH"
chmod -R a+r "$FULL_ARTIFACTS_PATH"
chmod -R a+r "$FULL_COVERAGE_RESULTS_PATH"