build / build (push) Failing after 6m36s
core.filemode=false on this Windows checkout dropped the +x bit on the initial commit. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
57 lines
2.0 KiB
Bash
Executable File
57 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Builds the nasmon binary (linux/amd64, static) and packs it into .deb and .rpm with nfpm.
|
|
# Output: dist/nasmon_<version>_amd64.deb and dist/nasmon-<version>.<arch>.rpm
|
|
#
|
|
# One-time setup:
|
|
# go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
|
|
#
|
|
# Usage:
|
|
# ./build.sh # version from git tag, or 0.1.0+<timestamp>
|
|
# VERSION=0.2.0 ./build.sh
|
|
# TEST=1 ./build.sh # run go vet + go test first
|
|
|
|
set -euo pipefail
|
|
|
|
root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
dist="$root/dist"
|
|
|
|
for tool in go nfpm; do
|
|
command -v "$tool" >/dev/null 2>&1 || { echo "$tool not found - see the setup notes at the top of build.sh" >&2; exit 1; }
|
|
done
|
|
|
|
version="${VERSION:-}"
|
|
if [ -z "$version" ] && command -v git >/dev/null 2>&1; then
|
|
tag="$(cd "$root" && git describe --tags --always --dirty 2>/dev/null || true)"
|
|
if [[ "$tag" =~ ^v?([0-9]+\.[0-9]+\.[0-9]+)(-([0-9]+)-g([0-9a-f]+))?(-dirty)?$ ]]; then
|
|
version="${BASH_REMATCH[1]}"
|
|
[ -n "${BASH_REMATCH[3]}" ] && version+="+git${BASH_REMATCH[3]}.${BASH_REMATCH[4]}"
|
|
[ -n "${BASH_REMATCH[5]}" ] && version+=".dirty"
|
|
fi
|
|
fi
|
|
[ -z "$version" ] && version="0.1.0+$(date +%Y%m%d.%H%M)"
|
|
|
|
mkdir -p "$dist"
|
|
|
|
if [ "${TEST:-}" = "1" ]; then
|
|
echo "==> go vet / go test"
|
|
(cd "$root" && go vet ./... && go test ./...)
|
|
fi
|
|
|
|
echo "==> Building nasmon $version (linux/amd64)"
|
|
(cd "$root" && GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
|
|
go build -trimpath -ldflags "-s -w -X main.version=$version" -o "$dist/nasmon" ./cmd/nasmon)
|
|
|
|
echo "==> Packaging .deb"
|
|
rm -f "$dist"/nasmon_*.deb
|
|
(cd "$root/packaging" && NASMON_VERSION="$version" nfpm package -f nfpm.yaml -p deb -t "$dist")
|
|
|
|
echo "==> Packaging .rpm"
|
|
rm -f "$dist"/nasmon-*.rpm
|
|
(cd "$root/packaging" && NASMON_VERSION="$version" nfpm package -f nfpm.yaml -p rpm -t "$dist")
|
|
|
|
for pkg in "$dist"/nasmon*.deb "$dist"/nasmon*.rpm; do
|
|
[ -e "$pkg" ] || continue
|
|
size_mb=$(du -m "$pkg" | cut -f1)
|
|
echo "==> $pkg (${size_mb} MB)"
|
|
done
|