Feature: conditional `search` and `replace` blocks
Closed this issue · 9 comments
- bump-my-version version: 0.21.0
- Python version: Any
- Operating System: All
Description
I've been running into a problem and was wondering how much of an implementation challenge this would be. In my changelog, I would love to make use of the search and replace functionality for automating the version entries a bit.
An example implementation (from a rendered cookiecutter template):
[[tool.bumpversion.files]]
filename = "CHANGES.rst"
search = """\
`Unreleased <https://github.com/audreyr/python_boilerplate>`_ (latest)
----------------------------------------------------------------------
"""
replace = """\
`Unreleased <https://github.com/audreyr/python_boilerplate>`_ (latest)
----------------------------------------------------------------------
Contributors:
Changes
^^^^^^^
* No change.
Fixes
^^^^^
* No change.
.. _changes_{new_version}:
`v{new_version} <https://github.com/audreyr/python_boilerplate/tree/{new_version}>`_
-----------------------------------------------------------------------------
"""
To break it down, this adds a new entry that for unreleased
and replaces the older unreleased
entry with the tagged version. My issue is when I'm using SemVer v2.0
(https://semver.org/spec/v2.0.0.html) and bumping the development version on every commit, e.g.:
v1.0.0
→ 1.0.1-dev0 (bump build)
→ 1.0.1-dev1 (bump build
→ 1.0.1 (bump release)
This triggers the replacement block on every operation, so I end up with multiple changelog blocks for each progressive non-release
bump. Not great.
What I'd like to happen
I'd love to see an option under the [[tool.bumpversion.files]]
entries to only do a replacement operation if a specific type of bump
operation is called (e.g. major
, minor
, patch
, but specifically release
in my case), e.g.:
[[tool.bumpversion.files]]
filename = "src/python_boilerplate/__init__.py"
search = "__version__ = \"{current_version}\""
replace = "__version__ = \"{new_version}\""
on = "release"
FYI @bzah
Your approach is interesting. It might be a bit before I can accomplish it.
What I currently do to avoid this problem is not have bump-my-version commit and tag. Then I can package the dev release but the version changes are not saved.
We'd also like to use such a feature, for example in the various replacements for a Quality-time release.
Ideally, the changelog itself should only be altered in case of a "final" release and not for release-candidates.
I have working code in PR #189 . I'm going to update the docs more. I would love some feedback before I merge this.
I assume you mean #197, is it possible to publish a release candidate or temp version we can easily fetch from pypi? :)
@wkoot @Zeitsperre I have a pre-release available.
@coordt Thanks so much! I'll have time either today or tomorrow to give this a try!
@wkoot @Zeitsperre I have a pre-release available.
Tested, seems to be working! I only used the exclude_bumps
option though
Can confirm that it works for include-bumps
!