Test playmode, editmode and all modes

This commit is contained in:
Webber
2019-11-28 00:07:17 +01:00
committed by Webber Takken
parent c71997dc22
commit 0a693aa053
3 changed files with 216 additions and 139 deletions

View File

@@ -1,18 +1,31 @@
name: Workflow Actions name: Happy flow
on: [push] on: [push]
jobs: jobs:
testWorkflowActions: requestManualActivationFile:
runs-on: ubuntu-latest
name: Request manual activation file
steps:
# Checkout repository (required to test local actions)
- name: Checkout repository
uses: actions/checkout@v1
# Configure request manual activation file action
- name: Request manual activation file
uses: ./request-manual-activation-file
id: getManualLicenseFile
# Upload artifact
- name: Expose as artifact
uses: actions/upload-artifact@v1
with:
name: ${{ steps.getManualLicenseFile.outputs.filePath }}
path: ${{ steps.getManualLicenseFile.outputs.filePath }}
requestActivation:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Test the workflow actions name: Test the workflow actions
# Set Unity version
strategy:
matrix:
unity-tag: [2019.2.11f1] # TODO - Reference this tag in all steps
steps: steps:
# Checkout repository (required to test local actions) # Checkout repository (required to test local actions)
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v1 uses: actions/checkout@v1
@@ -23,31 +36,75 @@ jobs:
env: env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
testRunnerInEditMode:
runs-on: ubuntu-latest
name: Test the workflow actions
steps:
# Checkout repository (required to test local actions)
- name: Checkout repository
uses: actions/checkout@v1
# Configure test runner # Configure test runner
- name: Run tests - name: Run tests
uses: ./test-runner uses: ./test-runner
env: env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_PROJECT: sample-project UNITY_PROJECT: unity-project-with-correct-tests
TEST_PLATFORM: playmode # [ playmode | editmode ] TEST_MODE: editmode
# Upload artifact # Upload artifact
- name: Expose as artifact - name: Expose as artifact
uses: actions/upload-artifact@v1 uses: actions/upload-artifact@v1
with: with:
name: 2019.2 test results name: Test results (edit mode)
path: sample-project/old-results.xml path: artifacts/unity-project-with-correct-tests/editmode-results.xml
# TODO - Verify that playmode-results does not exist
testRunnerInPlayMode:
runs-on: ubuntu-latest
name: Test the workflow actions
steps:
# Checkout repository (required to test local actions)
- name: Checkout repository
uses: actions/checkout@v1
# Configure test runner
- name: Run tests
uses: ./test-runner
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_PROJECT: unity-project-with-correct-tests
TEST_MODE: playmode
# Upload artifact # Upload artifact
- name: Expose as artifact - name: Expose as artifact
uses: actions/upload-artifact@v1 uses: actions/upload-artifact@v1
with: with:
name: 2019.3 edit mode results name: Test results (play mode)
path: sample-project/editmode-results.xml path: artifacts/unity-project-with-correct-tests/playmode-results.xml
# Upload artifact # TODO - Verify that editmode-results does not exist
testRunnerInAllModes:
runs-on: ubuntu-latest
name: Test the workflow actions
steps:
# Checkout repository (required to test local actions)
- name: Checkout repository
uses: actions/checkout@v1
# Configure test runner
- name: Run tests
uses: ./test-runner
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_PROJECT: unity-project-with-correct-tests
TEST_MODE: all
# Upload artifacts
- name: Expose as artifact - name: Expose as artifact
uses: actions/upload-artifact@v1 uses: actions/upload-artifact@v1
with: with:
name: 2019.3 play mode results name: Test results (all modes)
path: sample-project/playmode-results.xml path: artifacts/unity-project-with-correct-tests/

View File

@@ -1,30 +0,0 @@
name: Request manual activation file
on: [push]
jobs:
requestManualActivationFile:
runs-on: ubuntu-latest
name: Request manual activation file
# Set Unity version
strategy:
matrix:
unity-tag: [2019.2.11f1] # TODO - Reference this tag in all steps
steps:
# Checkout repository (required to test local actions)
- name: Checkout repository
uses: actions/checkout@v1
# Configure request manual activation file action
- name: Request manual activation file
uses: ./request-manual-activation-file
id: getManualLicenseFile
# Upload artifact
- name: Expose as artifact
uses: actions/upload-artifact@v1
with:
name: ${{ steps.getManualLicenseFile.outputs.filePath }}
path: ${{ steps.getManualLicenseFile.outputs.filePath }}

View File

