PaulHatch / semantic-version

A GitHub Action to generate semantic version from a git repository's commit history.
MIT License
338 stars 64 forks source link

Miscalculation of version #156

Closed rohitpid closed 4 months ago

rohitpid commented 5 months ago

When I run the action with debug output, I get a miscalculated version. Here is part of the debug output:

{
    "commands": [
        {
            "command": "git",
            "args": [
                "rev-parse",
                "--abbrev-ref",
                "HEAD"
            ],
            "output": "dev\n",
            "stderr": "",
            "error": null
        },
        {
            "command": "git",
            "args": [
                "rev-list",
                "-n1",
                "--all"
            ],
            "output": "0182346abfa899141296ac86f3e75ad3c18c52b9\n",
            "stderr": "",
            "error": null
        },
        {
            "command": "git",
            "args": [
                "rev-parse",
                "HEAD"
            ],
            "output": "0182346abfa899141296ac86f3e75ad3c18c52b9\n",
            "stderr": "",
            "error": null
        },
        {
            "command": "git tag --points-at 0182346abfa899141296ac86f3e75ad3c18c52b9 v*[0-9].*[0-9].*[0-9]",
            "args": [],
            "output": "v0.4.0.dev18\n",
            "stderr": "",
            "error": null
        },
        {
            "command": "git for-each-ref --sort=-v:*refname --format=%(refname:short) --merged=0182346abfa899141296ac86f3e75ad3c18c52b9 refs/tags/v*[0-9].*[0-9].*[0-9]",
            "args": [],
            "output": "v0.4.3.dev3\nv0.4.3.dev1\nv0.4.3.dev0\nv0.4.0.dev18\nv0.4.0.dev13\nv0.4.0.dev12\nv0.4.0.dev11\nv0.4.0.dev10\nv0.4.0.dev9\nv0.4.0.dev8\nv0.3.0\nv0.3.0.dev4\nv0.3.0.dev3\nv0.2.12.dev0\nv0.2.11.dev0\nv0.2.10\nv0.2.10.dev0\nv0.2.10-1\nv0.2.9\nv0.2.9.dev7\nv0.2.9.dev6\nv0.2.9-1\nv0.2.8\nv0.2.8.dev6\nv0.2.8.dev5\nv0.2.8.dev4\nv0.2.8.dev3\nv0.2.8.dev2\nv0.2.8.dev1\nv0.2.8-3\nv0.2.8-2\nv0.2.8-1\nv0.2.7.dev1\nv0.2.7.dev0\nv0.2.6.dev0\nv0.2.5\nv0.2.5.dev1\nv0.2.5.dev0\nv0.2.4.dev0\nv0.2.3.dev1\nv0.2.3.dev0\nv0.2.2\nv0.2.2.dev0\nv0.2.1.dev0\nv0.1.9.dev0\nv0.1.8.dev0\nv0.1.7.dev0\nv0.1.6\nv0.1.6.dev1\nv0.1.6.dev0\nv0.1.5\nv0.1.5.dev0\nv0.1.4\nv0.1.3\nv0.1.2\nv0.1.1\nv0.1.0\n",
            "stderr": "",
            "error": null
        },
        {
            "command": "git",
            "args": [
                "merge-base",
                "v0.3.0",
                "0182346abfa899141296ac86f3e75ad3c18c52b9"
            ],
            "output": "fafc5c91bfee7194db69256a329524e056303731\n",
            "stderr": "",
            "error": null
        },

From this, I would expect a calculated version to be above 0.4.3.dev3 but somehow I get 0.4.0.dev18. Why is that?

PaulHatch commented 5 months ago

The only tags that will be counted are those that conform to this pattern:

{PREFIX}{MAJOR}.{MINOR}.{PATCH} (An additional namespace can be specified, but that's only meant for a more advanced mono repo use case)

Your tags are:

v0.4.3.dev3
v0.4.3.dev1
v0.4.3.dev0
v0.4.0.dev18
v0.4.0.dev13
v0.4.0.dev12
v0.4.0.dev11
v0.4.0.dev10
v0.4.0.dev9
v0.4.0.dev8
v0.3.0
v0.3.0.dev4
v0.3.0.dev3
v0.2.12.dev0
v0.2.11.dev0
v0.2.10
v0.2.10.dev0
v0.2.10-1
v0.2.9
v0.2.9.dev7
v0.2.9.dev6
v0.2.9-1
v0.2.8
v0.2.8.dev6
v0.2.8.dev5
v0.2.8.dev4
v0.2.8.dev3
v0.2.8.dev2
v0.2.8.dev1
v0.2.8-3
v0.2.8-2
v0.2.8-1
v0.2.7.dev1
v0.2.7.dev0
v0.2.6.dev0
v0.2.5
v0.2.5.dev1
v0.2.5.dev0
v0.2.4.dev0
v0.2.3.dev1
v0.2.3.dev0
v0.2.2
v0.2.2.dev0
v0.2.1.dev0
v0.1.9.dev0
v0.1.8.dev0
v0.1.7.dev0
v0.1.6
v0.1.6.dev1
v0.1.6.dev0
v0.1.5
v0.1.5.dev0
v0.1.4
v0.1.3
v0.1.2
v0.1.1
v0.1.0

These prerelease tags are ignored, all the .dev#, so the last tag here (I am guessing a bit at your config) is v0.3.0. The increment is the number of commits since the last version change and is not derived from the tag. Based on this I'd say you have a "minor" type commit, and 18 commits since the last version change. If you want to release a version and see the next version increment, you need to add a tag with a format like v0.4.3, which would result in an increment to v0.4.4 on the next commit. Also note that the version output is just a convenience, you are free to use whatever format you want and don't have to use the increment if you'd rather use something else like a commit hash or other build number, but in any case such tags are not considered by the action.

rohitpid commented 5 months ago

Thanks, I think a tag might have been deleted and that messed around with things. It might be an optional feature request to calculate versions based on latest dev tag but I understand that isn't current functionality.