mirror of
https://github.com/anand34577/ferrum.git
synced 2026-09-11 21:38:59 +00:00
8170b5c354
scripts/build.sh, get.sh, and scripts/linux/*.sh had lost their executable bit in git (core.fileMode=false on this Windows checkout meant a local chmod +x never made it into the index) — release.yml invokes scripts/build.sh directly rather than via `bash`, so the CI job failed immediately with exit code 126 (permission denied). Also invoke it via `bash` explicitly as a second line of defense, and fix the zip-install step's `||`/`&&` operator precedence (it always ran apt-get regardless of whether zip was already present, harmless but not what it looked like). Verified locally end-to-end: scripts/build.sh all now builds and packages all 6 platform targets and every checksum verifies.
76 lines
2.5 KiB
Bash
Executable File
76 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Builds the frontend and cross-compiles the ferrum binary for one or more
|
|
# platforms, then packages each as a .tar.gz (or .zip on Windows) under
|
|
# dist/ alongside a sha256sum manifest. Used locally and by
|
|
# .github/workflows/release.yml — CI just runs this script so a local build
|
|
# always matches what a tagged release publishes.
|
|
#
|
|
# Usage:
|
|
# scripts/build.sh # build for the current GOOS/GOARCH
|
|
# scripts/build.sh linux/amd64 windows/amd64 darwin/arm64
|
|
# scripts/build.sh all # every target below
|
|
set -euo pipefail
|
|
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
|
|
|
VERSION="${VERSION:-$(git describe --tags --always --dirty 2>/dev/null || echo dev)}"
|
|
COMMIT="${COMMIT:-$(git rev-parse --short HEAD 2>/dev/null || echo none)}"
|
|
DATE="${DATE:-$(date -u +%Y-%m-%dT%H:%M:%SZ)}"
|
|
LDFLAGS="-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}"
|
|
|
|
ALL_TARGETS=(linux/amd64 linux/arm64 windows/amd64 windows/arm64 darwin/amd64 darwin/arm64)
|
|
|
|
targets=("$@")
|
|
if [ ${#targets[@]} -eq 0 ]; then
|
|
targets=("$(go env GOOS)/$(go env GOARCH)")
|
|
elif [ "${targets[0]}" = "all" ]; then
|
|
targets=("${ALL_TARGETS[@]}")
|
|
fi
|
|
|
|
echo "==> Building frontend (web/dist)"
|
|
( cd web && npm ci && npm run build )
|
|
|
|
rm -rf dist
|
|
mkdir -p dist
|
|
|
|
echo "==> Version ${VERSION} (${COMMIT}, ${DATE})"
|
|
|
|
for target in "${targets[@]}"; do
|
|
goos="${target%/*}"
|
|
goarch="${target#*/}"
|
|
ext=""
|
|
[ "$goos" = "windows" ] && ext=".exe"
|
|
|
|
out_dir="dist/ferrum_${VERSION}_${goos}_${goarch}"
|
|
mkdir -p "$out_dir"
|
|
bin="$out_dir/ferrum${ext}"
|
|
|
|
echo "==> Building ${goos}/${goarch}"
|
|
CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" go build \
|
|
-trimpath -ldflags "$LDFLAGS" \
|
|
-o "$bin" ./cmd/ferrum
|
|
|
|
cp README.md LICENSE config.example.yaml "$out_dir/"
|
|
if [ "$goos" = "linux" ]; then
|
|
mkdir -p "$out_dir/packaging/systemd"
|
|
cp packaging/systemd/ferrum.service "$out_dir/packaging/systemd/"
|
|
cp scripts/linux/install.sh scripts/linux/uninstall.sh "$out_dir/"
|
|
elif [ "$goos" = "windows" ]; then
|
|
cp scripts/windows/install-service.ps1 scripts/windows/uninstall-service.ps1 "$out_dir/"
|
|
fi
|
|
|
|
( cd dist
|
|
base="ferrum_${VERSION}_${goos}_${goarch}"
|
|
if [ "$goos" = "windows" ]; then
|
|
zip -qr "${base}.zip" "$base"
|
|
else
|
|
tar -czf "${base}.tar.gz" "$base"
|
|
fi
|
|
rm -rf "$base"
|
|
)
|
|
done
|
|
|
|
( cd dist && sha256sum ferrum_* > checksums.txt 2>/dev/null || shasum -a 256 ferrum_* > checksums.txt )
|
|
|
|
echo "==> Done. Artifacts in dist/:"
|
|
ls -la dist
|