mirror of
https://github.com/game-ci/unity-actions.git
synced 2026-01-29 04:39:07 +08:00
Refactor test runner to activate and run
This commit is contained in:
14
.github/workflows/main.yml
vendored
14
.github/workflows/main.yml
vendored
@@ -23,3 +23,17 @@ jobs:
|
||||
env:
|
||||
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
||||
|
||||
# Configure test runner
|
||||
- name: Run tests
|
||||
uses: ./test-runner
|
||||
env:
|
||||
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
||||
UNITY_PROJECT: sample-project
|
||||
TEST_PLATFORM: playmode # [ playmode | editmode ]
|
||||
|
||||
# Upload artifact
|
||||
- name: Expose as artifact
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: test results
|
||||
path: sample-project/playmode-results.xml
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
FROM gableroux/unity3d:2019.2.11f1-webgl
|
||||
FROM gableroux/unity3d:2019.2.11f1
|
||||
|
||||
LABEL "com.github.actions.name"="Unity project test"
|
||||
LABEL "com.github.actions.description"="Test unity project"
|
||||
LABEL "com.github.actions.name"="Test runner"
|
||||
LABEL "com.github.actions.description"="Test a Unity project"
|
||||
LABEL "com.github.actions.icon"="box"
|
||||
LABEL "com.github.actions.color"="gray-dark"
|
||||
|
||||
5
test-runner/action.yml
Normal file
5
test-runner/action.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
name: 'Test runner'
|
||||
description: 'Run Unity tests for a project'
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
59
test-runner/entrypoint.sh
Normal file
59
test-runner/entrypoint.sh
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Set the license file path
|
||||
LICENSE_FILE_PATH=UnityLicenseFile.ulf
|
||||
UNITY_PROJECT_PATH=$GITHUB_WORKSPACE/$UNITY_PROJECT
|
||||
|
||||
# Copy license file from Github variables
|
||||
echo "$UNITY_LICENSE" | tr -d '\r' > $LICENSE_FILE_PATH
|
||||
echo "$UNITY_LICENSE" | tr -d '\r' > /root/.local/share/unity3d/Unity/Unity_lic.ulf
|
||||
# TODO - test if this line has any effect
|
||||
echo "$UNITY_LICENSE" | tr -d '\r' > /root/.local/share/unity3d/Unity/Unity_v2019.x.ulf
|
||||
|
||||
##
|
||||
## Activate license
|
||||
##
|
||||
echo "Requesting activation"
|
||||
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||
/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 project for $TEST_PLATFORM"
|
||||
echo "Using path: $UNITY_PROJECT_PATH"
|
||||
ls -alh $UNITY_PROJECT_PATH
|
||||
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||
/opt/Unity/Editor/Unity \
|
||||
-batchmode \
|
||||
-nographics \
|
||||
-logFile /dev/stdout \
|
||||
-runEditorTests "$UNITY_PROJECT_PATH" \
|
||||
-editorTestsResultFile "$UNITY_PROJECT_PATH/$TEST_PLATFORM-results.xml"
|
||||
# -projectPath "$GITHUB_WORKSPACE" \
|
||||
# -testPlatform $TEST_PLATFORM \
|
||||
# -testResults "$GITHUB_WORKSPACE/$TEST_PLATFORM-results.xml" \
|
||||
# -runTests
|
||||
|
||||
UNITY_EXIT_CODE=$?
|
||||
|
||||
if [ $UNITY_EXIT_CODE -eq 0 ]; then
|
||||
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
|
||||
|
||||
echo "Results: "
|
||||
cat $GITHUB_WORKSPACE/$TEST_PLATFORM-results.xml
|
||||
cat $GITHUB_WORKSPACE/$TEST_PLATFORM-results.xml | grep test-run | grep Passed
|
||||
exit $UNITY_EXIT_CODE
|
||||
@@ -1,57 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
echo "$UNITY_LICENSE" > /root/.local/share/unity3d/Unity/Unity_lic.ulf
|
||||
echo "$UNITY_LICENSE" > /root/.local/share/unity3d/Unity/Unity_v2019.2.11f1.ulf
|
||||
echo "$UNITY_LICENSE" > Unity_v2019.2.11f1.ulf
|
||||
|
||||
cat /root/.local/share/unity3d/Unity/Unity_lic.ulf
|
||||
|
||||
set -x
|
||||
|
||||
# Activate container
|
||||
# See: https://docs.unity3d.com/Manual/CommandLineArguments.html
|
||||
echo "Activating container"
|
||||
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||
/opt/Unity/Editor/Unity \
|
||||
-batchmode \
|
||||
-nographics \
|
||||
-logFile /dev/stdout \
|
||||
-manualLicenseFile Unity_v2019.2.11f1.ulf \
|
||||
-quit
|
||||
|
||||
echo "Testing project for $TEST_PLATFORM"
|
||||
echo "Using path: $GITHUB_WORKSPACE"
|
||||
ls -alh $GITHUB_WORKSPACE
|
||||
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||
/opt/Unity/Editor/Unity \
|
||||
-batchmode \
|
||||
-nographics \
|
||||
-logFile /dev/stdout \
|
||||
-runEditorTests "$GITHUB_WORKSPACE" \
|
||||
-editorTestsResultFile "$GITHUB_WORKSPACE/$TEST_PLATFORM-results.xml"
|
||||
# -projectPath "$GITHUB_WORKSPACE" \
|
||||
# -testPlatform $TEST_PLATFORM \
|
||||
# -testResults "$GITHUB_WORKSPACE/$TEST_PLATFORM-results.xml" \
|
||||
# -runTests
|
||||
|
||||
# TODO - remove exit 0 here
|
||||
exit 0
|
||||
|
||||
UNITY_EXIT_CODE=$?
|
||||
|
||||
if [ $UNITY_EXIT_CODE -eq 0 ]; then
|
||||
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
|
||||
|
||||
echo "Results: "
|
||||
cat $GITHUB_WORKSPACE/$TEST_PLATFORM-results.xml
|
||||
cat $GITHUB_WORKSPACE/$TEST_PLATFORM-results.xml | grep test-run | grep Passed
|
||||
exit $UNITY_EXIT_CODE
|
||||
Reference in New Issue
Block a user