From 6cc0e6a7e34678674a62da4b1c47810793317bb0 Mon Sep 17 00:00:00 2001 From: Jb DOYON Date: Thu, 6 Feb 2025 01:38:22 +0000 Subject: [PATCH 1/2] Fix 'make try' dynamic versioning selector Called wrong variable so no amount of flags disabling dyn version worked --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ce989d2..f0b55f3 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ try: --UNSAFE \ -d "description=A cool project" \ -d "python_version=${PYTHON_VERSION}" \ - -d "dynamic_version=${DYN_VERSION}" \ + -d "dynamic_versioning=${DYN_VERSION}" \ -d "project_name=${RANDOMIZED_PROJECT_NAME}" ${ARGS} # Get in there and run make cd template_expanded/ \ From 463cce2eaf6db2b77b171d63e97adf732e80136c Mon Sep 17 00:00:00 2001 From: Jb DOYON Date: Thu, 6 Feb 2025 01:40:45 +0000 Subject: [PATCH 2/2] Replace 'make release' with bump-my-version tool The Makefile does too much that is brittle! Simplify actual releases by moving bump-my-version tool to do the CHANGELOG udates. --- Makefile | 2 +- template/Makefile.j2 | 22 ++++++---------------- template/pyproject.toml.j2 | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index f0b55f3..c922f04 100644 --- a/Makefile +++ b/Makefile @@ -66,8 +66,8 @@ python-gitignore: # Make a release commit + tag, creating Changelog entry # Set BUMP variable to any of poetry-supported (major, minor, patch) # or number (1.2.3 etc), see 'poetry version' docs for details +# Variable BUMP defaults to 'patch' (v1.2.3 -> v1.2.4) .PHONY: release -# Default the bump to a patch (v1.2.3 -> v1.2.4) release: BUMP=patch release: # Set the new version Makefile variable after the version bump diff --git a/template/Makefile.j2 b/template/Makefile.j2 index 9b1b6f4..ac60ec9 100644 --- a/template/Makefile.j2 +++ b/template/Makefile.j2 @@ -81,24 +81,14 @@ docker-build-release: docker-build-dev: docker build -t ${DOCKER_IMAGE_NAME}-dev . -## Make a release commit + tag, creating Changelog entry -## Set BUMP variable to any of poetry-supported (major, minor, patch) -## or number (1.2.3 etc), see 'poetry version' docs for details -## Default the bump to a patch (v1.2.3 -> v1.2.4) -BUMP=patch +# Make a release commit + tag, creating Changelog entry +# Set BUMP variable to any of poetry-supported (major, minor, patch) +# or number (1.2.3 etc), see 'poetry version' docs for details +# Variable BUMP defaults to 'patch' (v1.2.3 -> v1.2.4) .PHONY: release +BUMP=patch release: -# Set the new version Makefile variable after the version bump - $(eval NEW_VERSION := $(shell poetry version --short{% if dynamic_version %} --dry-run{% endif %} ${BUMP})) - $(eval TMP_CHANGELOG := $(shell mktemp)) - sed \ - "s/\(## \[Unreleased\]\)/\1\n\n## v${NEW_VERSION} - $(shell date +%Y-%m-%d)/" \ - CHANGELOG.md > ${TMP_CHANGELOG} - mv --force ${TMP_CHANGELOG} CHANGELOG.md - git add CHANGELOG.md{% if not dynamic_version %} pyproject.toml{% endif %} - git commit -m "Bump to version v${NEW_VERSION}" - git tag --annotate "v${NEW_VERSION}" \ - --message "Release v${NEW_VERSION}" + bump-my-version bump ${BUMP} ## Less commonly used commands diff --git a/template/pyproject.toml.j2 b/template/pyproject.toml.j2 index 11f41d0..3284c00 100644 --- a/template/pyproject.toml.j2 +++ b/template/pyproject.toml.j2 @@ -93,3 +93,23 @@ pydocstyle = {convention = "google"} [tool.mypy] python_version = "{{python_version}}" check_untyped_defs = true + +[tool.bumpversion] +allow_dirty = false +commit = true +message = "Bump to version v{new_version}" +tag = true +tag_message = "Release v{new_version}" +setup_hooks = ["make"] + +[[tool.bumpversion.files]] +filename = "CHANGELOG.md" +search = "## [Unreleased]" +replace = "## [Unreleased]\n\n## v{new_version} - {now:%Y-%m-%d}" + +{%- if not dynamic_versioning %} +[[tool.bumpversion.files]] +filename = "pyproject.toml" +search = 'version = "{current_version}"' +replace = 'version = "{new_version}"' +{% endif -%}