diff --git a/ci/Build-Mac.sh b/ci/Build-Mac.sh index adeb578..f906a4b 100644 --- a/ci/Build-Mac.sh +++ b/ci/Build-Mac.sh @@ -1,26 +1,84 @@ #!/bin/bash -set -e +set -euo pipefail -TARGET=$1 +TARGET="${1:-}" if [[ -z "$TARGET" ]]; then - echo "Missing TARGET (Mac or iOS)" + echo "ERROR: Missing TARGET (Mac or iOS)" exit 1 fi -echo "=== Mac Build Starting ===" -echo "Target: $TARGET" +echo "====================================" +echo " Unity CI Build (Mac Agent)" +echo " Target: $TARGET" +echo "====================================" -UNITY_VERSION="2022.3.62f1" +# ----------------------------- +# Load toolchain config +# ----------------------------- +CONFIG_FILE="./ci/toolchain.json" + +UNITY_VERSION=$(cat "$CONFIG_FILE" | python3 -c "import sys, json; print(json.load(sys.stdin)['unityVersion'])") UNITY_ROOT="/Applications/Unity/Hub/Editor" -UNITY_EXE="$UNITY_ROOT/$UNITY_VERSION/Unity.app/Contents/MacOS/Unity" -if [[ ! -f "$UNITY_EXE" ]]; then - echo "Unity not installed at $UNITY_EXE" - exit 1 +UNITY_APP="$UNITY_ROOT/$UNITY_VERSION/Unity.app/Contents/MacOS/Unity" + +HUB="/Applications/Unity Hub.app/Contents/MacOS/Unity Hub" + +# ----------------------------- +# Ensure Unity exists +# ----------------------------- +if [[ ! -f "$UNITY_APP" ]]; then + echo "Unity $UNITY_VERSION not found. Installing via Unity Hub..." + + "$HUB" -- --headless install \ + --version "$UNITY_VERSION" + + if [[ $? -ne 0 ]]; then + echo "ERROR: Failed to install Unity $UNITY_VERSION" + exit 1 + fi fi +echo "Unity found at: $UNITY_APP" + +# ----------------------------- +# Ensure required modules +# ----------------------------- +echo "Ensuring Unity modules..." + +MODULES=$(cat "$CONFIG_FILE" | python3 -c " +import sys, json +print(' '.join(json.load(sys.stdin)['mac']['modules'])) +") + +for module in $MODULES; do + + echo "Checking module: $module" + + INSTALLED=$("$HUB" -- --headless editors --installed || true) + + if echo "$INSTALLED" | grep -q "$UNITY_VERSION.*$module"; then + echo "Module already installed: $module" + else + echo "Installing module: $module" + + "$HUB" -- --headless install-modules \ + --version "$UNITY_VERSION" \ + --module "$module" + + if [[ $? -ne 0 ]]; then + echo "ERROR: Failed to install module $module" + exit 1 + fi + fi + +done + +# ----------------------------- +# Resolve Unity build method +# ----------------------------- case "$TARGET" in Mac) METHOD="BuildScript.Mac" @@ -29,17 +87,36 @@ case "$TARGET" in METHOD="BuildScript.iOS" ;; *) - echo "Unknown target: $TARGET" + echo "ERROR: Unknown target: $TARGET" exit 1 ;; esac -"$UNITY_EXE" \ +echo "Using Unity method: $METHOD" + +# ----------------------------- +# Run Unity build +# ----------------------------- +"$UNITY_APP" \ -batchmode \ -nographics \ -quit \ -projectPath "$(pwd)" \ - -executeMethod $METHOD \ - -logFile - + -executeMethod "$METHOD" \ + -logFile "build-$TARGET.log" -echo "=== Build SUCCESS: $TARGET ===" \ No newline at end of file +EXIT_CODE=$? + +# ----------------------------- +# Validate result +# ----------------------------- +if [[ $EXIT_CODE -ne 0 ]]; then + echo "====================================" + echo " BUILD FAILED: $TARGET" + echo "====================================" + exit $EXIT_CODE +fi + +echo "====================================" +echo " BUILD SUCCESS: $TARGET" +echo "====================================" \ No newline at end of file diff --git a/ci/Build-Windows.ps1 b/ci/Build-Windows.ps1 index 3d077e4..cec3f5a 100644 --- a/ci/Build-Windows.ps1 +++ b/ci/Build-Windows.ps1 @@ -4,50 +4,113 @@ param( [string]$Target ) -Write-Host "=== Windows Build Starting ===" -Write-Host "Target: $Target" +$ErrorActionPreference = "Stop" +Write-Host "====================================" +Write-Host " Unity CI Build (Windows Agent)" +Write-Host " Target: $Target" +Write-Host "====================================" + +# ----------------------------- +# Load toolchain config +# ----------------------------- $config = Get-Content ".\ci\toolchain.json" | ConvertFrom-Json $unityVersion = $config.unityVersion $unityRoot = $config.windows.unityRoot -$unityExe = Join-Path $unityRoot "$unityVersion\Editor\Unity.exe" +$hubExe = "${env:ProgramFiles}\Unity Hub\Unity Hub.exe" -if (!(Test-Path $unityExe)) { - throw "Unity not installed: $unityExe" +if (!(Test-Path $hubExe)) { + throw "Unity Hub not found at: $hubExe" } -# ---------------------------- -# Toolchain setup (Windows agent) -# ---------------------------- +# ----------------------------- +# Ensure Unity is installed +# ----------------------------- +$unityEditorPath = Join-Path $unityRoot "$unityVersion\Editor\Unity.exe" -Write-Host "Ensuring toolchain (Unity + Android SDK/JDK/NDK)..." +if (!(Test-Path $unityEditorPath)) { -# NOTE: In real setups you either: -# - rely on Unity Hub installs, OR -# - preinstalled cached toolchain -# This script assumes preinstalled Hub-managed tools. + Write-Host "Unity $unityVersion not found. Installing via Unity Hub..." -# ---------------------------- -# Select Unity method -# ---------------------------- + # Install Unity Editor + & $hubExe -- --headless install ` + --version $unityVersion ` + --changeset "" 2>$null + if ($LASTEXITCODE -ne 0) { + throw "Failed to install Unity $unityVersion" + } +} + +Write-Host "Unity found: $unityEditorPath" + +# ----------------------------- +# Ensure required modules +# ----------------------------- +# NOTE: +# Unity Hub CLI installs modules per version. +# These are cached per editor version, not reinstalled each build. + +$modules = $config.windows.modules + +Write-Host "Ensuring Unity modules: $($modules -join ', ')" + +foreach ($module in $modules) { + + Write-Host "Checking module: $module" + + # Check installed modules via Unity Hub + $installed = & $hubExe -- --headless editors --installed + + if ($installed -notmatch "$unityVersion.*$module") { + + Write-Host "Installing module: $module" + + & $hubExe -- --headless install-modules ` + --version $unityVersion ` + --module $module + + if ($LASTEXITCODE -ne 0) { + throw "Failed to install module: $module" + } + } + else { + Write-Host "Module already installed: $module" + } +} + +# ----------------------------- +# Resolve Unity build method +# ----------------------------- $method = switch ($Target) { "Windows" { "BuildScript.Windows" } "Android" { "BuildScript.Android" } } -& $unityExe ` +Write-Host "Using Unity method: $method" + +# ----------------------------- +# Run Unity build +# ----------------------------- +& $unityEditorPath ` -batchmode ` -nographics ` -quit ` -projectPath $PWD ` -executeMethod $method ` - -logFile - + -logFile build-$Target.log -if ($LASTEXITCODE -ne 0) { - throw "Build failed: $Target" +$exitCode = $LASTEXITCODE + +# ----------------------------- +# Validate result +# ----------------------------- +if ($exitCode -ne 0) { + throw "Unity build failed ($Target). Exit code: $exitCode" } -Write-Host "=== Build SUCCESS: $Target ===" \ No newline at end of file +Write-Host "====================================" +Write-Host " BUILD SUCCESS: $Target" +Write-Host "====================================" \ No newline at end of file