Files
linuxdistro-roguelite/Tools/Validate-Checkout.ps1
T

68 lines
3.9 KiB
PowerShell

[CmdletBinding()]
param(
[string]$UnityPath = 'C:/Program Files/Unity/Hub/Editor/6000.4.8f1/Editor/Unity.exe',
[switch]$UseInstalledPackageCache,
[switch]$Build
)
$ErrorActionPreference = 'Stop'
$sourceRoot = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot '..')).Path
if (!(Test-Path -LiteralPath $UnityPath)) { throw "Unity editor not found: $UnityPath" }
Push-Location $sourceRoot
try {
# Export the index, so untracked files cannot silently make validation pass. Stage intended
# source changes first; this script neither stages nor commits anything.
$tracked = @(& git ls-files)
if ($LASTEXITCODE) { throw 'Cannot enumerate the Git index.' }
$paths = [Collections.Generic.HashSet[string]]::new([StringComparer]::Ordinal)
foreach ($path in $tracked) { [void]$paths.Add($path) }
foreach ($path in $tracked) {
if ($path -notlike 'Assets/*' -or $path -like '*.meta' -or $path -match '(^|/)\.') { continue }
if (!$paths.Contains($path + '.meta')) { throw "Missing tracked asset metadata: $path.meta" }
$parent = Split-Path $path -Parent
while ($parent -and $parent -ne 'Assets') {
$parent = $parent.Replace('\', '/')
if (!$paths.Contains($parent + '.meta')) { throw "Missing tracked folder metadata: $parent.meta" }
$parent = Split-Path $parent -Parent
}
}
$validationRoot = Join-Path ([IO.Path]::GetTempPath()) ('KernelPanicCheckout-' + [guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $validationRoot | Out-Null
$prefix = $validationRoot.Replace('\', '/') + '/'
& git checkout-index --all "--prefix=$prefix"
if ($LASTEXITCODE) { throw 'Git index export failed.' }
Write-Output "Validation project: $validationRoot"
if ($UseInstalledPackageCache) {
$cache = Join-Path $sourceRoot 'Library/PackageCache'
if (!(Test-Path -LiteralPath $cache)) { throw 'No installed package cache available.' }
& robocopy $cache (Join-Path $validationRoot 'Library/PackageCache') /E /NFL /NDL /NJH /NJS /R:1 /W:1
if ($LASTEXITCODE -ge 8) { throw 'Package cache copy failed.' }
}
$artifacts = Join-Path $validationRoot 'Artifacts'
New-Item -ItemType Directory -Path $artifacts | Out-Null
function Invoke-ValidationUnity([string[]]$Arguments) {
# All paths are generated here or explicitly supplied by the caller; quote each argument.
foreach ($argument in $Arguments) {
if ($argument.Contains('"')) { throw 'Double quotes are not supported in Unity arguments.' }
}
$quoted = ($Arguments | ForEach-Object { '"' + $_ + '"' }) -join ' '
$process = Start-Process -FilePath $UnityPath -ArgumentList $quoted -WindowStyle Hidden -PassThru
if (!$process.WaitForExit(1800000)) {
$process.Kill()
throw "Isolated validation timed out. See $artifacts"
}
if ($process.ExitCode -ne 0) { throw "Unity failed ($($process.ExitCode)). See $artifacts" }
}
Invoke-ValidationUnity @('-batchmode', '-projectPath', $validationRoot, '-runTests', '-testPlatform', 'EditMode',
'-testResults', (Join-Path $artifacts 'editmode.xml'), '-logFile', (Join-Path $artifacts 'editmode.log'))
[xml]$results = Get-Content -LiteralPath (Join-Path $artifacts 'editmode.xml') -Raw
if ($results.'test-run'.result -ne 'Passed' -or [int]$results.'test-run'.total -eq 0) { throw 'Tests did not pass.' }
Write-Output "EditMode: $($results.'test-run'.passed) passed; $($results.'test-run'.failed) failed."
if ($Build) {
Invoke-ValidationUnity @('-batchmode', '-quit', '-projectPath', $validationRoot,
'-executeMethod', 'KernelPanic.Editor.PlayerBuild.BuildWindows',
'-kernelPanicBuildPath', (Join-Path $artifacts 'Windows/KernelPanic.exe'),
'-logFile', (Join-Path $artifacts 'build.log'))
Write-Output "Player: $(Join-Path $artifacts 'Windows/KernelPanic.exe')"
}
} finally { Pop-Location }