callowayproject / bump-my-version

A small command line tool to simplify releasing software by updating all version strings in your source code by the correct increment and optionally commit and tag the changes.
https://callowayproject.github.io/bump-my-version/
MIT License
349 stars 21 forks source link

Feature: conditional `search` and `replace` blocks #189

Closed Zeitsperre closed 5 months ago

Zeitsperre commented 6 months ago

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"
Zeitsperre commented 6 months ago

FYI @bzah

coordt commented 6 months ago

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.

wkoot commented 5 months ago

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.

coordt commented 5 months ago

@wkoot @Zeitsperre

I have working code in PR #189 . I'm going to update the docs more. I would love some feedback before I merge this.

wkoot commented 5 months ago

I assume you mean https://github.com/callowayproject/bump-my-version/pull/197, is it possible to publish a release candidate or temp version we can easily fetch from pypi? :)

coordt commented 5 months ago

@wkoot @Zeitsperre I have a pre-release available.

Zeitsperre commented 5 months ago

@coordt Thanks so much! I'll have time either today or tomorrow to give this a try!

wkoot commented 5 months ago

@wkoot @Zeitsperre I have a pre-release available.

Tested, seems to be working! I only used the exclude_bumps option though

Zeitsperre commented 5 months ago

Can confirm that it works for include-bumps!