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

bump2version does not create proper custom version #147

Open TotteKarlsson opened 4 years ago

TotteKarlsson commented 4 years ago

We use bump2version to version our builds and releases in Gitlab, using a simple major.minor.patch (1.1.17) format.

Sometimes, however, it's useful to create versions outside the regular pipeline, with a custom version format, e.g. 1.1.17-test-1.

Trying bump2versions command line flags like this on a current version of 1.1.17:

bump2version.exe --search 1.0.17 --replace 1.0.17-testing --verbose --new-version 1.0.17-test-1 part Don't give any errors, but produces the wrong version-string in all files where the version-string is being managed.

The .bumpversion.cfg file looks like this:

[bumpversion]
current_version = 1.0.17

[bumpversion:file:CMakeLists.txt]
search = MVR_VERSION "{current_version}"
replace = MVR_VERSION "{new_version}"

[bumpversion:file:VERSION.txt]
search = {current_version}
replace = {new_version}

[bumpversion:file:installer/mvr.iss]
search = #define MyAppVersion "{current_version}"
replace = #define MyAppVersion "{new_version}"

In each file where the version-string is supposed to be changed, the change looks like this:

set(MVR_VERSION "MVR_VERSION "1.0.17"" ) which is not right. Proper search/replace would be

set(MVR_VERSION "1.0.17-test-1" )

mauvilsa commented 4 years ago

@TotteKarlsson you can make this work with a small modification of your .bumpversion.cfg file by redefining the parse and serialize options in the [bumpversion] section as follows:

[bumpversion]
current_version = 1.0.17
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-zA-Z0-9_.-]+))?
serialize = 
    {major}.{minor}.{patch}-{release}
    {major}.{minor}.{patch}

Even though this works it would be good if the bump2version command would fail if the value in new-version does not match according to parse, instead of silently incorrectly replacing stuff.

florisla commented 3 years ago

it would be good if the bump2version command would fail if the value in new-version does not match according to parse, instead of silently incorrectly replacing stuff.

This is actually the case since version 1.0.1 (#127).

@TotteKarlsson is this now working for you?

janluke commented 3 years ago

I've just run bumpversion --new-version 0.6.1-dev --no-tag patch with current_version = 0.6.0. Bumpversion replaced 0.6.0 with just 0.6.1 in all relevant files, even though setup.cfg was correctly updated with current_version = 0.6.1-dev and the commit message contains 0.6.1-dev as well.

Using bumpversion 1.0.1 with no custom configuration for parse and serialize.