c4urself / bump2version

Version-bump your software with a single command
https://pypi.python.org/pypi/bump2version
MIT License
1.06k stars 133 forks source link

Unexpected inconsistency with version affix #211

Open JonZeolla opened 3 years ago

JonZeolla commented 3 years ago

I have a fairly basic bumpversion setup for a project using SemVer (seisollc/easy_infra#79). I noticed that the commit_message from the config does not seem to be honored, and the resulting commit was inconsistent, where one file's version kept a -dirty append, but another file did not. Both issues were consistent between running it with pipenv run invoke release minor and bumpversion minor at the CLI (macOS w/zsh)

Here is my setup.cfg:

[bumpversion]
current_version = 0.7.1-dirty
commit_message = "Automatically generated release {new_version}"
commit = True
tag = True
push = True
...

[bumpversion:file:easy_infra/__init__.py]

[bumpversion:file:setup.cfg]

The inconsistent commit:

Screen Shot 2021-04-06 at 10 43 57 AM

This is a simplified version of how I'm running it, detailed in the PR linked above:

from bumpversion.cli import main as bumpversion

@task(pre=[test])
def release(c, release_type):  # pylint: disable=unused-argument
    """Make a new release of easy_infra"""
    if REPO.head.is_detached:
        LOG.error("In detached HEAD state, refusing to release")
        sys.exit(1)

    if release_type not in ["major", "minor", "patch"]:
        LOG.error("Please provide a release type of major, minor, or patch")
        sys.exit(1)

    bumpversion([release_type])
florisla commented 3 years ago

The inconsistency is caused by several non-intuitive factors here.

First, you can't really add setup.cfg as a bumpversion:file.
Setup.cfg contains your bump2version configuration, and bump2version will maintain the version value there. So you can drop this line from your config: [bumpversion:file:setup.cfg] and nothing will change.

Next, you don't have a custom parse expression in your config to accept the -dirty suffix. So it's not properly recognized -- actually bump2version should raise an error. Your new version becomes 8.0.0 without any suffix, so that's what's being written to the setup.cfg file.

And finally, bump2version's replacement does not check for word boundaries. So it finds the string 0,7.1 in 0.7.1-dirty and replaces only the 0.7.1 section with 8.0.0. It leaves the -dirty suffix untouched.

Side note: you can drop the pylint: disable=unused-argument in your tasks file by adding a leading underscore to the c argument.

JonZeolla commented 3 years ago

@florisla thank you for the explanation. If you'd like I can leave this open, but I'm also fine to close it.