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

This commit is contained in:
Masataka SUMI 2024-03-27 22:18:29 +09:00 committed by GitHub
parent 355552b1ee
commit 69c518caee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 123 additions and 25 deletions

View File

@ -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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aa6bba67bdf924544955525c74d8c99a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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);
}
}
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}");
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 124e86211e5ad3f418dfeccf07c16b4d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -31,18 +31,21 @@ namespace UniGLTF
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)