Files
Deployr/scripts/build.ps1
T
ClaudeandClaude Opus 5 7daceac077 Drop the version from release artifact names
The install scripts fetch deployr_<os>_<arch>, and the release tag already says
which version it is. Keeping the version in the filename too meant the bootstrap
had to reconstruct the name from the tag, which breaks the moment a tag is not
exactly "v" plus the version string.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 17:20:58 -05:00

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_${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)) }