mtkennerly / dunamai

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

calver versioning #73

Closed miigotu closed 10 months ago

miigotu commented 11 months ago

Any chance to get you interested in adding calver versioning? This format is used by quite a few large projects. It allows people to see a dead project really quickly.

some reference: https://calver.org/ https://github.com/StephaneBour/actions-calver/blob/master/entrypoint.sh

imo, DDDD.M.D-patchlevel, where patch level is the number of releases if more than one were made in the same day, first release has no patch level so (DDDD.M.D aka 2023.9.3), and the third release that day would be 2023.9.3-2.

For pre-releases, as defined by pypi/pep, 2023.9.2-SHORTHASH (git)

I dont think there is an easy way to make this project (and by extension poetry-dynaminc-versioning) create and manage versions for this format. currently I am going to get the version from calver and use it to set versions and then commit with the release message and build/push. Its a lot of moving parts that I would rather do right in poetry.

mtkennerly commented 11 months ago

I dont think there is an easy way to make this project (and by extension poetry-dynaminc-versioning) create and manage versions for this format.

You can accomplish this with a custom output format. Here's an example for poetry-dynamic-versioning (untested):

[tool.poetry-dynamic-versioning]
enable = true
format-jinja-imports = [
    { module = "datetime", item = "datetime" },
]
format-jinja = """
    {%- if distance == 0 -%}
        {{ serialize_pep440(base, stage, revision) }}
    {%- else -%}
        {%- set date = datetime.now().strftime("%Y.%m.%d") -%}
        {{ serialize_pep440(date, stage, revision, dev=distance, metadata=[commit]) }}
    {%- endif -%}
"""

Or using Dunamai on its own:

import datetime as dt
from dunamai import Version, serialize_pep440

def calver(v: Version) -> str:
    if v.distance == 0:
        return serialize_pep440(v.base, v.stage, v.revision)
    else:
        date = dt.datetime.now().strftime("%Y.%m.%d")
        return serialize_pep440(date, v.stage, v.revision, dev=v.distance, metadata=[v.commit])

version = Version.from_any()
serialized = version.serialize(format=calver)