Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create UnityPackage Action でとりあえず EditMode Tests まで走らせる #2271

Merged
merged 15 commits into from
Mar 27, 2024
55 changes: 34 additions & 21 deletions .github/workflows/create-unitypackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Create UnityPackage

on:
workflow_dispatch:
push:
branches:
- workflow-wip

env:
UNITY_PROJECT_PATH: .
Expand All @@ -24,23 +27,19 @@ jobs:
needs: checkout
runs-on: [self-hosted, Windows, X64, Unity]
outputs:
unity-editor-executable: ${{ steps.unity-editor-installation-check.outputs.unity-editor-executable }}
unity-editor-executable: ${{ steps.detect-unity-version.outputs.unity-editor-executable }}
steps:
- id: get-project-unity-version
- name: Detect Unity Version
id: detect-unity-version
run: |
PROJECT_VERSION_PATH="${UNITY_PROJECT_PATH}/ProjectSettings/ProjectVersion.txt"

UNITY_VERSION_RAW=`cat ${PROJECT_VERSION_PATH} | yq .m_EditorVersionWithRevision`
UNITY_VERSION=`echo ${UNITY_VERSION_RAW} | sed -E "s/^(\S+)\s+\((\S+)\)$/\1/"`
UNITY_CHANGESET=`echo ${UNITY_VERSION_RAW} | sed -E "s/^(\S+)\s+\((\S+)\)$/\2/"`

- id: unity-editor-installation-check
run: |
UNITY_HUB="C:\Program Files\Unity Hub\Unity Hub.exe"

UNITY_VERSION=`cat ${PROJECT_VERSION_PATH} | sed -n -E "s/^m_EditorVersion:\s+//p" | head -n 1`
UNITY_CHANGESET=`cat ${PROJECT_VERSION_PATH} | sed -n -E "s/^m_EditorVersionWithRevision:\s+\S+\s+\((\S+)\)/\1/p" | head -n 1`
UNITY_EDITOR_EXECUTABLE=`"${UNITY_HUB}" -- --headless editors --installed | \
sed -n -e "s/^${UNITY_VERSION} , installed at //p" | \
head`
sed -n -E "s/^${UNITY_VERSION} , installed at //p" | \
head -n 1`

if [ -z "${UNITY_EDITOR_EXECUTABLE}" ]; then
echo "Unity ${UNITY_VERSION} is not installed."
Expand All @@ -54,24 +53,38 @@ jobs:
--childModules"
fi

echo "unity-editor-executable=\"${UNITY_EDITOR_EXECUTABLE}\"" >> "${GITHUB_OUTPUT}"
echo "unity-editor-executable=${UNITY_EDITOR_EXECUTABLE}" >> "${GITHUB_OUTPUT}"

run-editor-tests:
run-edit-mode-tests:
needs: detect-unity-version
runs-on: [self-hosted, Windows, X64, Unity]
steps:
- id: run
- name: Run EditMode Tests
id: run-edit-mode-tests
run: |
echo "Run EditMode Tests..."
# RunEditModeTests の実行の結果、終了コードが 0 でない場合でもテストの結果を表示したいので set +e して一時的に回避する
set +e
"${{ needs.detect-unity-version.outputs.unity-editor-executable }}" \
-quit \
-batchmode \
-nographics \
-silent-crashes \
-logFile \
-projectPath "${UNITY_PROJECT_PATH}" \
-runEditorTests \
-editorTestsResultFile "${UNITY_PROJECT_PATH}/EditorTestResults.xml"

cat "${UNITY_PROJECT_PATH}/EditorTestResults.xml"
-executeMethod "UniGLTF.TestRunner.RunEditModeTests" \
-logFile output.log
RET=$?
set -e

echo "Output Log..."
cat output.log | egrep "^\[\[TestRunnerLog\]\]"

if [ ${RET:-1} -eq 0 ]; then
echo "Test succeeded."
exit 0
else
echo "Test failed."
exit 1
fi




8 changes: 8 additions & 0 deletions Assets/UniGLTF/Editor/TestRunner.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions Assets/UniGLTF/Editor/TestRunner/TestRunner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

using UnityEditor;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine;

namespace UniGLTF
{
public static class TestRunner
{
public static void RunEditModeTests()
{
var testRunnerApi = ScriptableObject.CreateInstance<TestRunnerApi>();
testRunnerApi.RegisterCallbacks(new TestCallback());
testRunnerApi.Execute(new ExecutionSettings(new Filter
{
testMode = TestMode.EditMode,
}));
}

private class TestCallback : ICallbacks
{
private static readonly string LogPrefix = $"[[TestRunnerLog]] ";
private static readonly string ResultLogPrefix = $"[[TestRunnerResult]] ";
private StackTraceLogType _tmpStackTraceLogType;

public void RunStarted(ITestAdaptor testsToRun)
{
_tmpStackTraceLogType = Application.GetStackTraceLogType(LogType.Log);
Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);

Debug.Log($"{LogPrefix}Edit Mode Tests Started.");
}

public void RunFinished(ITestResultAdaptor result)
{
Debug.Log($"{LogPrefix}Passed: {result.PassCount}, Skipped: {result.SkipCount}, Failed: {result.FailCount}");
Debug.Log($"{ResultLogPrefix}{result.FailCount}");

Application.SetStackTraceLogType(LogType.Log, _tmpStackTraceLogType);

if (Application.isBatchMode)
{
EditorApplication.Exit(result.FailCount > 0 ? 1 : 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

batchMode 起動のときに fail したテストがあったら終了コード 1 を返す

}
}

public void TestStarted(ITestAdaptor test)
{
}

public void TestFinished(ITestResultAdaptor result)
{
if (result.HasChildren) return;

if (result.TestStatus != TestStatus.Passed)
{
Debug.Log($"{LogPrefix}{result.Message}");
Debug.Log($"{LogPrefix}{result.StackTrace}");
}
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/UniGLTF/Editor/TestRunner/TestRunner.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions Assets/UniGLTF/Editor/TopMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ private static void ShowVersion() { }
private static void OpenMeshProcessingWindow() => MeshUtility.MeshUtilityDialog.OpenWindow();

#if VRM_DEVELOP
[MenuItem(DevelopmentMenuPrefix + "/Generate Serialization Code", priority = 51)]
[MenuItem(DevelopmentMenuPrefix + "/Run EditMode Tests", priority = 51)]
private static void RunEditModeTests() => TestRunner.RunEditModeTests();

[MenuItem(DevelopmentMenuPrefix + "/Generate Serialization Code", priority = 61)]
private static void GenerateSerializationCode()
{
SerializerGenerator.GenerateSerializer();
DeserializerGenerator.GenerateSerializer();
}

[MenuItem(DevelopmentMenuPrefix + "/Generate UniJSON ConcreteCast", priority = 52)]
[MenuItem(DevelopmentMenuPrefix + "/Generate UniJSON ConcreteCast", priority = 62)]
private static void GenerateUniJsonConcreteCastCode() => UniJSON.ConcreteCast.GenerateGenericCast();

[MenuItem("GameObject/CheckPrefabType", false, 53)]
[MenuItem("Assets/CheckPrefabType", false, 53)]
[MenuItem("GameObject/CheckPrefabType", false, 63)]
[MenuItem("Assets/CheckPrefabType", false, 64)]
private static void CheckPrefabType()
{
if (Selection.activeObject is GameObject go)
Expand Down