Track release build scripts for Forgejo Actions.
All checks were successful
release / build-and-upload (push) Successful in 16m38s
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:
parent
71d641eca6
commit
a930a697fa
3 changed files with 207 additions and 1 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -218,7 +218,10 @@ apps/proxy/proxy-android-arm64
|
|||
apps/proxy/rteproxy-android-arm64
|
||||
# local / VPS deploy + operator scripts (test stuff; keep out of git)
|
||||
deploy/
|
||||
scripts/
|
||||
# Ignore local scripts, but keep the release builders tracked for Forgejo Actions.
|
||||
scripts/*
|
||||
!scripts/build-release.sh
|
||||
!scripts/build-release.ps1
|
||||
# phone app modules: the Go packages are tracked and compiled into bin/drm.exe,
|
||||
# but most module.yaml files (package ids, Brightcove keys, origins, KIDs,
|
||||
# channel maps) are local only and must never be committed.
|
||||
|
|
|
|||
100
scripts/build-release.ps1
Normal file
100
scripts/build-release.ps1
Normal 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
|
||||
103
scripts/build-release.sh
Normal file
103
scripts/build-release.sh
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#!/usr/bin/env bash
|
||||
# Cross-compile host `drm` + on-device `proxy-android-arm64` into dist/release/.
|
||||
# Usage:
|
||||
# ./scripts/build-release.sh # VERSION=git describe
|
||||
# ./scripts/build-release.sh v1.2.3
|
||||
# OUT=dist/release ./scripts/build-release.sh
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
OUT="${OUT:-$ROOT/dist/release}"
|
||||
VERSION="${1:-}"
|
||||
if [[ -z "$VERSION" ]]; then
|
||||
VERSION="$(git -C "$ROOT" describe --tags --always --dirty 2>/dev/null || echo dev)"
|
||||
fi
|
||||
|
||||
# Resolve go even when it is not on PATH (e.g. Windows go-sdk install).
|
||||
resolve_go() {
|
||||
if command -v go >/dev/null 2>&1; then
|
||||
command -v go
|
||||
return
|
||||
fi
|
||||
local c
|
||||
for c in \
|
||||
"${GOROOT:+$GOROOT/bin/go}" \
|
||||
"$HOME/go-sdk/go/bin/go" \
|
||||
"$HOME/sdk/go/bin/go" \
|
||||
"$HOME/go/bin/go" \
|
||||
"/usr/local/go/bin/go" \
|
||||
"/usr/lib/go/bin/go"
|
||||
do
|
||||
if [[ -n "$c" && -x "$c" ]]; then
|
||||
echo "$c"
|
||||
return
|
||||
fi
|
||||
done
|
||||
echo "go not found on PATH or in common locations" >&2
|
||||
exit 1
|
||||
}
|
||||
GO="$(resolve_go)"
|
||||
echo "==> using $GO"
|
||||
"$GO" version
|
||||
|
||||
mkdir -p "$OUT"
|
||||
rm -f "$OUT"/drm-* "$OUT"/proxy-android-arm64 "$OUT"/SHA256SUMS.txt 2>/dev/null || true
|
||||
|
||||
echo "==> building host drm ($VERSION) into $OUT"
|
||||
build_host() {
|
||||
local goos="$1" goarch="$2" ext="${3:-}"
|
||||
local name="drm-${goos}-${goarch}${ext}"
|
||||
echo " - $name"
|
||||
(
|
||||
cd "$ROOT"
|
||||
GOOS="$goos" GOARCH="$goarch" CGO_ENABLED=0 \
|
||||
"$GO" -C apps/cli build -trimpath -ldflags="-s -w" -o "$OUT/$name" .
|
||||
)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
echo "==> building on-device MITM (linux/arm64)"
|
||||
(
|
||||
cd "$ROOT/apps/proxy/device"
|
||||
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 \
|
||||
"$GO" build -trimpath -ldflags='-s -w' -o "$OUT/proxy-android-arm64" .
|
||||
)
|
||||
|
||||
# Also copy into the usual local paths for convenience when run by hand.
|
||||
mkdir -p "$ROOT/bin" "$ROOT/apps/proxy"
|
||||
cp -f "$OUT/proxy-android-arm64" "$ROOT/bin/proxy-android-arm64"
|
||||
cp -f "$OUT/proxy-android-arm64" "$ROOT/apps/proxy/proxy-android-arm64"
|
||||
case "$(uname -s)" in
|
||||
Linux)
|
||||
arch="$(uname -m)"
|
||||
case "$arch" in
|
||||
x86_64) cp -f "$OUT/drm-linux-amd64" "$ROOT/bin/drm" ;;
|
||||
aarch64) cp -f "$OUT/drm-linux-arm64" "$ROOT/bin/drm" ;;
|
||||
esac
|
||||
;;
|
||||
Darwin)
|
||||
arch="$(uname -m)"
|
||||
case "$arch" in
|
||||
x86_64) cp -f "$OUT/drm-darwin-amd64" "$ROOT/bin/drm" ;;
|
||||
arm64) cp -f "$OUT/drm-darwin-arm64" "$ROOT/bin/drm" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
(
|
||||
cd "$OUT"
|
||||
if command -v sha256sum >/dev/null 2>&1; then
|
||||
sha256sum drm-* proxy-android-arm64 > SHA256SUMS.txt
|
||||
else
|
||||
shasum -a 256 drm-* proxy-android-arm64 > SHA256SUMS.txt
|
||||
fi
|
||||
)
|
||||
|
||||
echo "==> done ($VERSION)"
|
||||
ls -la "$OUT"
|
||||
Loading…
Add table
Add a link
Reference in a new issue