more
This commit is contained in:
+105
-89
@@ -9,109 +9,125 @@ Write-Host " Unity CI Build (Windows Agent)"
|
||||
Write-Host " Target: $Target"
|
||||
Write-Host "===================================="
|
||||
|
||||
# -----------------------------
|
||||
# Load toolchain config
|
||||
# -----------------------------
|
||||
$config = Get-Content ".\ci\toolchain.json" | ConvertFrom-Json
|
||||
try {
|
||||
|
||||
$unityVersion = $config.unityVersion
|
||||
$unityRoot = $config.windows.unityRoot
|
||||
# -----------------------------
|
||||
# Load toolchain config
|
||||
# -----------------------------
|
||||
$config = Get-Content ".\ci\toolchain.json" | ConvertFrom-Json
|
||||
|
||||
$hubExe = "${env:ProgramFiles}\Unity Hub\Unity Hub.exe"
|
||||
$unityVersion = $config.unityVersion
|
||||
$unityRoot = $config.windows.unityRoot
|
||||
|
||||
if (!(Test-Path $hubExe)) {
|
||||
throw "Unity Hub not found at: $hubExe"
|
||||
}
|
||||
$hubExe = "${env:ProgramFiles}\Unity Hub\Unity Hub.exe"
|
||||
|
||||
# -----------------------------
|
||||
# Ensure Unity is installed
|
||||
# -----------------------------
|
||||
$unityEditorPath = Join-Path $unityRoot "$unityVersion\Editor\Unity.exe"
|
||||
|
||||
if (!(Test-Path $unityEditorPath)) {
|
||||
|
||||
Write-Host "Unity $unityVersion not found. Installing via Unity Hub..."
|
||||
|
||||
# Install Unity Editor
|
||||
& $hubExe -- --headless install `
|
||||
--version $unityVersion 2>$null
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Failed to install Unity $unityVersion"
|
||||
if (!(Test-Path $hubExe)) {
|
||||
throw "Unity Hub not found at: $hubExe"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Unity found: $unityEditorPath"
|
||||
# -----------------------------
|
||||
# Ensure Unity is installed
|
||||
# -----------------------------
|
||||
$unityEditorPath = Join-Path $unityRoot "$unityVersion\Editor\Unity.exe"
|
||||
|
||||
# -----------------------------
|
||||
# Ensure required modules
|
||||
# -----------------------------
|
||||
# NOTE:
|
||||
# Unity Hub CLI installs modules per version.
|
||||
# These are cached per editor version, not reinstalled each build.
|
||||
if (!(Test-Path $unityEditorPath)) {
|
||||
|
||||
$modules = $config.windows.modules
|
||||
Write-Host "Unity $unityVersion not found. Installing via Unity Hub..."
|
||||
|
||||
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
|
||||
# Install Unity Editor
|
||||
& $hubExe -- --headless install `
|
||||
--version $unityVersion
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Failed to install module: $module"
|
||||
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
|
||||
# -----------------------------
|
||||
if (!$Target) {
|
||||
Write-Host "No Target Provided"
|
||||
exit
|
||||
}
|
||||
else {
|
||||
Write-Host "Module already installed: $module"
|
||||
$method = switch ($Target) {
|
||||
"Windows" { "BuildScript.Windows" }
|
||||
"Android" { "BuildScript.Android" }
|
||||
}
|
||||
|
||||
Write-Host "Using Unity method: $method"
|
||||
|
||||
# -----------------------------
|
||||
# Run Unity build
|
||||
# -----------------------------
|
||||
$unityArgs = @(
|
||||
"-batchmode",
|
||||
"-nographics",
|
||||
"-quit",
|
||||
"-projectPath", "$PWD",
|
||||
"-executeMethod", "$method",
|
||||
"-logFile", "$PWD/unity_batch_build.log" # CRITICAL: Captures what goes wrong
|
||||
)
|
||||
|
||||
# Execute using the array
|
||||
& $unityEditorPath @unityArgs
|
||||
|
||||
$exitCode = $LASTEXITCODE
|
||||
|
||||
# -----------------------------
|
||||
# Validate result
|
||||
# -----------------------------
|
||||
if ($exitCode -ne 0) {
|
||||
throw "Unity build failed ($Target). Exit code: $exitCode"
|
||||
}
|
||||
|
||||
Write-Host "===================================="
|
||||
Write-Host " BUILD SUCCESS: $Target"
|
||||
Write-Host "===================================="
|
||||
}
|
||||
}
|
||||
|
||||
# -----------------------------
|
||||
# Resolve Unity build method
|
||||
# -----------------------------
|
||||
if(!$Target){
|
||||
Write-Host "No Target Provided"
|
||||
exit
|
||||
catch {
|
||||
throw
|
||||
}
|
||||
finally {
|
||||
Write-Host "Cleaning Up"
|
||||
# Stop-Process -Name "Unity", "Unity Hub" -Force
|
||||
}
|
||||
$method = switch ($Target) {
|
||||
"Windows" { "BuildScript.Windows" }
|
||||
"Android" { "BuildScript.Android" }
|
||||
}
|
||||
|
||||
Write-Host "Using Unity method: $method"
|
||||
|
||||
# -----------------------------
|
||||
# Run Unity build
|
||||
# -----------------------------
|
||||
& $unityEditorPath `
|
||||
-batchmode `
|
||||
-nographics `
|
||||
-quit `
|
||||
-projectPath $PWD `
|
||||
-executeMethod $method `
|
||||
-logFile build-$Target.log
|
||||
|
||||
$exitCode = $LASTEXITCODE
|
||||
|
||||
# -----------------------------
|
||||
# Validate result
|
||||
# -----------------------------
|
||||
if ($exitCode -ne 0) {
|
||||
throw "Unity build failed ($Target). Exit code: $exitCode"
|
||||
}
|
||||
|
||||
Write-Host "===================================="
|
||||
Write-Host " BUILD SUCCESS: $Target"
|
||||
Write-Host "===================================="
|
||||
Reference in New Issue
Block a user