<# .SYNOPSIS Entry gate for the alpha channel (portable-runtime-spec.md section 6), run by CI on the packed release files before anything is published. .DESCRIPTION Fails unless all of these hold: 1. All four release assets exist in -OutDir: the runtime, its source package, the MSYS2 source package and SHA256SUMS.txt (spec section 7: a runtime is never published without its sources). 2. SHA256SUMS.txt lists the three archives, and every hash matches. 3. manifest.json in the runtime names -Commit, channel "alpha", the source package, and exactly the patches in -AppliedPatches. 4. The runtime's own qemu-system-x86_64.exe, run with a PATH holding only the runtime and Windows (no MSYS2), lists reims-graphics-pci in "-device help". This is not the stable gate: promotion to stable still needs the real-host smoke test (scripts/smoke-runtime.ps1) and a person's approval. #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$OutDir, [Parameter(Mandatory = $true)] [string]$Commit, [Parameter(Mandatory = $true)] [string]$Zstd, [string[]]$AppliedPatches = @(), # Only for checking packages built before the 2026-11-28 rename ("candidate"). [string]$ExpectChannel = 'alpha', [string]$TempRoot = $env:RUNNER_TEMP ) $ErrorActionPreference = 'Stop' $AppliedPatches = @($AppliedPatches | ForEach-Object { $_ -split ',' } | ForEach-Object { $_.Trim() } | Where-Object { $_ }) $names = @{ runtime = "reims-runtime-win-x64-$Commit.tar.zst" source = "reims-runtime-src-$Commit.tar.zst" msys2 = "reims-runtime-msys2-src-$Commit.tar.zst" sums = 'SHA256SUMS.txt' } # 1. All four assets. foreach ($k in $names.Keys) { $p = Join-Path $OutDir $names[$k] if (-not (Test-Path -LiteralPath $p)) { throw "Missing release asset: $($names[$k])" } } Write-Host 'PASS four release assets present' # 2. Sums cover the three archives and match. $sums = @{} foreach ($line in Get-Content -LiteralPath (Join-Path $OutDir $names.sums)) { if ($line -match '^([0-9a-fA-F]{64})\s+\*?(.+)$') { $sums[$Matches[2].Trim()] = $Matches[1].ToLowerInvariant() } } foreach ($k in 'runtime', 'source', 'msys2') { $n = $names[$k] if (-not $sums.ContainsKey($n)) { throw "SHA256SUMS.txt has no entry for $n" } $got = (Get-FileHash -Algorithm SHA256 -LiteralPath (Join-Path $OutDir $n)).Hash.ToLowerInvariant() if ($got -ne $sums[$n]) { throw "SHA256 mismatch for ${n}: listed $($sums[$n]), actual $got" } } Write-Host 'PASS SHA256SUMS.txt covers and matches all archives' # Extract the runtime. $work = Join-Path $TempRoot ("alpha-gate-" + [guid]::NewGuid()) New-Item -ItemType Directory -Force -Path $work | Out-Null try { $tar = Join-Path $work 'runtime.tar' & $Zstd -d -q -f (Join-Path $OutDir $names.runtime) -o $tar if ($LASTEXITCODE -ne 0) { throw "zstd failed ($LASTEXITCODE)" } # Windows' own bsdtar: GNU tar from Git/MSYS2 reads "D:" as a remote host. & (Join-Path $env:SystemRoot 'System32\tar.exe') -xf $tar -C $work if ($LASTEXITCODE -ne 0) { throw "tar failed ($LASTEXITCODE)" } Remove-Item -LiteralPath $tar -Force $root = Join-Path $work "reims-runtime-win-x64-$Commit" # 3. Manifest states what was really built. $m = Get-Content -Raw -LiteralPath (Join-Path $root 'manifest.json') | ConvertFrom-Json if ($m.commit -ne $Commit) { throw "manifest commit is $($m.commit), expected $Commit" } if ($m.channel -ne $ExpectChannel) { throw "manifest channel is $($m.channel), expected $ExpectChannel" } if ($m.source_package -ne $names.source) { throw "manifest source_package is $($m.source_package), expected $($names.source)" } $declared = @($m.patches | ForEach-Object { $_.name }) if (($declared -join ',') -ne ($AppliedPatches -join ',')) { throw "manifest patches [$($declared -join ', ')] differ from those applied [$($AppliedPatches -join ', ')]" } Write-Host "PASS manifest: commit $Commit, channel $($m.channel), patches [$($declared -join ', ')]" # 4. QEMU runs from the bundle alone and has the reims device. $qemuBin = Join-Path $root 'qemu\bin' $psi = [Diagnostics.ProcessStartInfo]::new((Join-Path $qemuBin 'qemu-system-x86_64.exe'), '-device help') $psi.UseShellExecute = $false $psi.RedirectStandardOutput = $true $psi.RedirectStandardError = $true $psi.WorkingDirectory = $qemuBin $psi.Environment['PATH'] = "$qemuBin;$env:SystemRoot\System32;$env:SystemRoot" $proc = [Diagnostics.Process]::Start($psi) $errTask = $proc.StandardError.ReadToEndAsync() $out = $proc.StandardOutput.ReadToEnd() if (-not $proc.WaitForExit(120000)) { $proc.Kill(); throw 'qemu -device help timed out' } $err = $errTask.Result if ($proc.ExitCode -ne 0) { throw "qemu -device help exited $($proc.ExitCode): $err" } if ($out -notmatch 'reims-graphics-pci') { throw "qemu -device help does not list reims-graphics-pci`n$out`n$err" } Write-Host 'PASS qemu-system-x86_64 -device help lists reims-graphics-pci (no MSYS2 on PATH)' } finally { Remove-Item -Recurse -Force -LiteralPath $work -ErrorAction SilentlyContinue }