diff --git a/.github/workflows/create-unitypackage.yml b/.github/workflows/create-unitypackage.yml index 6a135dec00..04d5ac1e2a 100644 --- a/.github/workflows/create-unitypackage.yml +++ b/.github/workflows/create-unitypackage.yml @@ -2,6 +2,9 @@ name: Create UnityPackage on: workflow_dispatch: + push: + branches: + - workflow-wip env: UNITY_PROJECT_PATH: . @@ -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." @@ -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 + + diff --git a/Assets/UniGLTF/Editor/TestRunner.meta b/Assets/UniGLTF/Editor/TestRunner.meta new file mode 100644 index 0000000000..71abf6fecf --- /dev/null +++ b/Assets/UniGLTF/Editor/TestRunner.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: aa6bba67bdf924544955525c74d8c99a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Editor/TestRunner/TestRunner.cs b/Assets/UniGLTF/Editor/TestRunner/TestRunner.cs new file mode 100644 index 0000000000..1885bf5c9f --- /dev/null +++ b/Assets/UniGLTF/Editor/TestRunner/TestRunner.cs @@ -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.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); + } + } + + 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}"); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Editor/TestRunner/TestRunner.cs.meta b/Assets/UniGLTF/Editor/TestRunner/TestRunner.cs.meta new file mode 100644 index 0000000000..5032c25f4f --- /dev/null +++ b/Assets/UniGLTF/Editor/TestRunner/TestRunner.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 124e86211e5ad3f418dfeccf07c16b4d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Editor/TopMenu.cs b/Assets/UniGLTF/Editor/TopMenu.cs index cb98950bfc..f5e4e9cdfd 100644 --- a/Assets/UniGLTF/Editor/TopMenu.cs +++ b/Assets/UniGLTF/Editor/TopMenu.cs @@ -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)