callowayproject / bump-my-version

A small command line tool to simplify releasing software by updating all version strings in your source code by the correct increment and optionally commit and tag the changes.
https://callowayproject.github.io/bump-my-version/
MIT License
242 stars 17 forks source link

current_version and tag_name need to match exactly #74

Closed skipperTux closed 1 day ago

skipperTux commented 8 months ago

Description

Sorry for my late response with regards to Issue #14. I tested the current version but I still have (three new) issues, separating those into three different GitHub issues. This first issues is related to the new scm_info.current_version looking for tag names in the git repository. When the tag_name does not match the current_version, an error pops up: "{current_version} does not match last tagged version". I think this is related to this check in config.py.

Maybe this is on purpose, however it prevents renaming tags into something like tag_name = "v{new_version}" or - as we do in our monorepo - "app/{new_version}". It seems to work when setting current_version = "app/3.5.0-beta+build.1038" in the config. Not sure though if parsing and serializing is affected by this pattern.

An idea to make this more flexible would be to either check only the version part in the tag, however making the tag_pattern more complex, or having an option to disable the git tag checking in the config.

What I Did

.bumpversion.toml (excerpt, the files part is not relevant for this issue).

[tool.bumpversion]
current_version = "3.5.0-beta+build.1038"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(-(?P<release>[0-9A-Za-z]+))?(\\+build\\.(?P<build>.[0-9A-Za-z]+))?"
serialize = [
    "{major}.{minor}.{patch}-{release}+build.{build}",
    "{major}.{minor}.{patch}+build.{build}"
]
commit = true
message = "Bump version: {current_version} -> {new_version}"
tag = false
tag_name = "app/{new_version}"
tag_message = "Version app/{new_version}"
allow_dirty = true

[tool.bumpversion.parts.release]
values = [
    "beta",
    "rc",
    "final"
]
optional_value = "final"

[tool.bumpversion.parts.build]
first_value = 1000
independent = true
$ bump-my-version.exe bump --tag --no-commit patch
Specified version (3.5.0-beta+build.1038) does not match last tagged version (app/3.5.0-beta+build.1038)
skipperTux commented 3 days ago

We are experiencing a weird regression with this issue. With regards to our existing repository, we have tags for our app, like

$ git tag --list
app/3.5.0-beta+build.1038
[...]
app/4.0.2+build.1045
app/4.0.2+build.1046

Running bump-my-version.exe bump --tag --commit --dry-run patch all is Ok. Running bump without dry-run increases version, patch part. Running the first command again returns Specified version (4.0.3-beta+build.1047) does not match last tagged version (app/4.0.3-beta+build.1047). This is reproducible with different versions and tags (~ other projects in our mono-repo).

It seems like the "old tags" are Ok, but a "new tag" breaks the parsing, and current_version and tag_name need to match exactly again. Only change in the bumpversion.toml, I added always_increment = true for the build part (however I am not sure this is connected to the issue).

Tested with bump-my-version, version 0.20.3 bump-my-version, version 0.24.1

More information needed? Shall I reopen this issue or create a new issue, linking to this one?

coordt commented 3 days ago

If you could post your configuration and then run the offending command with -vv to get more verbose output, it will give me more information on what or where things are going wrong.

skipperTux commented 3 days ago

I removed the [[tool.bumpversion.files]] in the config, they are not relevant for this issue, see above.

