From cf854a2acebf1bbbb58728fb75906a8722946c12 Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Sat, 25 Apr 2026 16:53:37 +1000 Subject: [PATCH 1/2] chore: derive version from git tags via hatch-vcs Replace hardcoded version in pyproject.toml with hatch-vcs so the package version is read from git tags at build time. Dockerfile accepts a VERSION build arg and passes it as HATCH_VCS_PRETEND_VERSION for builds without a git checkout. Makefile _tag target now rebuilds the container with the correct version automatically. --- Dockerfile | 3 ++- Makefile | 24 ++++++++++++++++++++++++ pyproject.toml | 14 +++++--------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index d3ad37d..d24cf6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,8 @@ COPY --chown=appuser:appuser pyproject.toml uv.lock README.md ./ # Switch to appuser and install Python dependencies USER appuser -RUN uv sync --frozen +ARG VERSION=dev +RUN HATCH_VCS_PRETEND_VERSION=${VERSION} uv sync --frozen # Copy application source COPY --chown=appuser:appuser src/ ./src/ diff --git a/Makefile b/Makefile index cb85240..175abb4 100644 --- a/Makefile +++ b/Makefile @@ -45,3 +45,27 @@ docker-clean: docker system prune -f docker-restart: docker-down docker-up + +# Bump helpers — reads the latest semver tag and creates the next one. +# If no tag exists yet, starts from v0.0.0. +_LATEST := $(shell git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | head -1) +_BASE := $(if $(_LATEST),$(_LATEST),v0.0.0) +_MAJ := $(shell echo $(_BASE) | sed 's/^v//' | cut -d. -f1) +_MIN := $(shell echo $(_BASE) | sed 's/^v//' | cut -d. -f2) +_PAT := $(shell echo $(_BASE) | sed 's/^v//' | cut -d. -f3) + +patch: + @NEW=v$(_MAJ).$(_MIN).$(shell expr $(_PAT) + 1); \ + git tag $$NEW && echo "Tagged $$NEW" && $(MAKE) _tag TAG=$$NEW + +minor: + @NEW=v$(_MAJ).$(shell expr $(_MIN) + 1).0; \ + git tag $$NEW && echo "Tagged $$NEW" && $(MAKE) _tag TAG=$$NEW + +major: + @NEW=v$(shell expr $(_MAJ) + 1).0.0; \ + git tag $$NEW && echo "Tagged $$NEW" && $(MAKE) _tag TAG=$$NEW + +_tag: + git push origin $(TAG) + docker-compose build --no-cache --build-arg VERSION=$(TAG:v%=%) diff --git a/pyproject.toml b/pyproject.toml index a2130a7..5aed9d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "artifactapi" -version = "2.0.5" +dynamic = ["version"] description = "Generic artifact caching system with support for various package managers" dependencies = [ @@ -23,9 +23,12 @@ license = {text = "MIT"} artifactapi = "artifactapi.main:main" [build-system] -requires = ["hatchling"] +requires = ["hatchling", "hatch-vcs"] build-backend = "hatchling.build" +[tool.hatch.version] +source = "vcs" + [tool.hatch.metadata] allow-direct-references = true @@ -40,11 +43,4 @@ dev = [ "isort>=5.12.0", "mypy>=1.6.0", "ruff>=0.1.0", - "bump-my-version>=1.2.0", ] - -[tool.bumpversion] -current_version = "2.0.5" -commit = true -tag = true -message = "Bump version: {current_version} → {new_version}" From 33e7365a88931444a7f4bb8f38124cec5f32f09d Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Sat, 25 Apr 2026 17:31:36 +1000 Subject: [PATCH 2/2] fix: set SETUPTOOLS_SCM_PRETEND_VERSION in Dockerfile for hatch-vcs --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d24cf6f..f259f52 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,9 @@ COPY --chown=appuser:appuser pyproject.toml uv.lock README.md ./ # Switch to appuser and install Python dependencies USER appuser ARG VERSION=dev -RUN HATCH_VCS_PRETEND_VERSION=${VERSION} uv sync --frozen +ENV HATCH_VCS_PRETEND_VERSION=${VERSION} \ + SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} +RUN uv sync --frozen # Copy application source COPY --chown=appuser:appuser src/ ./src/