fix documentation and add error message for missing jq

pull/164/head
Aaron Trudeau 2023-06-07 01:23:53 -04:00
parent 1afbd6b347
commit 0df3ab6b88
No known key found for this signature in database
GPG Key ID: 5EA8D416A3C71A20
2 changed files with 247 additions and 240 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 be compatible with apt-get.' description: 'Specific docker image that should be used for testing the project. If packageMode is true, this image must have jq installed.'
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,239 +1,246 @@
#!/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."
echo "" if ! command -v jq &> /dev/null
echo "###########################" then
echo "# Package Folder #" 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 "###########################" exit
echo "" fi
ls -la "$UNITY_PROJECT_PATH"
echo "" echo ""
echo "###########################"
echo "Creating an empty Unity project to add the package $PACKAGE_NAME to." echo "# Package Folder #"
echo "###########################"
TEMP_PROJECT_PATH="./TempProject" echo ""
unity-editor \ ls -la "$UNITY_PROJECT_PATH"
-batchmode \ echo ""
-createProject "$TEMP_PROJECT_PATH" \
-quit echo "Creating an empty Unity project to add the package $PACKAGE_NAME to."
# use jq to add the package to the temp project through manually modifying Packages/manifest.json TEMP_PROJECT_PATH="./TempProject"
echo "Adding package to the temporary project's dependencies and testables..."
echo "" unity-editor \
-batchmode \
PACKAGE_MANIFEST_PATH="$TEMP_PROJECT_PATH/Packages/manifest.json" -createProject "$TEMP_PROJECT_PATH" \
if [ ! -f "$PACKAGE_MANIFEST_PATH" ]; then -quit
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 "" echo "Adding package to the temporary project's dependencies and testables..."
echo "###########################" echo ""
echo "# Temp Project Folder #"
echo "###########################" PACKAGE_MANIFEST_PATH="$TEMP_PROJECT_PATH/Packages/manifest.json"
echo "" 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..."
ls -a "$TEMP_PROJECT_PATH"
echo ""
echo "" echo "###########################"
echo "################################" echo "# Temp Project Folder #"
echo "# Temp Project Packages Folder #" echo "###########################"
echo "################################" echo ""
echo ""
ls -a "$TEMP_PROJECT_PATH"
ls -a "$TEMP_PROJECT_PATH/Packages"
echo ""
exit 1 echo "################################"
fi echo "# Temp Project Packages Folder #"
echo "################################"
PACKAGE_MANIFEST_JSON=$(cat "$PACKAGE_MANIFEST_PATH") echo ""
echo "$PACKAGE_MANIFEST_JSON" | \
jq \ ls -a "$TEMP_PROJECT_PATH/Packages"
--arg packageName "$PACKAGE_NAME" \
--arg projectPath "$UNITY_PROJECT_PATH" \ exit 1
'.dependencies += {"com.unity.testtools.codecoverage": "1.1.1"} | .dependencies += {"\($packageName)": "file:\($projectPath)"} | . += {testables: ["\($packageName)"]}' \ fi
> "$PACKAGE_MANIFEST_PATH"
PACKAGE_MANIFEST_JSON=$(cat "$PACKAGE_MANIFEST_PATH")
UNITY_PROJECT_PATH="$TEMP_PROJECT_PATH" echo "$PACKAGE_MANIFEST_JSON" | \
fi jq \
--arg packageName "$PACKAGE_NAME" \
--arg projectPath "$UNITY_PROJECT_PATH" \
# '.dependencies += {"com.unity.testtools.codecoverage": "1.1.1"} | .dependencies += {"\($packageName)": "file:\($projectPath)"} | . += {testables: ["\($packageName)"]}' \
# Overall info > "$PACKAGE_MANIFEST_PATH"
#
UNITY_PROJECT_PATH="$TEMP_PROJECT_PATH"
echo "" fi
echo "###########################"
echo "# Artifacts folder #"
echo "###########################" #
echo "" # Overall info
echo "Creating \"$FULL_ARTIFACTS_PATH\" if it does not exist." #
mkdir -p $FULL_ARTIFACTS_PATH
echo ""
echo "" echo "###########################"
echo "###########################" echo "# Artifacts folder #"
echo "# Project directory #" echo "###########################"
echo "###########################" echo ""
echo "" echo "Creating \"$FULL_ARTIFACTS_PATH\" if it does not exist."
ls -alh $UNITY_PROJECT_PATH mkdir -p $FULL_ARTIFACTS_PATH
# echo ""
# Testing for each platform echo "###########################"
# echo "# Project directory #"
for platform in ${TEST_PLATFORMS//;/ }; do echo "###########################"
if [[ "$platform" == "standalone" ]]; then echo ""
echo "" ls -alh $UNITY_PROJECT_PATH
echo "###########################"
echo "# Building Standalone #" #
echo "###########################" # Testing for each platform
echo "" #
for platform in ${TEST_PLATFORMS//;/ }; do
# Create directories if they do not exist if [[ "$platform" == "standalone" ]]; then
mkdir -p "$UNITY_PROJECT_PATH/Assets/Editor/" echo ""
mkdir -p "$UNITY_PROJECT_PATH/Assets/Player/" echo "###########################"
# Copy the scripts echo "# Building Standalone #"
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/" echo ""
# Verify recursive paths
ls -Ralph "$UNITY_PROJECT_PATH/Assets/Editor/" # Create directories if they do not exist
ls -Ralph "$UNITY_PROJECT_PATH/Assets/Player/" mkdir -p "$UNITY_PROJECT_PATH/Assets/Editor/"
mkdir -p "$UNITY_PROJECT_PATH/Assets/Player/"
runTests="-runTests -testPlatform StandaloneLinux64 -builtTestRunnerPath $UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone" # Copy the scripts
else 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/"
echo "###########################" # Verify recursive paths
echo "# Testing in $platform #" ls -Ralph "$UNITY_PROJECT_PATH/Assets/Editor/"
echo "###########################" ls -Ralph "$UNITY_PROJECT_PATH/Assets/Player/"
echo ""
runTests="-runTests -testPlatform StandaloneLinux64 -builtTestRunnerPath $UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone"
if [[ "$platform" != "COMBINE_RESULTS" ]]; then else
runTests="-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml" echo ""
else echo "###########################"
runTests="-quit" echo "# Testing in $platform #"
fi echo "###########################"
fi echo ""
unity-editor \ if [[ "$platform" != "COMBINE_RESULTS" ]]; then
-batchmode \ runTests="-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
-logFile "$FULL_ARTIFACTS_PATH/$platform.log" \ else
-projectPath "$UNITY_PROJECT_PATH" \ runTests="-quit"
-coverageResultsPath "$FULL_COVERAGE_RESULTS_PATH" \ fi
$runTests \ fi
-enableCodeCoverage \
-debugCodeOptimization \ unity-editor \
-coverageOptions "$COVERAGE_OPTIONS" \ -batchmode \
$CUSTOM_PARAMETERS -logFile "$FULL_ARTIFACTS_PATH/$platform.log" \
-projectPath "$UNITY_PROJECT_PATH" \
# Catch exit code -coverageResultsPath "$FULL_COVERAGE_RESULTS_PATH" \
TEST_EXIT_CODE=$? $runTests \
-enableCodeCoverage \
# Print unity log output -debugCodeOptimization \
cat "$FULL_ARTIFACTS_PATH/$platform.log" -coverageOptions "$COVERAGE_OPTIONS" \
$CUSTOM_PARAMETERS
if [[ $TEST_EXIT_CODE -eq 0 && "$platform" == "standalone" ]]; then
echo "" # Catch exit code
echo "###########################" TEST_EXIT_CODE=$?
echo "# Testing Standalone #"
echo "###########################" # Print unity log output
echo "" cat "$FULL_ARTIFACTS_PATH/$platform.log"
# Code Coverage currently only supports code ran in the Editor and not in Standalone/Player. if [[ $TEST_EXIT_CODE -eq 0 && "$platform" == "standalone" ]]; then
# https://docs.unity.cn/Packages/com.unity.testtools.codecoverage@1.1/manual/TechnicalDetails.html#how-it-works echo ""
echo "###########################"
xvfb-run -a -e /dev/stdout "$UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone" \ echo "# Testing Standalone #"
-batchmode \ echo "###########################"
-nographics \ echo ""
-logFile "$FULL_ARTIFACTS_PATH/$platform-player.log" \
-testResults "$FULL_ARTIFACTS_PATH/$platform-results.xml" # 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
# Catch exit code
TEST_EXIT_CODE=$? xvfb-run -a -e /dev/stdout "$UNITY_PROJECT_PATH/Build/UnityTestRunner-Standalone" \
-batchmode \
# Print player log output -nographics \
cat "$FULL_ARTIFACTS_PATH/$platform-player.log" -logFile "$FULL_ARTIFACTS_PATH/$platform-player.log" \
fi -testResults "$FULL_ARTIFACTS_PATH/$platform-results.xml"
# Display results # Catch exit code
if [ $TEST_EXIT_CODE -eq 0 ]; then TEST_EXIT_CODE=$?
echo "Run succeeded, no failures occurred";
elif [ $TEST_EXIT_CODE -eq 2 ]; then # Print player log output
echo "Run succeeded, some tests failed"; cat "$FULL_ARTIFACTS_PATH/$platform-player.log"
elif [ $TEST_EXIT_CODE -eq 3 ]; then fi
echo "Run failure (other failure)";
else # Display results
echo "Unexpected exit code $TEST_EXIT_CODE"; if [ $TEST_EXIT_CODE -eq 0 ]; then
fi echo "Run succeeded, no failures occurred";
elif [ $TEST_EXIT_CODE -eq 2 ]; then
if [ $TEST_EXIT_CODE -ne 0 ]; then echo "Run succeeded, some tests failed";
TEST_RUNNER_EXIT_CODE=$TEST_EXIT_CODE elif [ $TEST_EXIT_CODE -eq 3 ]; then
fi echo "Run failure (other failure)";
else
echo "" echo "Unexpected exit code $TEST_EXIT_CODE";
echo "###########################" fi
echo "# $platform Results #"
echo "###########################" if [ $TEST_EXIT_CODE -ne 0 ]; then
echo "" TEST_RUNNER_EXIT_CODE=$TEST_EXIT_CODE
fi
if [[ "$platform" != "COMBINE_RESULTS" ]]; then
cat "$FULL_ARTIFACTS_PATH/$platform-results.xml" echo ""
cat "$FULL_ARTIFACTS_PATH/$platform-results.xml" | grep test-run | grep Passed echo "###########################"
fi echo "# $platform Results #"
done echo "###########################"
echo ""
#
# Permissions if [[ "$platform" != "COMBINE_RESULTS" ]]; then
# cat "$FULL_ARTIFACTS_PATH/$platform-results.xml"
cat "$FULL_ARTIFACTS_PATH/$platform-results.xml" | grep test-run | grep Passed
# Make a given user owner of all artifacts fi
if [[ -n "$CHOWN_FILES_TO" ]]; then done
chown -R "$CHOWN_FILES_TO" "$UNITY_PROJECT_PATH"
chown -R "$CHOWN_FILES_TO" "$FULL_ARTIFACTS_PATH" #
chown -R "$CHOWN_FILES_TO" "$FULL_COVERAGE_RESULTS_PATH" # Permissions
fi #
# Add read permissions for everyone to all artifacts # Make a given user owner of all artifacts
chmod -R a+r "$UNITY_PROJECT_PATH" if [[ -n "$CHOWN_FILES_TO" ]]; then
chmod -R a+r "$FULL_ARTIFACTS_PATH" chown -R "$CHOWN_FILES_TO" "$UNITY_PROJECT_PATH"
chmod -R a+r "$FULL_COVERAGE_RESULTS_PATH" chown -R "$CHOWN_FILES_TO" "$FULL_ARTIFACTS_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"