117 lines
2.8 KiB
PowerShell
117 lines
2.8 KiB
PowerShell
param(
|
|
[string]$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
|
|
|
|
$hubExe = "${env:ProgramFiles}\Unity Hub\Unity Hub.exe"
|
|
|
|
if (!(Test-Path $hubExe)) {
|
|
throw "Unity Hub not found at: $hubExe"
|
|
}
|
|
|
|
# -----------------------------
|
|
# 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"
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
$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 "====================================" |