49 lines
3.1 KiB
PowerShell
49 lines
3.1 KiB
PowerShell
# Build the Windows installer natively on Windows (Go + NSIS).
|
|
# Usage: powershell -ExecutionPolicy Bypass -File platform\windows\build-windows.ps1 [-Arch amd64|arm64] [-Version x.y.z]
|
|
# Version default: Get-VeraePackageVersion → internal/job.HelperVersion (or $env:VERSION).
|
|
param([string]$Arch = "amd64", [string]$Version = "")
|
|
$ErrorActionPreference = "Stop"
|
|
$Root = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).Path
|
|
$Out = Join-Path $Root "dist\windows"
|
|
$Stage = Join-Path $Out "stage-$Arch"
|
|
$Go = (Get-Command go -ErrorAction SilentlyContinue).Source; if (-not $Go) { $Go = "C:\Program Files\Go\bin\go.exe" }
|
|
$Nsis = (Get-Command makensis -ErrorAction SilentlyContinue).Source; if (-not $Nsis) { $Nsis = "${env:ProgramFiles(x86)}\NSIS\makensis.exe" }
|
|
|
|
# Package version = internal/job.HelperVersion (single source of truth).
|
|
$common = Join-Path $PSScriptRoot "scripts\common.ps1"
|
|
if (Test-Path -LiteralPath $common) { . $common }
|
|
if (-not $Version) {
|
|
if (Get-Command Get-VeraePackageVersion -ErrorAction SilentlyContinue) {
|
|
$Version = Get-VeraePackageVersion
|
|
} elseif ($env:VERSION -and $env:VERSION.Trim()) {
|
|
$Version = $env:VERSION.Trim()
|
|
} else {
|
|
$jobGo = Join-Path $Root "internal\job\job.go"
|
|
if (Test-Path -LiteralPath $jobGo) {
|
|
$line = Select-String -Path $jobGo -Pattern 'HelperVersion\s*=\s*"([^"]+)"' -ErrorAction SilentlyContinue |
|
|
Select-Object -First 1
|
|
if ($line -and $line.Matches.Count -gt 0) {
|
|
$Version = $line.Matches[0].Groups[1].Value
|
|
}
|
|
}
|
|
}
|
|
if (-not $Version) { $Version = "0.3.6" } # must match HelperVersion fallback
|
|
}
|
|
Remove-Item -Recurse -Force $Stage -ErrorAction SilentlyContinue
|
|
New-Item -ItemType Directory -Force -Path $Stage, (Join-Path $Stage "scripts") | Out-Null
|
|
Push-Location $Root
|
|
try {
|
|
$env:CGO_ENABLED = "0"; $env:GOOS = "windows"; $env:GOARCH = $Arch
|
|
& $Go version
|
|
& $Go test ./internal/... ./cmd/... ; if ($LASTEXITCODE) { throw "go test failed" }
|
|
& $Go build -trimpath -ldflags "-s -w" -o (Join-Path $Stage "verae-print.exe") ./cmd/verae-print; if ($LASTEXITCODE) { throw "build cli failed" }
|
|
& $Go build -trimpath -ldflags "-s -w -H windowsgui" -o (Join-Path $Stage "verae-printhelper.exe") ./cmd/verae-print; if ($LASTEXITCODE) { throw "build helper failed" }
|
|
} finally { Pop-Location; Remove-Item Env:GOOS, Env:GOARCH -ErrorAction SilentlyContinue }
|
|
Copy-Item (Join-Path $PSScriptRoot "scripts\*.ps1") (Join-Path $Stage "scripts")
|
|
Copy-Item (Join-Path $PSScriptRoot "LICENSE.txt"), (Join-Path $PSScriptRoot "README-WINDOWS.txt") $Stage
|
|
& $Nsis /V3 "/DVERSION=$Version" "/DARCH=$Arch" "/DSRCDIR=$Stage" "/DOUTDIR=$Out" (Join-Path $PSScriptRoot "installer-windows.nsi")
|
|
if ($LASTEXITCODE) { throw "makensis failed" }
|
|
# raw files alongside the installer
|
|
Copy-Item (Join-Path $Stage "*") $Out -Recurse -Force
|
|
Get-ChildItem $Out -File | Where-Object { $_.Name -ne "SHA256SUMS.txt" -and $_.Extension -ne ".bundle" } | Get-FileHash -Algorithm SHA256 | ForEach-Object { "$($_.Hash.ToLower()) $(Split-Path $_.Path -Leaf)" } | Set-Content (Join-Path $Out "SHA256SUMS.txt")
|
|
Get-ChildItem $Out -File | Format-Table Name, Length -AutoSize
|