mtkennerly / poetry-dynamic-versioning

Plugin for Poetry to enable dynamic versioning based on VCS tags
MIT License
588 stars 36 forks source link

How to support semver in pattern and format config? #144

Closed mrt181 closed 9 months ago

mrt181 commented 9 months ago

When following semver when versioning my project I create tags that match this regex:

semver.org#regex

This pattern is not supported because we need to use predefined capture group names.

I have changed the regex to get the groups that the plugin supports, but it's not perfect.

regex101.com

I have this config

[tool.poetry-dynamic-versioning]
enable = false
bump = true
vcs = "git"
style = "semver"
pattern = "^(?P<base>(?P<major>0|[1-9]\\d*)\\.(?P<minor>0|[1-9]\\d*)\\.(?P<patch>0|[1-9]\\d*))(?:-(?P<prerelease>(?:(?P<stage>[a-zA-Z]*|(?:[a-zA-Z]+-[a-zA-Z0-9]+)*|(?:[a-zA-Z0-9]+\\.[a-zA-Z0-9]+)*))(?:\\.)*(?P<revision>0|[1-9]\\d*)*))?(?:\\+(?P<tagged_metadata>[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"                                                                                                                                                                           format-jinja = """
    {%- if distance == 0 -%}
        {{ serialize_semver(base, [stage], [tagged_metadata]) }}
    {%- elif (stage is not none) and (revision is not none) -%}
        {{ serialize_semver(base, ["%s.%s".format(stage, revision + 1)], [tagged_metadata]) }}
    {%- elif stage is not none -%}
        {{ serialize_semver(bump_version(base), [stage], [tagged_metadata]) }}
    {%- elif revision is not none -%}
        {{ serialize_semver(bump_version(base), [revision], [tagged_metadata]) }}
    {%- else -%}
        {{ serialize_semver(bump_version(base), [stage], [tagged_metadata]) }}
    {%- endif -%}
"""

And this history:

git log --max-count=2 --pretty="%C(auto)%h %(describe) %s"
ee17795 1.1.0-1-gee17795 chore: test
b1b97c4 1.1.0 release: v1.1.0

When I check the version I get this which is unexpected.

poetry dynamic-versioning

Invalid version '1.1.2-s.t.a.g.e.r.e.v.i.s.i.o.n' on package data-model

How can I fix this?

mtkennerly commented 9 months ago

There are a few issues here:

Is that -s.t.a... output possibly from before you wrapped stage/revision in []? With your current config, I would expect the output to be 1.1.2-None+None.

mrt181 commented 9 months ago

yes was able to fix it, thank you