.bumpversion.toml ``` [tool.bumpversion] current_version = "4.0.2+build.1046" parse = "(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)(-(?P[0-9A-Za-z]+))?(\\+build\\.(?P.[0-9A-Za-z]+))?" serialize = [ "{major}.{minor}.{patch}-{release}+build.{build}", "{major}.{minor}.{patch}+build.{build}" ] commit = true message = "Bump version: {current_version} -> {new_version}" tag = false tag_name = "app/{new_version}" tag_message = "Version app/{new_version}" allow_dirty = false [tool.bumpversion.parts.release] values = [ "beta", "rc", "final" ] optional_value = "final" [tool.bumpversion.parts.build] first_value = 1000 independent = true always_increment = true ```
Dry-run only with "old tags" ``` $ bump-my-version.exe bump -vv --tag --commit --dry-run patch Starting BumpVersion 0.24.1 Reading configuration Reading config file: C:\Users\me\source\repos\App\.bumpversion.toml Parsing current version '4.0.2+build.1046' Parsing version '4.0.2+build.1046' using regexp '(?P\d+)\.(?P\d+)\.(?P\d+)(-(?P[0-9A-Za-z]+))?(\+build\.(?P.[0-9A-Za-z]+))?' Parsed the following values: build=1046, major=4, minor=0, patch=2, release= Attempting to increment part 'patch' Values are now: build=1047, major=4, minor=0, patch=3, release=beta Serializing version '' Using serialization format '{major}.{minor}.{patch}-{release}+build.{build}' Serialized to '4.0.3-beta+build.1047' New version will be '4.0.3-beta+build.1047' Dry run active, won't touch any files. Processing config file: C:\Users\me\source\repos\App\.bumpversion.toml Serializing version '' Using serialization format '{major}.{minor}.{patch}+build.{build}' Serialized to '4.0.2+build.1046' Serializing version '' Using serialization format '{major}.{minor}.{patch}-{release}+build.{build}' Serialized to '4.0.3-beta+build.1047' Rendering search pattern with context No RegEx flag detected. Searching for the default pattern: '4\.0\.2\+build\.1046' Found '4\.0\.2\+build\.1046' at line 1: 4.0.2+build.1046 Would change file C:\Users\me\source\repos\App\.bumpversion.toml:tool.bumpversion.current_version: *** before C:\Users\me\source\repos\App\.bumpversion.toml:tool.bumpversion.current_version --- after C:\Users\me\source\repos\App\.bumpversion.toml:tool.bumpversion.current_version *************** *** 1 **** ! 4.0.2+build.1046 --- 1 ---- ! 4.0.3-beta+build.1047 Would prepare Git commit Would add changes in file 'C:\Users\me\source\repos\App\.bumpversion.toml' to Git Would commit to Git with message 'Bump version: 4.0.2+build.1046 -> 4.0.3-beta+build.1047' Would tag 'app/4.0.3-beta+build.1047' with message 'Version app/4.0.3-beta+build.1047' in Git and not signing Done. ```
Commit "new tag" ``` $ bump-my-version.exe bump -vv --tag --commit patch Starting BumpVersion 0.24.1 Reading configuration Reading config file: C:\Users\me\source\repos\App\.bumpversion.toml Parsing current version '4.0.2+build.1046' Parsing version '4.0.2+build.1046' using regexp '(?P\d+)\.(?P\d+)\.(?P\d+)(-(?P[0-9A-Za-z]+))?(\+build\.(?P.[0-9A-Za-z]+))?' Parsed the following values: build=1046, major=4, minor=0, patch=2, release= Attempting to increment part 'patch' Values are now: build=1047, major=4, minor=0, patch=3, release=beta Serializing version '' Using serialization format '{major}.{minor}.{patch}-{release}+build.{build}' Serialized to '4.0.3-beta+build.1047' New version will be '4.0.3-beta+build.1047' Processing config file: C:\Users\me\source\repos\App\.bumpversion.toml Serializing version '' Using serialization format '{major}.{minor}.{patch}+build.{build}' Serialized to '4.0.2+build.1046' Serializing version '' Using serialization format '{major}.{minor}.{patch}-{release}+build.{build}' Serialized to '4.0.3-beta+build.1047' Rendering search pattern with context No RegEx flag detected. Searching for the default pattern: '4\.0\.2\+build\.1046' Found '4\.0\.2\+build\.1046' at line 1: 4.0.2+build.1046 Changing file C:\Users\me\source\repos\App\.bumpversion.toml:tool.bumpversion.current_version: *** before C:\Users\me\source\repos\App\.bumpversion.toml:tool.bumpversion.current_version --- after C:\Users\me\source\repos\App\.bumpversion.toml:tool.bumpversion.current_version *************** *** 1 **** ! 4.0.2+build.1046 --- 1 ---- ! 4.0.3-beta+build.1047 Preparing Git commit Adding changes in file 'C:\Users\me\source\repos\App\.bumpversion.toml' to Git Committing to Git with message 'Bump version: 4.0.2+build.1046 -> 4.0.3-beta+build.1047' Tagging 'app/4.0.3-beta+build.1047' with message 'Version app/4.0.3-beta+build.1047' in Git and not signing Done. ```

Dry-run after "new tag"
$ bump-my-version.exe bump -vv --tag --commit --dry-run patch
Starting BumpVersion 0.24.1
Reading configuration
  Reading config file: C:\Users\me\source\repos\App\.bumpversion.toml
  Specified version (4.0.3-beta+build.1047) does not match last tagged version (app/4.0.3-beta+build.1047)
  Parsing current version '4.0.3-beta+build.1047'
    Parsing version '4.0.3-beta+build.1047' using regexp
'(?P\d+)\.(?P\d+)\.(?P\d+)(-(?P[0-9A-Za-z]+))?(\+build\.(?P.[0-9A-Za-z]+))?'
      Parsed the following values: build=1047, major=4, minor=0, patch=3, release=beta
  Attempting to increment part 'patch'
    Values are now: build=1048, major=4, minor=0, patch=4, release=beta
  Serializing version ''
    Using serialization format '{major}.{minor}.{patch}-{release}+build.{build}'
    Serialized to '4.0.4-beta+build.1048'
  New version will be '4.0.4-beta+build.1048'
Dry run active, won't touch any files.

Processing config file: C:\Users\me\source\repos\App\.bumpversion.toml
  Serializing version ''
    Using serialization format '{major}.{minor}.{patch}-{release}+build.{build}'
    Serialized to '4.0.3-beta+build.1047'
  Serializing version ''
    Using serialization format '{major}.{minor}.{patch}-{release}+build.{build}'
    Serialized to '4.0.4-beta+build.1048'
  Rendering search pattern with context
    No RegEx flag detected. Searching for the default pattern: '4\.0\.3\-beta\+build\.1047'
  Found '4\.0\.3\-beta\+build\.1047' at line 1: 4.0.3-beta+build.1047
  Would change file
C:\Users\me\source\repos\App\.bumpversion.toml:tool.bumpversion.current_version:
    *** before
C:\Users\me\source\repos\App\.bumpversion.toml:tool.bumpversion.current_version
    --- after
C:\Users\me\source\repos\App\.bumpversion.toml:tool.bumpversion.current_version
    ***************
    *** 1 ****
    ! 4.0.3-beta+build.1047
    --- 1 ----
    ! 4.0.4-beta+build.1048
Would prepare Git commit
  Would add changes in file 'C:\Users\me\source\repos\App\.bumpversion.toml' to
Git
  Would commit to Git with message 'Bump version: 4.0.3-beta+build.1047 -> 4.0.4-beta+build.1048'
Would tag 'app/4.0.4-beta+build.1048' with message 'Version app/4.0.4-beta+build.1048' in Git and not signing
Done.

Subsequent calls without dry-run give the same warning.

 Specified version (4.0.3-beta+build.1047) does not match last tagged version (app/4.0.3-beta+build.1047)
 Specified version (4.0.4-beta+build.1048) does not match last tagged version (app/4.0.4-beta+build.1048)
[...]
coordt commented 2 days ago

@skipperTux Thanks! Looking into it now.