From acd7c2f6991389c90d5cf65ded59ccd1997cc197 Mon Sep 17 00:00:00 2001 From: Hein Date: Mon, 12 Oct 2026 22:03:14 +0200 Subject: [PATCH] refactor(Makefile): simplify release-version logic and remove version-set --- Makefile | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 20ac9dc..11d5736 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ CONFIG_DIR := /etc/unitdore VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") LDFLAGS := -ldflags "-X github.com/warkanum/unitdore/cmd.version=$(VERSION)" -.PHONY: all build install uninstall test lint clean release-version version-set pkg-checksums +.PHONY: all build install uninstall test lint clean release-version pkg-checksums all: build @@ -42,15 +42,25 @@ lint: clean: rm -f $(BINARY) -## release-version: bump patch version, update source and package versions, commit, tag, and push +# VERSION only counts as a release version when given on the command line +# (it defaults to git describe for the build flags). +RELEASE_VERSION := $(if $(filter command line,$(origin VERSION)),$(patsubst v%,%,$(VERSION))) + +## release-version: bump version (patch, or VERSION=X.Y.Z), update source and package versions, commit, tag, and push release-version: - @CURRENT=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \ - MAJOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/'); \ - MINOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/'); \ - PATCH=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/'); \ - NEXT="v$$MAJOR.$$MINOR.$$((PATCH + 1))"; \ - PKGVER="$$MAJOR.$$MINOR.$$((PATCH + 1))"; \ - echo "Current: $$CURRENT → Next: $$NEXT"; \ + @if [ -n "$(RELEASE_VERSION)" ]; then \ + echo "$(RELEASE_VERSION)" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$$' || { echo "usage: make release-version [VERSION=X.Y.Z]"; exit 1; }; \ + PKGVER="$(RELEASE_VERSION)"; \ + else \ + CURRENT=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \ + MAJOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/'); \ + MINOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/'); \ + PATCH=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/'); \ + PKGVER="$$MAJOR.$$MINOR.$$((PATCH + 1))"; \ + fi; \ + NEXT="v$$PKGVER"; \ + if git rev-parse -q --verify "refs/tags/$$NEXT" >/dev/null; then echo "tag $$NEXT already exists"; exit 1; fi; \ + echo "Releasing $$NEXT"; \ scripts/bump-version.sh "$$PKGVER"; \ git add -A cmd/root.go pkg; \ git commit -m "chore(release): update package version to $$PKGVER"; \ @@ -58,12 +68,6 @@ release-version: git push origin HEAD "$$NEXT"; \ echo "Pushed $$NEXT — release workflow triggered" -## version-set: set version in source and package files, no commit/tag (make version-set NEW_VERSION=X.Y.Z) -version-set: - @echo "$(NEW_VERSION)" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$$' || { echo "usage: make version-set NEW_VERSION=X.Y.Z"; exit 1; } - scripts/bump-version.sh "$(NEW_VERSION)" - @echo "Version set to $(NEW_VERSION) — review with 'git diff', then commit" - ## pkg-checksums: fill the Void checksum from the published release (run after release) pkg-checksums: scripts/update-checksums.sh