mtkennerly / dunamai

Dynamic versioning library and CLI
https://dunamai.readthedocs.io/en/latest
MIT License
312 stars 24 forks source link

Version.serialize for SemVer fails after update to 1.6.0 #22

Closed ghost closed 2 years ago

ghost commented 2 years ago

Example:

from dunamai import Version
version = Version.from_git()
version_str = version.serialize(metadata=True, style=Style.SemVer)

Repository: https://github.com/splunk/addonfactory-ucc-generator

Traceback:

Traceback (most recent call last):
  File "/home/circleci/.venv/bin/ucc-gen", line 8, in <module>
    sys.exit(main())
  File "/home/circleci/.venv/lib/python3.7/site-packages/splunk_add_on_ucc_framework/__init__.py", line 873, in main
    _generate(args.source, args.config, args.ta_version)
  File "/home/circleci/.venv/lib/python3.7/site-packages/splunk_add_on_ucc_framework/__init__.py", line 691, in _generate
    version_str = version.serialize(metadata=True, style=Style.SemVer)
  File "/home/circleci/.venv/lib/python3.7/site-packages/dunamai/__init__.py", line 467, in serialize
    out = serialize_semver(base, pre=pre_parts, metadata=meta_parts)
  File "/home/circleci/.venv/lib/python3.7/site-packages/dunamai/__init__.py", line 1041, in serialize_semver
    check_version(serialized, Style.SemVer)
  File "/home/circleci/.venv/lib/python3.7/site-packages/dunamai/__init__.py", line 923, in check_version
    raise ValueError(failure_message)
ValueError: Version '0.3-beta.0.post.35+5a020de' does not conform to the Semantic Versioning style

dunamai 1.5.5 version: Version(base='0.1.0', stage=None, revision=None, distance=224, commit='5a020de', dirty=True, tagged_metadata=None)

dunamai 1.6.0 version: Version(base='0.3', stage='beta', revision=0, distance=35, commit='5a020de', dirty=True, tagged_metadata=None)

mtkennerly commented 2 years ago

Hi! This isn't an issue with Version.serialize, but rather is a side effect of a bug fix. Dunamai's default tag pattern previously required versions with three parts (v0.3.0), but that was an oversight, because Dunamai is meant to work also for other versioning systems like PEP 440 where 0.3 or 0.3.0.5 would be valid. So your v0.3 tag, which was previously ignored because it did not match the default pattern, is now being recognized as a version tag, so Dunamai tries to use it, but then it fails because it's invalid under Semantic Versioning (should be v0.3.0).

If you can't or don't want to change the tags, then you can pass a custom pattern to Version.from_git. This was the previous one, if you want to use it as-is:

https://github.com/mtkennerly/dunamai/blob/7f623493914592004ea1dbed989d7c1ae8fff5ff/dunamai/__init__.py#L26-L31

ghost commented 2 years ago

Hi! Thank you for the quick response. Yes, I investigated the issue a little bit more, you are correct. Thank you for the clarification.