Skip to content

Feature request discussion: Valid semver versions for CD based on tag distance #1261

@reallistic

Description

@reallistic

Hello thanks for all the hardwork on this lib!

I saw the discussion and resolution for #311 which is pretty good however it creates versions ending in .dev# unless there is an explicit tag. Tags makes a lot of sense for public releases where tags are a good way to snapshot the code at release time for public inspection and recreation. However, for internal/private projects it introduces a (small) bit of friction for releases that don't need the same level of auditing.

I would like to propose adding support for a distance-based semver strategy similar to setupmeta.

I have created a PoC for this here and am happy to open a PR with the changes if this version scheme is considered acceptable.

How this would work (adapted from setupmeta docs):

Every time you commit a change, the number of commits since last git tag will be used to determine the 'patch' part of version.

Example:

Commit Tag Version Note (command ran to add tag)
no .git 0.0.0 Version defaults to 0.0 (when no tag yet)
none 0.0.0+dirty No commit yet (but git init was ran)
g1 0.0.1 Initial commit, 0.0.1 means default v0.0 + 1 change
g1 0.0.1+dirty Same as above, only checkout was not clean anymore
g2 0.0.2
g3 0.0.3
g4 v0.1.0 0.1.0 git tag v0.1.0
g5 0.1.1 (1 commit since tag)
g6 0.1.2
g7 0.1.3
g8 v0.2.0 0.2.0 git tag v0.2.0
g9 0.2.1
g10 v1.0.0 1.0.0 git tag v1.0.0
g11 1.0.1
g10 v1.0.2 raise ValueError("invalid tag") git tag v1.0.2
  • Without any tag, version defaults to 0.0.*

  • First tag here is v0.1, git describe will yield v0.1.0 (no commits since last tag),
    and scheme will consider version to be 0.1.0 (tag 0.1 with 0 commits)

  • A commit occurs and doesn't add a git tag, version for that commit will be 0.1.1
    (tag 0.1 with 1 change since tag)

  • A 2nd commit occurs and doesn't add a git tag, version for that commit will be 0.1.2 etc

  • Dirty checkouts will get a version of the form 0.1.2+dirty

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions