diff --git a/.gitea/workflows/build-game.yml b/.gitea/workflows/build-game.yml index b8bf0a4f..2d96b87a 100644 --- a/.gitea/workflows/build-game.yml +++ b/.gitea/workflows/build-game.yml @@ -27,16 +27,15 @@ jobs: uses: actions/checkout@v4 - name: Build Unity Player (${{ matrix.platform }}) + env: + UNITY_BUILD_OUTPUT_PATH: "${{ github.workspace }}/Builds/${{ matrix.platform }}/${{ matrix.output_file }}" run: | set -e REPO_ROOT="$(pwd)" PROJECT_PATH="${REPO_ROOT}/${UNITY_PROJECT_SUBDIR}" BUILD_DIR="${REPO_ROOT}/Builds/${{ matrix.platform }}" - - echo "REPO_ROOT: $REPO_ROOT" - echo "PROJECT_PATH: $PROJECT_PATH" - echo "BUILD_DIR: $BUILD_DIR" - + LOG_FILE="${BUILD_DIR}/build-${{ matrix.platform }}.log" + mkdir -p "$BUILD_DIR" "$UNITY_EDITOR_PATH" \ @@ -44,17 +43,18 @@ jobs: -quit \ -projectPath "$PROJECT_PATH" \ -buildTarget "${{ matrix.build_target }}" \ - -customBuildPath "$BUILD_DIR/${{ matrix.output_file }}" \ - -logFile "Builds/unity-${{ matrix.platform }}.log" + -customBuildPath "$UNITY_BUILD_OUTPUT_PATH" \ + -executeMethod CommandLineBuild.BuildFromCli \ + -logFile "$LOG_FILE" - name: Print Unity Logs on Failure if: failure() run: | - echo "=== Custom Log ===" - cat "Builds/${{ matrix.platform }}/unity-build.log" 2>/dev/null || echo "Kein Custom-Log vorhanden" + echo "=== Build Log ===" + cat "Builds/${{ matrix.platform }}/build-${{ matrix.platform }}.log" 2>/dev/null || echo "Kein Build-Log vorhanden" echo "=== Unity Editor.log ===" tail -n 150 "$HOME/.config/unity3d/Unity/Editor.log" 2>/dev/null || echo "Kein Editor.log vorhanden" - + - name: Fix macOS Executable Permissions if: matrix.platform == 'macos' run: | diff --git a/My project/Assets/Editor/CommandLineBuild.cs b/My project/Assets/Editor/CommandLineBuild.cs new file mode 100644 index 00000000..26831038 --- /dev/null +++ b/My project/Assets/Editor/CommandLineBuild.cs @@ -0,0 +1,54 @@ +using System; +using System.Linq; +using UnityEditor; +using UnityEditor.Build.Reporting; +using UnityEngine; + +public static class CommandLineBuild +{ + public static void BuildFromCli() + { + string buildPath = Environment.GetEnvironmentVariable("UNITY_BUILD_OUTPUT_PATH"); + if (string.IsNullOrWhiteSpace(buildPath)) + { + string[] args = Environment.GetCommandLineArgs(); + int idx = Array.IndexOf(args, "-customBuildPath"); + if (idx >= 0 && idx + 1 < args.Length) + { + buildPath = args[idx + 1]; + } + } + + if (string.IsNullOrWhiteSpace(buildPath)) + { + Debug.LogError("Kein Build-Ausgabepfad angegeben."); + EditorApplication.Exit(1); + return; + } + + string[] scenes = EditorBuildSettings.scenes + .Where(s => s.enabled) + .Select(s => s.path) + .ToArray(); + + if (scenes.Length == 0) + { + Debug.LogError("Keine aktivierten Szenen in Build Settings gefunden!"); + EditorApplication.Exit(1); + return; + } + + BuildReport report = BuildPipeline.BuildPlayer( + scenes, + buildPath, + EditorUserBuildSettings.activeBuildTarget, + BuildOptions.None + ); + + if (report.summary.result != BuildResult.Succeeded) + { + Debug.LogError($"Build fehlgeschlagen: {report.summary.result}"); + EditorApplication.Exit(1); + } + } +} \ No newline at end of file