From b2d6ebd382a3d1a8bd579b309c63fb7b0b0ae650 Mon Sep 17 00:00:00 2001 From: Hein Date: Thu, 8 Oct 2026 17:11:07 +0200 Subject: [PATCH] feat(Makefile): add release-version target for versioning --- Makefile | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 42e836b..4bd3e60 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ BIN_DIR := bin CMD := ./cmd/go-mdtopdf-helper TOMD_CMD := ./cmd/go-tomd -.PHONY: all build run run-tomd test lint format clean +.PHONY: all build run run-tomd test lint format clean release-version all: format lint test build @@ -29,3 +29,30 @@ format: clean: rm -rf $(BIN_DIR) + +# Bump the latest vMAJOR.MINOR.PATCH tag and push the new tag, which triggers the release workflow. +# make release-version patch bump (v1.0.0 -> v1.0.1) +# make release-version BUMP=minor minor bump (v1.0.1 -> v1.1.0) +# make release-version BUMP=major major bump (v1.1.0 -> v2.0.0) +# make release-version DRY_RUN=1 show the next version without tagging or pushing +BUMP ?= patch +release-version: + @set -e; \ + case "$(BUMP)" in patch|minor|major) ;; *) echo "BUMP must be patch, minor or major (got '$(BUMP)')" >&2; exit 1;; esac; \ + git fetch --tags --quiet; \ + latest=$$(git tag --list 'v*' --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | head -n1 || true); \ + latest=$${latest:-v0.0.0}; \ + ver=$${latest#v}; major=$${ver%%.*}; rest=$${ver#*.}; minor=$${rest%%.*}; patch=$${rest#*.}; \ + case "$(BUMP)" in \ + major) major=$$((major + 1)); minor=0; patch=0;; \ + minor) minor=$$((minor + 1)); patch=0;; \ + patch) patch=$$((patch + 1));; \ + esac; \ + next="v$$major.$$minor.$$patch"; \ + echo "Latest tag: $$latest -> next: $$next"; \ + if [ -n "$(DRY_RUN)" ]; then echo "Dry run: nothing tagged or pushed"; exit 0; fi; \ + if [ -n "$$(git status --porcelain)" ]; then echo "Working tree is not clean; commit or stash first" >&2; exit 1; fi; \ + if [ -n "$$(git rev-list '@{u}..HEAD' 2>/dev/null)" ]; then echo "HEAD has unpushed commits; push them first" >&2; exit 1; fi; \ + git tag -a "$$next" -m "Release $$next"; \ + git push origin "$$next"; \ + echo "Pushed $$next"