Track release build scripts for Forgejo Actions.
All checks were successful
release / build-and-upload (push) Successful in 16m38s

scripts/ was fully gitignored, so tag pushes could never run
scripts/build-release.sh on the runner. Keep other local scripts
ignored; ship only the cross-compile helpers CI needs.
This commit is contained in:
404errordeveloper 2026-10-08 20:00:37 +02:00
parent 71d641eca6
commit a930a697fa
3 changed files with 207 additions and 1 deletions

100
scripts/build-release.ps1 Normal file
View file

@ -0,0 +1,100 @@
# Cross-compile host drm + on-device proxy-android-arm64 into dist/release/.
# Usage:
# .\scripts\build-release.ps1
# .\scripts\build-release.ps1 -Version v1.2.3
param(
[string]$Version = "",
[string]$Out = ""
)
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
if (-not $Out) { $Out = Join-Path $Root "dist\release" }
if (-not $Version) {
try { $Version = (git -C $Root describe --tags --always --dirty 2>$null) } catch { $Version = "dev" }
if (-not $Version) { $Version = "dev" }
}
function Resolve-Go {
$cmd = Get-Command go -ErrorAction SilentlyContinue
if ($cmd) { return $cmd.Source }
$candidates = @(
"$env:USERPROFILE\go-sdk\go\bin\go.exe",
"$env:USERPROFILE\sdk\go\bin\go.exe",
"$env:USERPROFILE\go\bin\go.exe",
"$env:LOCALAPPDATA\Programs\Go\bin\go.exe",
"C:\Program Files\Go\bin\go.exe",
"C:\Go\bin\go.exe",
"$env:GOROOT\bin\go.exe"
)
foreach ($c in $candidates) {
if ($c -and (Test-Path $c)) { return $c }
}
throw "go not found. Install Go or add it to PATH (looked in go-sdk, Program Files, GOROOT)."
}
$GoExe = Resolve-Go
Write-Host "==> using $GoExe"
& $GoExe version
New-Item -ItemType Directory -Force -Path $Out | Out-Null
Get-ChildItem $Out -ErrorAction SilentlyContinue | Where-Object { $_.Name -match '^(drm-|proxy-android-arm64|SHA256SUMS)' } | Remove-Item -Force
function Build-Host([string]$Goos, [string]$Goarch, [string]$Ext = "") {
$name = "drm-$Goos-$Goarch$Ext"
Write-Host " - $name"
$env:GOOS = $Goos
$env:GOARCH = $Goarch
$env:CGO_ENABLED = "0"
Push-Location $Root
try {
& $GoExe -C apps/cli build -trimpath -ldflags="-s -w" -o (Join-Path $Out $name) .
if ($LASTEXITCODE -ne 0) { throw "go build failed for $name" }
} finally {
Pop-Location
Remove-Item Env:GOOS -ErrorAction SilentlyContinue
Remove-Item Env:GOARCH -ErrorAction SilentlyContinue
Remove-Item Env:CGO_ENABLED -ErrorAction SilentlyContinue
}
}
Write-Host "==> building host drm ($Version) into $Out"
Build-Host windows amd64 ".exe"
Build-Host windows arm64 ".exe"
Build-Host linux amd64
Build-Host linux arm64
Build-Host darwin amd64
Build-Host darwin arm64
Write-Host "==> building on-device MITM (linux/arm64)"
$env:GOOS = "linux"
$env:GOARCH = "arm64"
$env:CGO_ENABLED = "0"
Push-Location (Join-Path $Root "apps\proxy\device")
try {
& $GoExe build -trimpath -ldflags="-s -w" -o (Join-Path $Out "proxy-android-arm64") .
if ($LASTEXITCODE -ne 0) { throw "proxy-android-arm64 build failed" }
} finally {
Pop-Location
Remove-Item Env:GOOS -ErrorAction SilentlyContinue
Remove-Item Env:GOARCH -ErrorAction SilentlyContinue
Remove-Item Env:CGO_ENABLED -ErrorAction SilentlyContinue
}
New-Item -ItemType Directory -Force -Path (Join-Path $Root "bin"), (Join-Path $Root "apps\proxy") | Out-Null
Copy-Item (Join-Path $Out "proxy-android-arm64") (Join-Path $Root "bin\proxy-android-arm64") -Force
Copy-Item (Join-Path $Out "proxy-android-arm64") (Join-Path $Root "apps\proxy\proxy-android-arm64") -Force
Copy-Item (Join-Path $Out "drm-windows-amd64.exe") (Join-Path $Root "bin\drm.exe") -Force
Write-Host "==> checksums"
$sumsPath = Join-Path $Out "SHA256SUMS.txt"
$tmpSums = Join-Path $Out "SHA256SUMS.txt.tmp"
$lines = Get-ChildItem $Out -File |
Where-Object { $_.Name -match '^(drm-|proxy-android)' } |
Get-FileHash -Algorithm SHA256 |
ForEach-Object { "{0} {1}" -f $_.Hash.ToLower(), (Split-Path $_.Path -Leaf) }
[System.IO.File]::WriteAllLines($tmpSums, @($lines))
Move-Item -Force $tmpSums $sumsPath
Write-Host "==> done ($Version)"
Get-ChildItem $Out | Format-Table Name, Length