build: bump versions only on local master

A bump amends and tags the last commit, so made on a feature branch it
tags a commit that master may never contain. The targets now refuse any
branch but master, and a detached HEAD.
This commit is contained in:
Ansho Rei
2026-11-04 09:24:54 +01:00
parent 530676e3ac
commit 8f8004c205
2 changed files with 11 additions and 3 deletions
+10 -3
View File
@@ -113,6 +113,8 @@ branding: ## Regenerate the logo SVGs and render the PNGs (needs inkscape)
PACKAGE = $(shell awk -F'"' '/^\[package\]/{p=1;next} /^\[/{p=0} p && /^name *= *"/{print $$2; exit}' Cargo.toml)
CURRENT = $(shell awk -F'"' '/^\[package\]/{p=1;next} /^\[/{p=0} p && /^version *= *"/{print $$2; exit}' Cargo.toml)
METAINFO = flatpak/$(FLATPAK_ID).metainfo.xml
# Versions are only made here, so a tag never lands on a commit that is not on it.
BUMP_BRANCH = master
.PHONY: version
version: ## Print the current version
@@ -128,13 +130,18 @@ minor: bump ## Bump for a feature: amend into the last commit and tag it
major: bump ## Bump for a breaking change, decided by hand
# Folds the bump into the last commit and tags it, as one action, so there is
# never a bump without a tag or a tag without a bump. Refuses anything that
# would make rewriting that commit lose work, orphan a tag or need a force push,
# and a version CHANGELOG.md does not describe yet.
# never a bump without a tag or a tag without a bump. Refuses any branch but
# BUMP_BRANCH, anything that would make rewriting that commit lose work, orphan
# a tag or need a force push, and a version CHANGELOG.md does not describe yet.
.PHONY: bump
bump:
@set -e; \
if [ -z "$(BUMP)" ]; then echo "error: run make patch, make minor or make major" >&2; exit 1; fi; \
branch=$$(git symbolic-ref --quiet --short HEAD || true); \
if [ "$$branch" != "$(BUMP_BRANCH)" ]; then \
echo "error: versions are only bumped on local $(BUMP_BRANCH), and this is $${branch:-a detached HEAD}. Fast-forward $(BUMP_BRANCH) to this work, switch to it, then bump." >&2; \
exit 1; \
fi; \
if ! git rev-parse -q --verify HEAD >/dev/null 2>&1; then \
echo "error: no commits yet, so there is no commit to fold a version bump into. Commit first." >&2; \
exit 1; \