goreleaser: goreleaser fails because of alphabetical tag sort

Describe the bug

If there are old tags that start with the letter ‘y’ or ‘z’, goreleaser will fail with this error.

release failed after 0.10s error=git tag y-tag was not made against commit <latest-commit>

goreleaser enforces semver, so normally all newer tags will start with the letter ‘v’ or with a number. Thus it will always be alphabetically sorted below those tags.

Further more if we have tags like v0.0.1 and then 0.0.2(without the ‘v’ in the tag), alphabetically v0.0.1 will be first. Both are valid semvers

To Reproduce

Create a tag starting with letter ‘y’ or ‘z’. In latter commits, create tags with semver. Run goreleaser release.

Environment (please complete the following information):

  • OS: mac
  • OS version: Darwin Ninan-2.local 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
  • GoReleaser Version: 0.120.1

Additional Notes:

This is becaue of the addition of -c versionsort.suffix=- tag -l --sort=-v:refname in the process of finding latest tag.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 24 (20 by maintainers)

Most upvoted comments

git tag --sort=-creatordate returns:

0.10.1-rc.6
0.10.1
0.10.1-rc.5
0.10.1-rc.4
0.10.1-rc.3

Is this conversation continued somewhere else? Any status on the fix?

FWIW, using go-git, something like this seems to work:

package main

import (
	"log"
	"sort"

	"github.com/Masterminds/semver/v3"
	"gopkg.in/src-d/go-git.v4"
	"gopkg.in/src-d/go-git.v4/plumbing"
)

func main() {
	r, err := git.PlainOpen(".")
	if err != nil {
		log.Fatalln(err)
	}
	tagrefs, err := r.Tags()
	if err != nil {
		log.Fatalln(err)
	}
	var tags []*semver.Version
	if err := tagrefs.ForEach(func(t *plumbing.Reference) error {
		sv, err := semver.NewVersion(t.Name().Short())
		tags = append(tags, sv)
		return err
	}); err != nil {
		log.Fatalln(err)
	}
	sort.Sort(semver.Collection(tags))
	log.Println(tags)
}

Not sure if v is required for a valid semver or not. But goreleaser considers both as valid. The docs only say the prefix v is not mandatory.