From f83797dd8acda2378333551664b68684173e4f98 Mon Sep 17 00:00:00 2001 From: Ed Maxwell-Lyte Date: Mon, 2 Aug 2021 12:07:46 +0100 Subject: [PATCH 1/4] fix: tag sorting When the HEAD commit has multiple tags, they are sorted in order to select the latest so that it can be released. However, the existing sort would not work if there were multiple commits across a Wednesday and a Thursday. For example: ``` git tag --points-at HEAD --format='%(creatordate)%09%(refname)' Wed Jul 28 07:13:19 2021 +0000 refs/tags/v0.0.183 Thu Jul 29 13:31:07 2021 +0000 refs/tags/v0.0.184 Thu Jul 29 13:38:42 2021 +0000 refs/tags/v0.0.185 Thu Jul 29 13:57:44 2021 +0000 refs/tags/v0.0.186 ``` When using the existing sort the `creatordate` field was targeted and reversed. Alphabetically Thursday comes before Wednesday, so that is reversed and the Wednesday release always comes first: ``` git tag --points-at HEAD --sort=-version:creatordate --format='%(creatordate)%09%(refname)' Wed Jul 28 07:13:19 2021 +0000 refs/tags/v0.0.183 Thu Jul 29 13:57:44 2021 +0000 refs/tags/v0.0.186 Thu Jul 29 13:38:42 2021 +0000 refs/tags/v0.0.185 Thu Jul 29 13:31:07 2021 +0000 refs/tags/v0.0.184 ``` This would make goreleaser attempt to release that existing tag again, and fail. If we instead sort by reversed `refname` we get the tags ordered by their numeric value, which ignore the day of the week of release: ``` git tag --points-at HEAD --sort=-version:refname --format='%(creatordate)%09%(refname)' Thu Jul 29 13:57:44 2021 +0000 refs/tags/v0.0.186 Thu Jul 29 13:38:42 2021 +0000 refs/tags/v0.0.185 Thu Jul 29 13:31:07 2021 +0000 refs/tags/v0.0.184 Wed Jul 28 07:13:19 2021 +0000 refs/tags/v0.0.183 ``` Allowing the latest version, 0.0.186 in this case, to be targeted for release. --- internal/pipe/git/git.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pipe/git/git.go b/internal/pipe/git/git.go index 46b63d326f3..4dab42f62f1 100644 --- a/internal/pipe/git/git.go +++ b/internal/pipe/git/git.go @@ -177,7 +177,7 @@ func getTag() (string, error) { return os.Getenv("GORELEASER_CURRENT_TAG"), nil }, func() (string, error) { - return git.Clean(git.Run("tag", "--points-at", "HEAD", "--sort", "-version:creatordate")) + return git.Clean(git.Run("tag", "--points-at", "HEAD", "--sort", "-version:refname")) }, func() (string, error) { return git.Clean(git.Run("describe", "--tags", "--abbrev=0")) From 7396f6a6f88ce0a92a1b140eb2ace8dcfc5362de Mon Sep 17 00:00:00 2001 From: Ed Maxwell-Lyte Date: Mon, 2 Aug 2021 13:06:08 +0100 Subject: [PATCH 2/4] corrected test case --- internal/pipe/git/git_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/internal/pipe/git/git_test.go b/internal/pipe/git/git_test.go index 51eae779197..6ff67260d5b 100644 --- a/internal/pipe/git/git_test.go +++ b/internal/pipe/git/git_test.go @@ -233,10 +233,7 @@ func TestTagFromCI(t *testing.T) { envs map[string]string expected string }{ - // It is not possible to concisely figure out the tag if a commit has more than one tags. Git always - // returns the tags in lexicographical order (ASC), which implies that we expect v0.0.1 here. - // More details: https://github.com/goreleaser/goreleaser/issues/1163 - {expected: "v0.0.1"}, + {expected: "v0.0.2"}, { envs: map[string]string{"GORELEASER_CURRENT_TAG": "v0.0.2"}, expected: "v0.0.2", From 9f183376ecf219d1e5cca76b04ff43bcbb104a30 Mon Sep 17 00:00:00 2001 From: Ed Maxwell-Lyte Date: Mon, 2 Aug 2021 16:01:46 +0100 Subject: [PATCH 3/4] add space --- internal/pipe/git/git_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pipe/git/git_test.go b/internal/pipe/git/git_test.go index 6ff67260d5b..d43a4d61bdb 100644 --- a/internal/pipe/git/git_test.go +++ b/internal/pipe/git/git_test.go @@ -232,7 +232,7 @@ func TestTagFromCI(t *testing.T) { for _, tc := range []struct { envs map[string]string expected string - }{ + } { {expected: "v0.0.2"}, { envs: map[string]string{"GORELEASER_CURRENT_TAG": "v0.0.2"}, From e3f5562fbfd3e5e6329368a5d9e24a46ea29ef8b Mon Sep 17 00:00:00 2001 From: Ed Maxwell-Lyte Date: Mon, 2 Aug 2021 16:02:03 +0100 Subject: [PATCH 4/4] remove space --- internal/pipe/git/git_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pipe/git/git_test.go b/internal/pipe/git/git_test.go index d43a4d61bdb..6ff67260d5b 100644 --- a/internal/pipe/git/git_test.go +++ b/internal/pipe/git/git_test.go @@ -232,7 +232,7 @@ func TestTagFromCI(t *testing.T) { for _, tc := range []struct { envs map[string]string expected string - } { + }{ {expected: "v0.0.2"}, { envs: map[string]string{"GORELEASER_CURRENT_TAG": "v0.0.2"},