Format-Table writes format-descriptor objects, not text, so piping the script through Select-Object or Out-String broke the stream and made the script exit 1 after a successful build. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
68 lines
2.0 KiB
PowerShell
68 lines
2.0 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Cross-compiles deployr for every supported platform.
|
|
|
|
.EXAMPLE
|
|
.\scripts\build.ps1 # build everything into dist\
|
|
.\scripts\build.ps1 -Version 1.0.0 # stamp a release version
|
|
.\scripts\build.ps1 -Only windows/amd64
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[string]$Version = "dev",
|
|
[string]$Only = "",
|
|
[string]$OutDir = "dist"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$root = Split-Path -Parent $PSScriptRoot
|
|
Set-Location $root
|
|
|
|
$targets = @(
|
|
"windows/amd64",
|
|
"windows/arm64",
|
|
"darwin/amd64",
|
|
"darwin/arm64",
|
|
"linux/amd64",
|
|
"linux/arm64"
|
|
)
|
|
if ($Only) { $targets = @($Only) }
|
|
|
|
$commit = "none"
|
|
try { $commit = (git rev-parse --short HEAD 2>$null).Trim() } catch { }
|
|
if (-not $commit) { $commit = "none" }
|
|
$date = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
|
|
|
|
$pkg = "git.starwarslab.us/ATOM_IT/Deployr/internal/version"
|
|
$ldflags = "-s -w -X $pkg.Version=$Version -X $pkg.Commit=$commit -X $pkg.Date=$date"
|
|
|
|
New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
|
|
|
|
foreach ($target in $targets) {
|
|
$parts = $target.Split("/")
|
|
$os = $parts[0]
|
|
$arch = $parts[1]
|
|
$name = "deployr_${Version}_${os}_${arch}"
|
|
if ($os -eq "windows") { $name += ".exe" }
|
|
|
|
Write-Host "building $target -> $OutDir\$name"
|
|
$env:GOOS = $os
|
|
$env:GOARCH = $arch
|
|
$env:CGO_ENABLED = "0"
|
|
go build -trimpath -ldflags $ldflags -o "$OutDir\$name" ./cmd/deployr
|
|
if ($LASTEXITCODE -ne 0) { throw "build failed for $target" }
|
|
}
|
|
|
|
$env:GOOS = ""; $env:GOARCH = ""; $env:CGO_ENABLED = ""
|
|
|
|
Get-ChildItem $OutDir -File |
|
|
Where-Object { $_.Name -ne "SHA256SUMS" } |
|
|
ForEach-Object { "{0} {1}" -f (Get-FileHash $_.FullName -Algorithm SHA256).Hash.ToLower(), $_.Name } |
|
|
Set-Content -Path (Join-Path $OutDir "SHA256SUMS") -Encoding utf8
|
|
|
|
Write-Host ""
|
|
# Emit plain strings, not format objects: Format-Table output breaks if the
|
|
# caller pipes this script through Select-Object or Out-String.
|
|
Get-ChildItem $OutDir -File |
|
|
ForEach-Object { Write-Host ("{0,-40} {1,6:N1} MB" -f $_.Name, ($_.Length / 1MB)) }
|