more
This commit is contained in:
+84
-21
@@ -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 ==="
|
||||
Write-Host "===================================="
|
||||
Write-Host " BUILD SUCCESS: $Target"
|
||||
Write-Host "===================================="
|
||||
Reference in New Issue
Block a user