@@ -1,129 +1,179 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Set the license file path # Set the license file path
LICENSE_FILE_PATH=UnityLicenseFile.ulf LICENSE_FILE_PATH=UnityLicenseFile.ulf
UNITY_PROJECT_PATH=$GITHUB_WORKSPACE/$UNITY_PROJECT UNITY_PROJECT_PATH=$GITHUB_WORKSPACE/$UNITY_PROJECT
TEST_ARTIFACTS_PATH=$GITHUB_WORKSPACE/artifacts/$UNITY_PROJECT
# Copy license file from Github variables # Set the modes for testing
echo "$UNITY_LICENSE" | tr -d '\r' > $LICENSE_FILE_PATH case $TEST_MODE in
echo "$UNITY_LICENSE" | tr -d '\r' > /root/.local/share/unity3d/Unity/Unity_lic.ulf editmode)
# TODO - test if this line has any effect echo "Edit mode selected for testing."
echo "$UNITY_LICENSE" | tr -d '\r' > /root/.local/share/unity3d/Unity/Unity_v2019.x.ulf EDIT_MODE=true
;;
playmode)
echo "Play mode selected for testing."
PLAY_MODE=true
;;
*)
echo "All modes selected for testing."
EDIT_MODE=true
PLAY_MODE=true
;;
esac
## # Copy license file from Github variables
## Activate license echo "$UNITY_LICENSE" | tr -d '\r' > $LICENSE_FILE_PATH
## echo "$UNITY_LICENSE" | tr -d '\r' > /root/.local/share/unity3d/Unity/Unity_lic.ulf
echo "Requesting activation" # TODO - test if this line has any effect
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \ echo "$UNITY_LICENSE" | tr -d '\r' > /root/.local/share/unity3d/Unity/Unity_v2019.x.ulf
/opt/Unity/Editor/Unity \
-batchmode \
-nographics \
-logFile /dev/stdout \
-quit \
-manualLicenseFile $LICENSE_FILE_PATH
# This is expected to always exit with code 1 (both success and failure).
# Convert to exit code 0 by echoing the current exit code.
echo $?
# Exit code is now 0
echo "Testing the 2019.2 way" ##
# Reference: https://docs.unity3d.com/2019.2/Documentation/Manual/CommandLineArguments.html ## Activate license
echo "Using path: $UNITY_PROJECT_PATH" ##
ls -alh $UNITY_PROJECT_PATH echo "Requesting activation"
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \ xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
/opt/Unity/Editor/Unity \ /opt/Unity/Editor/Unity \
-batchmode \ -batchmode \
-logfile /dev/stdout \ -nographics \
-runEditorTests "$UNITY_PROJECT_PATH" \ -logFile /dev/stdout \
-editorTestsResultFile "$UNITY_PROJECT_PATH/old-results.xml" -quit \
-manualLicenseFile $LICENSE_FILE_PATH
# This is expected to always exit with code 1 (both success and failure).
# Convert to exit code 0 by echoing the current exit code.
echo $?
# Exit code is now 0
UNITY_EXIT_CODE=$?
if [ $UNITY_EXIT_CODE -eq 0 ]; then # The following tests are 2019 mode (requires Unity 2019.2.11f1 or later)
echo "Run succeeded, no failures occurred";
elif [ $UNITY_EXIT_CODE -eq 2 ]; then
echo "Run succeeded, some tests failed";
elif [ $UNITY_EXIT_CODE -eq 3 ]; then
echo "Run failure (other failure)";
else
echo "Unexpected exit code $UNITY_EXIT_CODE";
fi
# Test 2019.3 mode
# Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html # Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html
# #
# EditMode # Overall info
# #
echo ""
echo "###########################"
echo "# Artifacts folder #"
echo "###########################"
echo ""
echo "Creating \"$TEST_ARTIFACTS_PATH\" if it does not exist."
mkdir -p $TEST_ARTIFACTS_PATH
echo ""
echo "###########################"
echo "# Project directory #"
echo "###########################"
echo ""
ls -alh $UNITY_PROJECT_PATH ls -alh $UNITY_PROJECT_PATH
echo "Testing the 2019.3 way (editmode)"
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
/opt/Unity/Editor/Unity \
-batchmode \
-logfile /dev/stdout \
-projectPath "$UNITY_PROJECT_PATH" \
-runTests \
-testPlatform editmode \
-testResults "$UNITY_PROJECT_PATH/editmode-results.xml"
UNITY_EXIT_CODE=$? #
# Testing in EditMode
#
if [ $UNITY_EXIT_CODE -eq 0 ]; then if [ $EDIT_MODE = true ]; then
echo "Run succeeded, no failures occurred"; echo ""
elif [ $UNITY_EXIT_CODE -eq 2 ]; then echo "###########################"
echo "Run succeeded, some tests failed"; echo "# Testing in EditMode #"
elif [ $UNITY_EXIT_CODE -eq 3 ]; then echo "###########################"
echo "Run failure (other failure)"; echo ""
else xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
echo "Unexpected exit code $UNITY_EXIT_CODE"; /opt/Unity/Editor/Unity \
-batchmode \
-logfile /dev/stdout \
-projectPath "$UNITY_PROJECT_PATH" \
-runTests \
-testPlatform editmode \
-testResults "$TEST_ARTIFACTS_PATH/editmode-results.xml"
# Catch exit code
EDIT_MODE_EXIT_CODE=$?
# Display results
if [ $EDIT_MODE_EXIT_CODE -eq 0 ]; then
echo "Run succeeded, no failures occurred";
elif [ $EDIT_MODE_EXIT_CODE -eq 2 ]; then
echo "Run succeeded, some tests failed";
elif [ $EDIT_MODE_EXIT_CODE -eq 3 ]; then
echo "Run failure (other failure)";
else
echo "Unexpected exit code $EDIT_MODE_EXIT_CODE";
fi
fi fi
# #
# PlayMode # Testing in PlayMode
# #
ls -alh $UNITY_PROJECT_PATH if [ $PLAY_MODE = true ]; then
echo "Testing the 2019.3 way (playmode)" echo ""
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \ echo "###########################"
/opt/Unity/Editor/Unity \ echo "# Testing in PlayMode #"
-batchmode \ echo "###########################"
-logfile /dev/stdout \ echo ""
-projectPath "$UNITY_PROJECT_PATH" \ xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
-runTests \ /opt/Unity/Editor/Unity \
-testPlatform playmode \ -batchmode \
-testResults "$UNITY_PROJECT_PATH/playmode-results.xml" -logfile /dev/stdout \
-projectPath "$UNITY_PROJECT_PATH" \
-runTests \
-testPlatform playmode \
-testResults "$TEST_ARTIFACTS_PATH/playmode-results.xml"
UNITY_EXIT_CODE=$? # Catch exit code
PLAY_MODE_EXIT_CODE=$?
if [ $UNITY_EXIT_CODE -eq 0 ]; then # Display results
echo "Run succeeded, no failures occurred"; if [ $PLAY_MODE_EXIT_CODE -eq 0 ]; then
elif [ $UNITY_EXIT_CODE -eq 2 ]; then echo "Run succeeded, no failures occurred";
echo "Run succeeded, some tests failed"; elif [ $PLAY_MODE_EXIT_CODE -eq 2 ]; then
elif [ $UNITY_EXIT_CODE -eq 3 ]; then echo "Run succeeded, some tests failed";
echo "Run failure (other failure)"; elif [ $PLAY_MODE_EXIT_CODE -eq 3 ]; then
else echo "Run failure (other failure)";
echo "Unexpected exit code $UNITY_EXIT_CODE"; else
echo "Unexpected exit code $PLAY_MODE_EXIT_CODE";
fi
fi fi
# #
# Results # Results
# #
echo ""
echo "###########################"
echo "# Project directory #"
echo "###########################"
echo ""
ls -alh $UNITY_PROJECT_PATH ls -alh $UNITY_PROJECT_PATH
echo "Results:" if [ $EDIT_MODE = true ]; then
cat "$UNITY_PROJECT_PATH/$TEST_PLATFORM-results.xml" echo ""
cat "$UNITY_PROJECT_PATH/$TEST_PLATFORM-results.xml" | grep test-run | grep Passed echo "###########################"
echo "\n\nEditMode Results\n\n" echo "# Edit Mode Results #"
cat "$UNITY_PROJECT_PATH/editmode-results.xml" echo "###########################"
cat "$UNITY_PROJECT_PATH/editmode-results.xml" | grep test-run | grep Passed echo ""
echo "\n\nPlayMode Results\n\n" cat "$TEST_ARTIFACTS_PATH/editmode-results.xml"
cat "$UNITY_PROJECT_PATH/playmode-results.xml" cat "$TEST_ARTIFACTS_PATH/editmode-results.xml" | grep test-run | grep Passed
cat "$UNITY_PROJECT_PATH/playmode-results.xml" | grep test-run | grep Passed fi
if [ $PLAY_MODE = true ]; then
echo ""
echo "###########################"
echo "# Edit Mode Results #"
echo "###########################"
echo ""
cat "$TEST_ARTIFACTS_PATH/playmode-results.xml"
cat "$TEST_ARTIFACTS_PATH/playmode-results.xml" | grep test-run | grep Passed
fi
# #
# Exit # Exit
# #
exit $UNITY_EXIT_CODE if [ $EDIT_MODE_EXIT_CODE -gt 0 ]; then
exit $EDIT_MODE_EXIT_CODE
fi
if [ $PLAY_MODE_EXIT_CODE -gt 0 ]; then
exit $PLAY_MODE_EXIT_CODE
fi