65 lines
2.6 KiB
PowerShell
65 lines
2.6 KiB
PowerShell
#Requires -Version 7.0
|
|
param(
|
|
[Parameter(Mandatory)] [string]$Executable,
|
|
[Parameter(Mandatory)] [string]$Version,
|
|
[switch]$Package
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$exe = Get-Item -LiteralPath $Executable
|
|
$start = [Diagnostics.ProcessStartInfo]::new($exe.FullName)
|
|
$start.ArgumentList.Add('version')
|
|
$start.UseShellExecute = $false
|
|
$start.CreateNoWindow = $true
|
|
$start.RedirectStandardOutput = $true
|
|
$start.RedirectStandardError = $true
|
|
$process = [Diagnostics.Process]::Start($start)
|
|
try {
|
|
$stdout = $process.StandardOutput.ReadToEndAsync()
|
|
$stderr = $process.StandardError.ReadToEndAsync()
|
|
if (-not $process.WaitForExit(15000)) {
|
|
$process.Kill($true)
|
|
throw "$($exe.Name) version timed out"
|
|
}
|
|
$actual = $stdout.GetAwaiter().GetResult().Trim()
|
|
if ($process.ExitCode -ne 0 -or $actual -cne "reims-go $Version") {
|
|
throw "$($exe.Name) version returned '$actual' (exit $($process.ExitCode)): $($stderr.GetAwaiter().GetResult())"
|
|
}
|
|
} finally {
|
|
$process.Dispose()
|
|
}
|
|
|
|
if ($Package) {
|
|
$zip = Get-Item -LiteralPath ([IO.Path]::ChangeExtension($exe.FullName, '.zip'))
|
|
$exeHash = (Get-FileHash -LiteralPath $exe.FullName -Algorithm SHA256).Hash
|
|
$zipHash = (Get-FileHash -LiteralPath $zip.FullName -Algorithm SHA256).Hash
|
|
$expected = @("$($exeHash.ToLowerInvariant()) $($exe.Name)", "$($zipHash.ToLowerInvariant()) $($zip.Name)")
|
|
$sums = @(Get-Content -LiteralPath (Join-Path $exe.DirectoryName 'SHA256SUMS.txt'))
|
|
if ($sums.Count -ne $expected.Count -or (Compare-Object $expected $sums -CaseSensitive)) {
|
|
throw 'SHA256SUMS.txt does not match the EXE and ZIP'
|
|
}
|
|
|
|
$archive = [IO.Compression.ZipFile]::OpenRead($zip.FullName)
|
|
try {
|
|
$required = @($exe.Name, 'LICENSE', 'NOTICE.md')
|
|
if ($archive.Entries.Count -ne $required.Count -or (Compare-Object $required @($archive.Entries.FullName) -CaseSensitive)) {
|
|
throw 'ZIP must contain the EXE, LICENSE and NOTICE.md at its root'
|
|
}
|
|
foreach ($name in $required) {
|
|
$entry = $archive.GetEntry($name).Open()
|
|
try {
|
|
$hash = (Get-FileHash -InputStream $entry -Algorithm SHA256).Hash
|
|
$source = if ($name -eq $exe.Name) { $exeHash } else {
|
|
(Get-FileHash -LiteralPath (Join-Path $PSScriptRoot "../$name") -Algorithm SHA256).Hash
|
|
}
|
|
if ($hash -cne $source) { throw "ZIP entry $name differs from its source file" }
|
|
} finally {
|
|
$entry.Dispose()
|
|
}
|
|
}
|
|
} finally {
|
|
$archive.Dispose()
|
|
}
|
|
}
|
|
Write-Host "PASS $($exe.Name) $Version"
|