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.
This commit is contained in:
+2
-1
@@ -32,7 +32,8 @@ COPY --chown=appuser:appuser pyproject.toml uv.lock README.md ./
|
|||||||
|
|
||||||
# Switch to appuser and install Python dependencies
|
# Switch to appuser and install Python dependencies
|
||||||
USER appuser
|
USER appuser
|
||||||
RUN uv sync --frozen
|
ARG VERSION=dev
|
||||||
|
RUN HATCH_VCS_PRETEND_VERSION=${VERSION} uv sync --frozen
|
||||||
|
|
||||||
# Copy application source
|
# Copy application source
|
||||||
COPY --chown=appuser:appuser src/ ./src/
|
COPY --chown=appuser:appuser src/ ./src/
|
||||||
|
|||||||
@@ -45,3 +45,27 @@ docker-clean:
|
|||||||
docker system prune -f
|
docker system prune -f
|
||||||
|
|
||||||
docker-restart: docker-down docker-up
|
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%=%)
|
||||||
|
|||||||
+5
-9
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "artifactapi"
|
name = "artifactapi"
|
||||||
version = "2.0.5"
|
dynamic = ["version"]
|
||||||
description = "Generic artifact caching system with support for various package managers"
|
description = "Generic artifact caching system with support for various package managers"
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
@@ -23,9 +23,12 @@ license = {text = "MIT"}
|
|||||||
artifactapi = "artifactapi.main:main"
|
artifactapi = "artifactapi.main:main"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["hatchling"]
|
requires = ["hatchling", "hatch-vcs"]
|
||||||
build-backend = "hatchling.build"
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
[tool.hatch.version]
|
||||||
|
source = "vcs"
|
||||||
|
|
||||||
[tool.hatch.metadata]
|
[tool.hatch.metadata]
|
||||||
allow-direct-references = true
|
allow-direct-references = true
|
||||||
|
|
||||||
@@ -40,11 +43,4 @@ dev = [
|
|||||||
"isort>=5.12.0",
|
"isort>=5.12.0",
|
||||||
"mypy>=1.6.0",
|
"mypy>=1.6.0",
|
||||||
"ruff>=0.1.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}"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user