Build via Script.

This commit is contained in:
2026-11-24 19:10:46 +01:00
parent c322dbf9c1
commit bb90a7a2c8
2 changed files with 64 additions and 10 deletions
+10 -10
View File
@@ -27,16 +27,15 @@ jobs:
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Build Unity Player (${{ matrix.platform }}) - name: Build Unity Player (${{ matrix.platform }})
env:
UNITY_BUILD_OUTPUT_PATH: "${{ github.workspace }}/Builds/${{ matrix.platform }}/${{ matrix.output_file }}"
run: | run: |
set -e set -e
REPO_ROOT="$(pwd)" REPO_ROOT="$(pwd)"
PROJECT_PATH="${REPO_ROOT}/${UNITY_PROJECT_SUBDIR}" PROJECT_PATH="${REPO_ROOT}/${UNITY_PROJECT_SUBDIR}"
BUILD_DIR="${REPO_ROOT}/Builds/${{ matrix.platform }}" BUILD_DIR="${REPO_ROOT}/Builds/${{ matrix.platform }}"
LOG_FILE="${BUILD_DIR}/build-${{ matrix.platform }}.log"
echo "REPO_ROOT: $REPO_ROOT"
echo "PROJECT_PATH: $PROJECT_PATH"
echo "BUILD_DIR: $BUILD_DIR"
mkdir -p "$BUILD_DIR" mkdir -p "$BUILD_DIR"
"$UNITY_EDITOR_PATH" \ "$UNITY_EDITOR_PATH" \
@@ -44,17 +43,18 @@ jobs:
-quit \ -quit \
-projectPath "$PROJECT_PATH" \ -projectPath "$PROJECT_PATH" \
-buildTarget "${{ matrix.build_target }}" \ -buildTarget "${{ matrix.build_target }}" \
-customBuildPath "$BUILD_DIR/${{ matrix.output_file }}" \ -customBuildPath "$UNITY_BUILD_OUTPUT_PATH" \
-logFile "Builds/unity-${{ matrix.platform }}.log" -executeMethod CommandLineBuild.BuildFromCli \
-logFile "$LOG_FILE"
- name: Print Unity Logs on Failure - name: Print Unity Logs on Failure
if: failure() if: failure()
run: | run: |
echo "=== Custom Log ===" echo "=== Build Log ==="
cat "Builds/${{ matrix.platform }}/unity-build.log" 2>/dev/null || echo "Kein Custom-Log vorhanden" cat "Builds/${{ matrix.platform }}/build-${{ matrix.platform }}.log" 2>/dev/null || echo "Kein Build-Log vorhanden"
echo "=== Unity Editor.log ===" echo "=== Unity Editor.log ==="
tail -n 150 "$HOME/.config/unity3d/Unity/Editor.log" 2>/dev/null || echo "Kein Editor.log vorhanden" tail -n 150 "$HOME/.config/unity3d/Unity/Editor.log" 2>/dev/null || echo "Kein Editor.log vorhanden"
- name: Fix macOS Executable Permissions - name: Fix macOS Executable Permissions
if: matrix.platform == 'macos' if: matrix.platform == 'macos'
run: | run: |
@@ -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);
}
}
}