commitizen-tools / commitizen

Create committing rules for projects :rocket: auto bump versions :arrow_up: and auto changelog generation :open_file_folder:
https://commitizen-tools.github.io/commitizen/
MIT License
2.39k stars 257 forks source link

Help wanted: commitizen 3.x not supoort generate CHANGELOG with tag format like v1.0.0-release #950

Open dhmemi opened 8 months ago

dhmemi commented 8 months ago

Description

Commitizen 3.x not supoort generate CHANGELOG with tag format like v1.0.0-release, but it works well with commitizen 2.x.

My repo tags could not be changed as it released. Any idea to solve this problem in order to generate the changelog correctly?

Steps to reproduce

PS E:\codes\aidi-sdk> cz ch                           
InvalidVersion GitTag('v0.7.1-release', '0689497d1cf9d036cb510cfed3a96135d9456419', '2023-12-08')
InvalidVersion GitTag('v0.7.0-release', 'c81dd1acd809ea2df66154bc5ecb64fb625a40e6', '2023-12-07')

Current behavior

no

Desired behavior

no

Screenshots

No response

Environment

cz version: 3.13.0

rshmhrj commented 7 months ago

This is also happening for maven type versions (using cz version 3.13.0):

cz init
Welcome to commitizen!

Answer the questions to configure your project.
For further configuration visit:

https://commitizen-tools.github.io/commitizen/config/

? Please choose a supported config file:  .cz.toml
? Please choose a cz (commit rule): (default: cz_conventional_commits) cz_conventional_commits
? Choose the source of the version: commitizen: Fetch and set version in commitizen config (default)
? Is master_0.0.2-SNAPSHOT.74 the latest tag? No
? Please choose the latest tag:  v0.0.1-SNAPSHOT
? Choose version scheme:  semver
Traceback (most recent call last):
  File "/usr/local/bin/cz", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/Cellar/commitizen/3.13.0/libexec/lib/python3.12/site-packages/commitizen/cli.py", line 570, in main
    args.func(conf, arguments)()
  File "/usr/local/Cellar/commitizen/3.13.0/libexec/lib/python3.12/site-packages/commitizen/commands/init.py", line 100, in __call__
    version = get_version_scheme(self.config, version_scheme)(tag)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/opt/python-packaging/lib/python3.12/site-packages/packaging/version.py", line 200, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: 'v0.0.1-SNAPSHOT'
image
Lee-W commented 4 months ago

Thanks for reporting. Just verified this is a valid issue.

Lee-W commented 4 months ago

The root cause is https://github.com/commitizen-tools/commitizen/blob/ac07bdaa30155ef080ad6487c8ccc21067d0ceab/commitizen/version_schemes.py#L152. The following is a simplified version of this error.

from packaging.version import Version as _BaseVersion

_BaseVersion("1.0.0-test")

I guess we'll need to overwrite https://github.com/pypa/packaging/blob/32deafe8668a2130a3366b98154914d188f3718e/src/packaging/version.py#L185 to something like https://github.com/pypa/packaging/blob/32deafe8668a2130a3366b98154914d188f3718e/src/packaging/version.py#L117 but with semver support?

@noirbizarre @woile WDYT?

woile commented 4 months ago

Definitely a good idea, we should add tests for semver and semver2

Lee-W commented 4 months ago

Added tests first https://github.com/commitizen-tools/commitizen/pull/1081