c4urself / bump2version

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

bumping up a stable part should not increment when the current version has a prerelease part #230

Open ecs-jnguyen opened 2 years ago

ecs-jnguyen commented 2 years ago

What I am trying to achieve

Hi I am trying to automate versioning and deployments of my package with a ci tool like github actions. When there is a push to my main branch I am trying to increment the minor version. There are 2 scenarios where I am pushing to my main branch (in this example the current version in the main branch is 1.0.0):

  1. Via merging a pull request from a release branch which is version 1.1.0-rc0. I expect this to increment to 1.1.0 after the merge.
  2. Via merging a pull request from hotfix branch, which branched from main. This branch has version 1.0.0 and I expect main to have version 1.1.0 after the merge. I don't want to increment the patch part for hot fixes, I prefer to only worry about the minor version.

I know that making changes to bump2version minor would create breaking changes for a lot of people that use it. Could we add a new option for major, minor, patch that behaves like so:

bumpversion.cfg file

[bumpversion]
current_version = 1.0.0-rc1
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<release_num>\d+)(\.(?P<dev>[a-z]+))?)?
serialize = 
    {major}.{minor}.{patch}-{release}{release_num}.{dev}+{$PKG_ID}
    {major}.{minor}.{patch}-{release}{release_num}
    {major}.{minor}.{patch}
message = Bump version: {new_version}

[bumpversion:part:release]
optional_value = ignore
first_value = rc
values = 
    rc
    ignore

[bumpversion:part:release_num]
first_value = 0

[bumpversion:part:dev]
optional_value = ignore
first_value = dev
values = 
    dev
    ignore
florisla commented 2 years ago

How would your preferred config file look, with the new feature added?

If I understand correctly, you'd want to bump release from rc to ignore, bit if it's already ignore, then when bumping it you would like to 'overflow' and increment patch instead.

So something like this?

[bumpversion:part:release]
optional_value = final
first_value = rc
overflow =
    final: patch
values = 
    rc
    final

You could also argue that when bumping final overflows to bumping patch, release should gets its first_value. As it always does when patch is bumped. So 1.0.0 would bump to to 1.0.1.rc0 instead of to 1.0.1. So that would require yet another configuration value (overflow_resets_part ?).