From a4c0994046ed5556466f239ab96535cb9bc72f76 Mon Sep 17 00:00:00 2001 From: Webber Date: Tue, 26 Nov 2019 08:29:27 +0100 Subject: [PATCH] Refactor test runner to activate and run --- .github/workflows/main.yml | 14 ++++++++ {test => test-runner}/Dockerfile | 6 ++-- test-runner/action.yml | 5 +++ test-runner/entrypoint.sh | 59 ++++++++++++++++++++++++++++++++ test/entrypoint.sh | 57 ------------------------------ 5 files changed, 81 insertions(+), 60 deletions(-) rename {test => test-runner}/Dockerfile (70%) create mode 100644 test-runner/action.yml create mode 100644 test-runner/entrypoint.sh delete mode 100644 test/entrypoint.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ed8436b..7ae3832 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/test/Dockerfile b/test-runner/Dockerfile similarity index 70% rename from test/Dockerfile rename to test-runner/Dockerfile index 6b333c2..2ae0726 100644 --- a/test/Dockerfile +++ b/test-runner/Dockerfile @@ -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" diff --git a/test-runner/action.yml b/test-runner/action.yml new file mode 100644 index 0000000..2e4bc7b --- /dev/null +++ b/test-runner/action.yml @@ -0,0 +1,5 @@ +name: 'Test runner' +description: 'Run Unity tests for a project' +runs: + using: 'docker' + image: 'Dockerfile' diff --git a/test-runner/entrypoint.sh b/test-runner/entrypoint.sh new file mode 100644 index 0000000..4745636 --- /dev/null +++ b/test-runner/entrypoint.sh @@ -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 diff --git a/test/entrypoint.sh b/test/entrypoint.sh deleted file mode 100644 index 590d4de..0000000 --- a/test/entrypoint.sh +++ /dev/null @@ -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