60 lines
4.5 KiB
PowerShell
60 lines
4.5 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
$ridRepo = Split-Path $PSScriptRoot -Parent
|
|
$ridRoot = Join-Path ([IO.Path]::GetTempPath()) ('RID-package-review-' + [guid]::NewGuid().ToString('N'))
|
|
$ridOutput = Join-Path $ridRoot 'output'
|
|
$ridDeployment = Join-Path $ridOutput 'FPV-RID-Rust'
|
|
$ridData = Join-Path $ridDeployment 'registry/data'
|
|
New-Item -ItemType Directory -Force -Path $ridData | Out-Null
|
|
$ridSentinel = Join-Path $ridData 'registry.sqlite'
|
|
[IO.File]::WriteAllText($ridSentinel, 'sentinel data: must not be touched or packaged')
|
|
$ridBefore = (Get-FileHash -LiteralPath $ridSentinel -Algorithm SHA256).Hash
|
|
$ridRejected = $false
|
|
try { & (Join-Path $PSScriptRoot 'package.ps1') -OutputRoot $ridOutput } catch { $ridRejected = $true }
|
|
if (-not $ridRejected) { throw 'Dirty deployment folder was accepted' }
|
|
if ((Get-FileHash -LiteralPath $ridSentinel -Algorithm SHA256).Hash -ne $ridBefore) { throw 'Deployment data was modified' }
|
|
if (Test-Path -LiteralPath (Join-Path $ridOutput 'FPV-RID-Rust-Windows-x64.zip')) { throw 'Dirty package was published' }
|
|
|
|
$ridCacheOutput = Join-Path $ridRoot 'existing-map'
|
|
$ridExistingTiles = Join-Path $ridCacheOutput 'FPV-RID-Rust/map_cache/img_w/2/1'
|
|
New-Item -ItemType Directory -Path $ridExistingTiles -Force | Out-Null
|
|
$ridMapSentinel = Join-Path $ridExistingTiles '2.png'
|
|
[IO.File]::WriteAllText($ridMapSentinel, 'existing offline tile')
|
|
$ridRejected = $false
|
|
try { & (Join-Path $PSScriptRoot 'package.ps1') -OutputRoot $ridCacheOutput } catch { $ridRejected = $true }
|
|
if (!$ridRejected -or [IO.File]::ReadAllText($ridMapSentinel) -ne 'existing offline tile') { throw 'Offline map directory was not protected' }
|
|
|
|
$ridCleanOutput = Join-Path $ridRoot 'clean'
|
|
& (Join-Path $PSScriptRoot 'package.ps1') -OutputRoot $ridCleanOutput
|
|
if ($LASTEXITCODE -ne 0) { throw 'Clean package failed' }
|
|
# Repackage the same clean output, proving repeat builds remain supported.
|
|
& (Join-Path $PSScriptRoot 'package.ps1') -OutputRoot $ridCleanOutput
|
|
if ($LASTEXITCODE -ne 0) { throw 'Repeat package failed' }
|
|
$ridExistingZip = Join-Path $ridCleanOutput 'FPV-RID-Rust-Windows-x64.zip'
|
|
$ridOriginalZipHash = (Get-FileHash -LiteralPath $ridExistingZip -Algorithm SHA256).Hash
|
|
$ridUsedData = Join-Path $ridCleanOutput 'FPV-RID-Rust/registry/data'
|
|
New-Item -ItemType Directory -Force -Path $ridUsedData | Out-Null
|
|
[IO.File]::WriteAllText((Join-Path $ridUsedData 'registry.sqlite'), 'used deployment sentinel')
|
|
$ridRejected = $false
|
|
try { & (Join-Path $PSScriptRoot 'package.ps1') -OutputRoot $ridCleanOutput } catch { $ridRejected = $true }
|
|
if (-not $ridRejected) { throw 'Repackaging a used release folder was accepted' }
|
|
if ((Get-FileHash -LiteralPath $ridExistingZip -Algorithm SHA256).Hash -ne $ridOriginalZipHash) { throw 'Existing clean ZIP was overwritten on rejection' }
|
|
if ([IO.File]::ReadAllText((Join-Path $ridUsedData 'registry.sqlite')) -ne 'used deployment sentinel') { throw 'Existing deployment data was changed' }
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
$ridZipPath = Join-Path $ridCleanOutput 'FPV-RID-Rust-Windows-x64.zip'
|
|
$ridZip = [IO.Compression.ZipFile]::OpenRead($ridZipPath)
|
|
try {
|
|
$ridExpected = @('fpv-rid-registry.exe','rid-map-downloader.exe','map-downloader-LICENSE.txt','启动Rust版.cmd','使用说明.md','config.example.json','third-party-licenses.txt','dependency-licenses.txt','build-info.json','SHA256SUMS.txt','map_cache/README.txt') | ForEach-Object { 'FPV-RID-Rust/' + $_ }
|
|
$ridActual = @($ridZip.Entries | ForEach-Object { $_.FullName.Replace('\','/') })
|
|
if ($ridActual.Count -ne $ridExpected.Count -or @(Compare-Object $ridActual $ridExpected).Count) { throw 'Archive contains unexpected files' }
|
|
} finally { $ridZip.Dispose() }
|
|
$ridZipHash = (Get-FileHash -LiteralPath $ridZipPath -Algorithm SHA256).Hash
|
|
if (-not (Get-Content -LiteralPath "$ridZipPath.sha256" -Raw).StartsWith($ridZipHash)) { throw 'ZIP checksum mismatch' }
|
|
foreach ($ridLine in Get-Content -LiteralPath (Join-Path $ridCleanOutput 'FPV-RID-Rust/SHA256SUMS.txt')) {
|
|
if ($ridLine -notmatch '^([A-F0-9]{64}) (.+)$') { throw 'Invalid checksum entry' }
|
|
$ridHash = $Matches[1]
|
|
$ridFile = Join-Path (Join-Path $ridCleanOutput 'FPV-RID-Rust') $Matches[2]
|
|
if ((Get-FileHash -LiteralPath $ridFile -Algorithm SHA256).Hash -ne $ridHash) { throw 'Release file checksum mismatch' }
|
|
}
|
|
if (@(Get-ChildItem -LiteralPath $ridCleanOutput -Directory -Filter '.package-*').Count) { throw 'Owned staging files were left behind' }
|
|
Write-Output "PASS: existing data and tiles preserved; repeat package, map_cache, ZIP and file checksums verified. Evidence: $ridRoot"
|