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

Add support for premajor, preminor, prepatch, etc. #63

Open glutanimate opened 5 years ago

glutanimate commented 5 years ago

This is inspired by npm's semver increments. To quote the node docs:

premajor in one call will bump the version up to the next major version and down to a prerelease of that major version. preminor, and prepatch work the same way.

E.g.:

$ version
0.3.5
$ bumpversion patch
Bumped from 0.3.5 to 0.3.6
$ bumpversion preminor
Bumped from 0.3.6 to 0.4.0-dev.0

From what I understand it's not possible to replicate this with bumpversion without using --new-version at some point. Either you always walk through the pre-release steps or you don't walk through them at all.

For instance, this config:

[bumpversion]
current_version = 0.3.5
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?(\.(?P<build>\d+))?
serialize = 
    {major}.{minor}.{patch}-{release}.{build}
    {major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = gamma
values = 
    dev
    alpha
    beta
    gamma

would behave as follows:

$ version
0.3.5
$ bumpversion patch
Bumped from 0.3.5 to 0.3.6-dev.0
$ bumpversion minor
Bumped from 0.3.6-dev.0 to 0.4.0-dev.0

In many scenarios this is not desirable, as you would want to be able to push out a patch without having to walk through the pre-release steps (e.g. dev → alpha →...).

The only other option is to add first_value = gamma under [bumpversion:part:release] which would change the behavior as follows:

$ version
0.3.5
$ bumpversion patch
Bumped from 0.3.5 to 0.3.6
$ bumpversion minor
Bumped from 0.3.6 to 0.4.0

But to switch to a pre-release you would then have to use --new-version:

$ bumpversion part --new-version=0.4.0-dev.0
Bumped from 0.3.6 to 0.4.0-dev.0

It would be nice to have a shorthand for this rather than having to manually type the release.

P.S.: Thanks for all your work on bump2version! It's nice to see this project alive and thriving.

florisla commented 5 years ago

I have a similar flow, with the same inconvenience. The limitation being that you can bump only one part at once unless you specify the full new-version (which is error-prone).

The node semver preminor approach requires the tool to know what is a 'pre' value for a part, which bump2version currently does not know.

I think it would be most flexible if bump2version would support multiple part arguments at once, and also allows you to choose between "bump to the next value like usually" or "bump to the value which I explicitly choose here".

A command-line interface like this would be really sweet:

# specify an explicit value for one specific part
bump2version release=gamma
bump2version --part release=gamma

# bump multiple parts in one go
bump2version --part patch --part release
# bump two parts, with one a specific value
bump2version --part patch --part release=gamma
c4urself commented 4 years ago

Definitely open to this.