Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sort tags by version not day of the week #2377

Merged
merged 4 commits into from Aug 2, 2021

Conversation

edwardmlyte
Copy link
Contributor

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, here is our commit with multiple tags. Printing out the creatordate and refname to demonstrate the issue.

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.

...

...

...

@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Aug 2, 2021
@vercel
Copy link

vercel bot commented Aug 2, 2021

@edwardmlyte is attempting to deploy a commit to the goreleaser Team on Vercel.

A member of the Team first needs to authorize it.

@caarlos0
Copy link
Member

caarlos0 commented Aug 2, 2021

lgtm, but there are test failures... can you take a look?

Ed Maxwell-Lyte added 2 commits August 2, 2021 13:08
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.
@edwardmlyte
Copy link
Contributor Author

Hmm, @caarlos0 I can't see why the tests aren't being retriggered. I rebased and force pushed to bring it in line with master, would that cause an issue?

@caarlos0
Copy link
Member

caarlos0 commented Aug 2, 2021

Hmm, @caarlos0 I can't see why the tests aren't being retriggered. I rebased and force pushed to bring it in line with master, would that cause an issue?

I need to approve the run for some reason...

@caarlos0 caarlos0 added the bug Something isn't working label Aug 2, 2021
@caarlos0 caarlos0 enabled auto-merge (squash) August 2, 2021 16:14
@caarlos0 caarlos0 merged commit 18695c2 into goreleaser:master Aug 2, 2021
@edwardmlyte edwardmlyte deleted the correct-tag-sort branch August 3, 2021 07:16
@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2021

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants