4

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" )

Any hints on how to use bump2versions flags to achieve a custom version?

florisla
  • 12,668
  • 6
  • 40
  • 47
Totte Karlsson
  • 1,261
  • 1
  • 20
  • 55

1 Answers1

5

As of bump2version v1.0.1, it won't produce the syntax error anymore.

You should do the following:

  • Define a two separate parts for the 'test' and '1' parts of your version string. Let's call them 'release' and 'build'.
  • Configure the build part to have values and an optional_value.
  • Add a custom parse so that both new parts can be parsed from a version string.
  • Add multiple serialize options, so that a version number can exist with and without the two optional parts.

This is the config:

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

[bumpversion:part:release]
first_value = regular
optional_value = regular
values = 
    alpha
    beta
    rc
    test
    regular

[bumpversion:part:build]

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

[bumpversion:file:version.txt]

[bumpversion:file:define.txt]
search = #define MyAppVersion "{current_version}"
replace = #define MyAppVersion "{new_version}"

And this command succeeds:

bump2version.exe --verbose --new-version 1.0.17-test-1 bogus-part
florisla
  • 12,668
  • 6
  • 40
  • 47