`make release` cross-compiles the CLI for the four machines it is actually run on and writes SHA256SUMS beside them. It refuses an untagged tree, an edited one, and a commit that is past the tag. Each of those produces a binary whose `hpcod version` is not the release - a bare revision, or one carrying +dirty - and the time to find that out is before the file is uploaded, not when someone is trying to work out which binary is on a host. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
57 lines
2.2 KiB
Makefile
57 lines
2.2 KiB
Makefile
BIN := hpcod
|
|
|
|
# The release tag, for `hpcod version`. Deliberately without --always: with no
|
|
# tag in sight this is empty, and the binary reports its revision alone rather
|
|
# than a made-up version. --dirty is what stops a local edit from claiming to
|
|
# be the release.
|
|
VERSION := $(shell git describe --tags --dirty 2>/dev/null)
|
|
LDFLAGS := -s -w -X main.releaseVersion=$(VERSION)
|
|
|
|
# Where the release artefacts land, and which machines they are for: the
|
|
# control plane runs on Linux, the CLI is driven from whatever the operator
|
|
# sits in front of.
|
|
DIST := dist
|
|
PLATFORMS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
|
|
|
|
.PHONY: all linux test clean deploy-portal release
|
|
all: linux
|
|
|
|
linux:
|
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags="$(LDFLAGS)" -o $(BIN)-linux-amd64 ./cmd/hpcod
|
|
@ls -lh $(BIN)-linux-amd64
|
|
|
|
test:
|
|
go vet ./... && go test ./...
|
|
|
|
# The portal runs on the Caddy host: it needs to reach every Proxmox API, and
|
|
# binding to loopback there means Caddy is the only thing that can reach it.
|
|
deploy-portal: linux
|
|
scp -q $(BIN)-linux-amd64 web-frontend:/tmp/hpcod
|
|
ssh web-frontend 'sudo install -m 0755 /tmp/hpcod /usr/local/bin/hpcod && sudo systemctl restart hpcod-portal && systemctl is-active hpcod-portal'
|
|
|
|
# Build every platform from one tag, and record what was built.
|
|
#
|
|
# It refuses to run from an untagged or edited tree. A release artefact whose
|
|
# version is a bare revision, or carries +dirty, is not a release - and the
|
|
# time to find that out is before it is uploaded, not when someone asks which
|
|
# binary is on a host.
|
|
release:
|
|
@case "$(VERSION)" in \
|
|
"") echo "no tag here: git tag -a vX.Y.Z first"; exit 1 ;; \
|
|
*dirty) echo "working tree is dirty: $(VERSION)"; exit 1 ;; \
|
|
*-*-g*) echo "not on a tag: $(VERSION)"; exit 1 ;; \
|
|
esac
|
|
rm -rf $(DIST) && mkdir -p $(DIST)
|
|
@for p in $(PLATFORMS); do \
|
|
os=$${p%/*}; arch=$${p#*/}; out=$(DIST)/$(BIN)-$(VERSION)-$$os-$$arch; \
|
|
echo " $$out"; \
|
|
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 \
|
|
go build -trimpath -ldflags="$(LDFLAGS)" -o $$out ./cmd/hpcod || exit 1; \
|
|
done
|
|
cd $(DIST) && shasum -a 256 * > SHA256SUMS
|
|
@echo && cat $(DIST)/SHA256SUMS
|
|
|
|
clean:
|
|
rm -f $(BIN)-linux-amd64
|
|
rm -rf $(DIST)
|