feat: add make patch, minor and major, and show the running version

The version had never moved from 0.1.0, so a build on the Deck could not
be matched to what it contains. The bump targets follow frig and
worklane: write the new version, amend it into the last commit and tag
it. Here they also add a release to the Flatpak metainfo, and refuse a
version that CHANGELOG.md, new in this commit, has no entry for.

The version is shown at the bottom left of every screen, the login
screen included.
This commit is contained in:
Ansho Rei
2026-11-04 09:23:33 +01:00
parent 3cb810bbd5
commit 530676e3ac
8 changed files with 122 additions and 2 deletions
+72
View File
@@ -108,6 +108,78 @@ branding: ## Regenerate the logo SVGs and render the PNGs (needs inkscape)
render steam-logo 1280 720 steam-logo-1280x720; \
render steam-icon 256 256 steam-icon-256
# Versioning. Cargo.toml's [package] version is the one source: the app shows
# it, and the bump writes it to Cargo.lock and the Flatpak metainfo too.
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
.PHONY: version
version: ## Print the current version
@echo $(CURRENT)
patch: BUMP = patch
minor: BUMP = minor
major: BUMP = major
.PHONY: patch minor major
patch: bump ## Bump for a bug fix: amend into the last commit and tag it
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.
.PHONY: bump
bump:
@set -e; \
if [ -z "$(BUMP)" ]; then echo "error: run make patch, make minor or make major" >&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; \
fi; \
if [ -n "$$(git status --porcelain)" ]; then \
echo "error: working tree is dirty. Commit or stash first, and decide whether that work belongs in this version:" >&2; \
git status --short >&2; \
exit 1; \
fi; \
if [ -n "$$(git tag --points-at HEAD)" ]; then \
echo "error: HEAD is already tagged $$(git tag --points-at HEAD | paste -sd' '). Amending it would leave that tag on an orphaned commit. Commit something first." >&2; \
exit 1; \
fi; \
if upstream=$$(git rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>/dev/null) && \
git merge-base --is-ancestor HEAD "$$upstream" 2>/dev/null; then \
echo "error: HEAD is already pushed to $$upstream. Amending it would need a force push. Commit something first." >&2; \
exit 1; \
fi; \
current="$(CURRENT)"; \
if [ -z "$$current" ]; then echo "error: no version found in the [package] table of Cargo.toml" >&2; exit 1; fi; \
new=$$(echo "$$current" | awk -F. -v kind=$(BUMP) '{ \
if (NF != 3) exit 1; \
if (kind == "patch") printf "%d.%d.%d\n", $$1, $$2, $$3 + 1; \
else if (kind == "minor") printf "%d.%d.0\n", $$1, $$2 + 1; \
else printf "%d.0.0\n", $$1 + 1 }'); \
if [ -z "$$new" ]; then echo "error: cannot bump version '$$current': expected major.minor.patch" >&2; exit 1; fi; \
if git rev-parse -q --verify "refs/tags/v$$new" >/dev/null; then \
echo "error: tag v$$new already exists" >&2; exit 1; \
fi; \
if ! grep -q "^## v$$new " CHANGELOG.md 2>/dev/null; then \
echo "error: CHANGELOG.md has no '## v$$new' entry. Add one to the last commit first (git commit --amend)." >&2; \
exit 1; \
fi; \
today=$$(date +%Y-%m-%d); \
awk -v v="$$new" '/^\[package\]/{p=1} /^\[/ && !/^\[package\]/{p=0} p && /^version *= *"/{sub(/"[^"]*"/, "\"" v "\"")} {print}' Cargo.toml > Cargo.toml.bump; \
mv Cargo.toml.bump Cargo.toml; \
awk -v v="$$new" -v pkg="$(PACKAGE)" '$$0 == "name = \"" pkg "\""{f=1} f && /^version = "/{sub(/"[^"]*"/, "\"" v "\""); f=0} {print}' Cargo.lock > Cargo.lock.bump; \
mv Cargo.lock.bump Cargo.lock; \
awk -v v="$$new" -v d="$$today" '{print} /^ *<releases>/{print " <release version=\"" v "\" date=\"" d "\"/>"}' $(METAINFO) > $(METAINFO).bump; \
mv $(METAINFO).bump $(METAINFO); \
git add Cargo.toml Cargo.lock $(METAINFO); \
git commit --quiet --amend --no-edit; \
git tag -a "v$$new" -m "v$$new"; \
echo "$$current -> $$new, tagged v$$new on $$(git rev-parse --short HEAD) ($$(git log -1 --format=%s))"
.PHONY: clean
clean: ## Remove build output, screenshots and scratch config
cargo clean