c4urself / bump2version

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

Allow version part to conditionally reset #190

Closed markmacode closed 4 months ago

markmacode commented 3 years ago

Reason

This will help some workflows better follow semantic versioning (semver) standards. With a semver of marjor.minor.patch, when also using alpha, beta, and rc parts for releases, there is no supported way to stop a patch bump from getting alpha attached to it. This is a problem as the patch part of a version may not need pre-releases in most cases, we can see this in the Python releases.

There may be a scenario in the workflow stated above where we want to release an alpha version of a patch. Although it would be considered an exceptional scenario, so an exceptional scenario should not be what happens by default.

Problem

# Example setup.cfg
[bumpversion]
current_version = 3.8.4
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<pre>[a-z]+)\.(?P<build>\d+))?
serialize = 
    {major}.{minor}.{patch}-{pre}.{build}
    {major}.{minor}.{patch}

[bumpversion:part:pre]
first_value = alpha
optional_value = gamma
values = 
    alpha
    beta
    rc
    gamma

[bumpversion:part:build]
first_value = 1

My version can now go in 3 possible directions from here, the patch bump cannot be supported in the config.

Proposed solution

Adding a reset_with argument that can list the parent parts that the target part will reset with when they are bumped.

# ...
[bumpversion:part:pre]
# ...
reset_with = 
    major
    minor
# ...

Considerations

This solution has a pitfall though. If there is a version of 3.8.5-beta.2, if the patch part is not in the reset_with list, then bumping the patch will go from 3.8.5-beta.2 -> 3.8.6-beta.2. I'm not sure of the cleanest way to avoid this, it seems like more configuration arguments would need to be added to avoid it.

Since this is in the theme of conditionally altering parts of a version based on the bumps of another part, a more scalable solution may be to include a feature that allows completely custom conditional alterations of the version. I would like for this to be explored and discussed since it would be a one-size-fits-all deal. But it seems like a really large feature, and I am not sure how to introduce that idea to the contributors of this project.

Current workarounds