bump2version
bump2version copied to clipboard
[Question] How to use bump version to add PR number to version
Hi I am trying to use bump2version to automate versioning during a CI build. My use case is to mark the package version with a pull request number when opening a pull request and to update the minor version when pushing to the master branch.
I have gotten it to work, during my master build, I am making 2 commands to increment the version. However I am wondering if there is a more elegant way to do this
What I'm trying to achieve
- I start off with some version, for example 1.0.0
- I open a pull request number 123 to the main branch
master, then I want bump2version to modify the version to be1.1.0-beta123(I will not commit change and push to github) - When I merge pull request 123 to master, then I want bump2version to modify the version to
1.1.0. Then my CI tool will push the.bumpversion.cfgandsetup.pyfile to github (I am handling the additional git push webhook to stop incrementing version) - Repeat
How I've accomplished this so far
Step 1 Open a pull request number 123 to master
CI tool commands
$ export PR_NUM=123
$ bump2version minor # results in: 1.0.0 --> 1.1.0-beta123
$ push package to pypi repo
Step 2 pull request number 123 into master
CI tool commands
$ export PR_NUM="ignore"
$ bump2version minor # results in: 1.0.0 --> 1.1.0-betaignore
$ bump2version release # results in: 1.1.0-betaignore --> 1.1.0
$ push package to pypi repo
$ git commit / tag / push
.bumpversion.cfg I have configured
[bumpversion]
current_version = 1.0.0
False = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
serialize =
{major}.{minor}.{patch}-{release}{$PR_NUM}
{major}.{minor}.{patch}
[bumpversion:part:release]
optional_value = ignore
first_value = beta
values =
beta
ignore
[bumpversion:file:setup.py] # setup.py also starts version at 1.0.0
I think currently this is not possible.
Each bump2version invocation can only bump one part. It can not change minor and release in one go.
Ugly workarounds are to use --new-version (which forces you to handle things manually) or to put the 'beta' string also in the environment variable.
One way I've gotten this to work is for Step 2 in the original post, do the following:
$ export PR_NUM="ignore"
$ bump2version minor --serialize ""major}.{minor}.{patch}" # results in: 1.0.0 --> 1.1.0