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

103
scripts/build-release.sh Normal file
View 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"