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

bug: git tag: uses first tag that matches commit and not the latest #255

Closed
lrstanley opened this issue Nov 12, 2020 · 4 comments · Fixed by #259
Closed

bug: git tag: uses first tag that matches commit and not the latest #255

lrstanley opened this issue Nov 12, 2020 · 4 comments · Fixed by #259

Comments

@lrstanley
Copy link

This is technically more related to goreleaser itself and not the action, however I think reporting it under the action repo still makes sense due to the type of bug.

I've got a workflow setup so when I push to any tag, it will automatically build and release it on GitHub:
https://github.com/lrstanley/links/blob/master/.github/workflows/release.yml

However, there is a problem where if I tag the same commit twice (i.e. triggering it to rebuild the code with a different Go version as an example), it still only picks the FIRST tag that relates to that commit.

As you can see in the following build output (I've since deleted the new v0.5.3 tag, but this log still exists), you can see GitHub sees the new tag, and it clones the git repository down with that tag, however goreleaser is still using the v0.5.2 tag:
https://github.com/lrstanley/links/runs/1392634281?check_suite_focus=true

That is likely due to goreleaser using the following command (or something similar):

$ git describe --tags a1d277ff3b61a39d61f1ed135c97643ad054d8aa
v0.5.2

However, we can see with the following command, that two tags actually relate to the commit:

$ git tag --contains a1d277ff3b61a39d61f1ed135c97643ad054d8aa
v0.5.2
v0.5.3

You may wonder why I am even retagging the same commit. This is because there isn't a super easy way of automating goreleaser to rebuild, retag, and release the same code, but with a newer version of Go, at least with GitHub actions today. If the code doesn't need to be changed, there isn't really any kind of commit that needs to happen, to qualify for goreleaser to pick it up.


  1. Is there a way I can pass the specific tag to be used to goreleaser, via this action, since it doesn't use what actions/checkout is providing? Or, is there a way goreleaser can notice that actions/checkout checked out a specific tag, and use that tag?
  2. Does it make sense for goreleaser to use the first tag that relates to the commit, not the latest tag that relates to the commit, by default?

Logs from actions/checkout...:

2020-11-12T20:30:33.2634625Z ##[group]Fetching the repository
2020-11-12T20:30:33.2645932Z [command]/usr/bin/git -c protocol.version=2 fetch --prune --progress --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
[...]
2020-11-12T20:30:34.1552511Z Resolving deltas: 100% (455/455), done.
2020-11-12T20:30:34.1553020Z From https://github.com/lrstanley/links
2020-11-12T20:30:34.1554275Z  * [new branch]      master     -> origin/master
2020-11-12T20:30:34.1555089Z  * [new tag]         v0.1.0     -> v0.1.0
2020-11-12T20:30:34.1555846Z  * [new tag]         v0.1.1     -> v0.1.1
2020-11-12T20:30:34.1556577Z  * [new tag]         v0.2.0     -> v0.2.0
2020-11-12T20:30:34.1557245Z  * [new tag]         v0.2.1     -> v0.2.1
2020-11-12T20:30:34.1558021Z  * [new tag]         v0.2.2     -> v0.2.2
2020-11-12T20:30:34.1558814Z  * [new tag]         v0.2.3     -> v0.2.3
2020-11-12T20:30:34.1559555Z  * [new tag]         v0.2.4     -> v0.2.4
2020-11-12T20:30:34.1560275Z  * [new tag]         v0.2.5     -> v0.2.5
2020-11-12T20:30:34.1561010Z  * [new tag]         v0.3.0     -> v0.3.0
2020-11-12T20:30:34.1561719Z  * [new tag]         v0.3.1     -> v0.3.1
2020-11-12T20:30:34.1562630Z  * [new tag]         v0.3.2     -> v0.3.2
2020-11-12T20:30:34.1563381Z  * [new tag]         v0.4.0     -> v0.4.0
2020-11-12T20:30:34.1564117Z  * [new tag]         v0.4.1     -> v0.4.1
2020-11-12T20:30:34.1564900Z  * [new tag]         v0.4.2     -> v0.4.2
2020-11-12T20:30:34.1565648Z  * [new tag]         v0.4.3     -> v0.4.3
2020-11-12T20:30:34.1566361Z  * [new tag]         v0.4.4     -> v0.4.4
2020-11-12T20:30:34.1567087Z  * [new tag]         v0.4.5     -> v0.4.5
2020-11-12T20:30:34.1567804Z  * [new tag]         v0.5.0     -> v0.5.0
2020-11-12T20:30:34.1568541Z  * [new tag]         v0.5.1     -> v0.5.1
2020-11-12T20:30:34.1569223Z  * [new tag]         v0.5.2     -> v0.5.2
2020-11-12T20:30:34.1569955Z  * [new tag]         v0.5.3     -> v0.5.3
2020-11-12T20:30:34.1570719Z [command]/usr/bin/git tag --list v0.5.3
2020-11-12T20:30:34.1571300Z v0.5.3
2020-11-12T20:30:34.1572053Z [command]/usr/bin/git rev-parse refs/tags/v0.5.3
2020-11-12T20:30:34.1572842Z a1d277ff3b61a39d61f1ed135c97643ad054d8aa
2020-11-12T20:30:34.1574117Z ##[endgroup]
2020-11-12T20:30:34.1574815Z ##[group]Determining the checkout info
2020-11-12T20:30:34.1575412Z ##[endgroup]
2020-11-12T20:30:34.1575954Z ##[group]Checking out the ref
2020-11-12T20:30:34.1576891Z [command]/usr/bin/git checkout --progress --force refs/tags/v0.5.3
2020-11-12T20:30:34.1577859Z Note: switching to 'refs/tags/v0.5.3'.
[...]
2020-11-12T20:30:34.1587959Z HEAD is now at a1d277f fix: behind-proxy used on incorrect router
2020-11-12T20:30:34.1588482Z ##[endgroup]
2020-11-12T20:30:34.1589115Z [command]/usr/bin/git log -1 --format='%H'
2020-11-12T20:30:34.1590208Z 'a1d277ff3b61a39d61f1ed135c97643ad054d8aa'

Logs from goreleaser:

/opt/hostedtoolcache/goreleaser-action/0.147.0/x64/goreleaser release --rm-dist --skip-validate --release-header=notes-header.md --release-footer=notes-footer.md

   • releasing...     
   • loading config file       file=.goreleaser.yml
   • loading environment variables
   • getting and validating git state
      • releasing v0.5.2, commit a1d277ff3b61a39d61f1ed135c97643ad054d8aa
      • pipe skipped              error=validation is disabled
   • parsing tag      
   • running before hooks
   • setting defaults 
      • snapshotting     
      • github/gitlab/gitea releases
      • project name     
      • building binaries
      • creating source archive
      • archives         
      • linux packages   
      • snapcraft packages
      • calculating checksums
      • signing artifacts
      • docker images    
      • artifactory      
      • blobs            
      • homebrew tap formula
      • scoop manifests  
      • milestones       
   • snapshotting     
      • pipe skipped              error=not a snapshot
   • checking ./dist  
   • writing effective config file
      • writing                   config=dist/config.yaml
   • generating changelog
      • writing                   changelog=dist/CHANGELOG.md
   • building binaries
      • building                  binary=/home/runner/work/links/links/dist/links_freebsd_amd64/links
      • building                  binary=/home/runner/work/links/links/dist/links_linux_amd64/links
      • building                  binary=/home/runner/work/links/links/dist/links_windows_amd64/links.exe
   • archives         
      • creating                  archive=dist/links_0.5.2_freebsd_amd64.tar.gz
      • creating                  archive=dist/links_0.5.2_linux_amd64.tar.gz
      • creating                  archive=dist/links_0.5.2_windows_amd64.zip
   • creating source archive
      • pipe skipped              error=source pipe is disabled
   • linux packages   
      • creating                  file=dist/links_0.5.2_linux_amd64.rpm
      • creating                  file=dist/links_0.5.2_linux_amd64.deb
   • snapcraft packages
   • calculating checksums
      • checksumming              file=links_0.5.2_linux_amd64.rpm
      • checksumming              file=links_0.5.2_windows_amd64.zip
      • checksumming              file=links_0.5.2_freebsd_amd64.tar.gz
      • checksumming              file=links_0.5.2_linux_amd64.deb
      • checksumming              file=links_0.5.2_linux_amd64.tar.gz
   • signing artifacts
   • docker images    
      • pipe skipped              error=docker section is not configured
   • publishing       
      • blobs            
         • pipe skipped              error=blobs section is not configured
      • http upload      
         • pipe skipped              error=uploads section is not configured
      • custom publisher 
         • pipe skipped              error=publishers section is not configured
      • artifactory      
         • pipe skipped              error=artifactory section is not configured
      • docker images    
      • snapcraft packages
      • github/gitlab/gitea releases
         • creating or updating release repo=lrstanley/links tag=v0.5.2
         • release updated           url=https://github.com/lrstanley/links/releases/tag/v0.5.2
         • uploading to release      file=dist/links_0.5.2_checksums.txt name=links_0.5.2_checksums.txt
         • uploading to release      file=dist/links_0.5.2_linux_amd64.tar.gz name=links_0.5.2_linux_amd64.tar.gz
         • uploading to release      file=dist/links_0.5.2_freebsd_amd64.tar.gz name=links_0.5.2_freebsd_amd64.tar.gz
         • uploading to release      file=dist/links_0.5.2_windows_amd64.zip name=links_0.5.2_windows_amd64.zip
         • failed to upload artifact, will retry artifact=links_0.5.2_windows_amd64.zip error=POST https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_windows_amd64.zip: 422 Validation Failed [{Resource:ReleaseAsset Field:name Code:already_exists Message:}] try=1
         • uploading to release      file=dist/links_0.5.2_linux_amd64.deb name=links_0.5.2_linux_amd64.deb
         • failed to upload artifact, will retry artifact=links_0.5.2_freebsd_amd64.tar.gz error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_freebsd_amd64.tar.gz": write tcp 10.1.0.4:52738->140.82.113.13:443: write: broken pipe try=1
         • failed to upload artifact, will retry artifact=links_0.5.2_linux_amd64.tar.gz error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_linux_amd64.tar.gz": write tcp 10.1.0.4:52736->140.82.113.13:443: use of closed network connection try=1
         • failed to upload artifact, will retry artifact=links_0.5.2_checksums.txt error=POST https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_checksums.txt: 422 Validation Failed [{Resource:ReleaseAsset Field:name Code:already_exists Message:}] try=1
         • uploading to release      file=dist/links_0.5.2_linux_amd64.rpm name=links_0.5.2_linux_amd64.rpm
         • uploading to release      file=dist/links_0.5.2_freebsd_amd64.tar.gz name=links_0.5.2_freebsd_amd64.tar.gz
         • uploading to release      file=dist/links_0.5.2_linux_amd64.tar.gz name=links_0.5.2_linux_amd64.tar.gz
         • failed to upload artifact, will retry artifact=links_0.5.2_linux_amd64.deb error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_linux_amd64.deb": write tcp 10.1.0.4:52740->140.82.113.13:443: use of closed network connection try=1
         • failed to upload artifact, will retry artifact=links_0.5.2_linux_amd64.rpm error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_linux_amd64.rpm": write tcp 10.1.0.4:52742->140.82.113.13:443: use of closed network connection try=1
         • failed to upload artifact, will retry artifact=links_0.5.2_freebsd_amd64.tar.gz error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_freebsd_amd64.tar.gz": write tcp 10.1.0.4:52744->140.82.113.13:443: write: broken pipe try=2
         • uploading to release      file=dist/links_0.5.2_linux_amd64.deb name=links_0.5.2_linux_amd64.deb
         • uploading to release      file=dist/links_0.5.2_linux_amd64.rpm name=links_0.5.2_linux_amd64.rpm
         • failed to upload artifact, will retry artifact=links_0.5.2_linux_amd64.tar.gz error=POST https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_linux_amd64.tar.gz: 422 Validation Failed [{Resource:ReleaseAsset Field:name Code:already_exists Message:}] try=2
         • failed to upload artifact, will retry artifact=links_0.5.2_linux_amd64.rpm error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_linux_amd64.rpm": http: server closed idle connection try=2
         • uploading to release      file=dist/links_0.5.2_freebsd_amd64.tar.gz name=links_0.5.2_freebsd_amd64.tar.gz
         • uploading to release      file=dist/links_0.5.2_linux_amd64.rpm name=links_0.5.2_linux_amd64.rpm
         • failed to upload artifact, will retry artifact=links_0.5.2_linux_amd64.deb error=POST https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_linux_amd64.deb: 422 Validation Failed [{Resource:ReleaseAsset Field:name Code:already_exists Message:}] try=2
         • failed to upload artifact, will retry artifact=links_0.5.2_freebsd_amd64.tar.gz error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_freebsd_amd64.tar.gz": write tcp 10.1.0.4:52750->140.82.113.13:443: use of closed network connection try=3
         • failed to upload artifact, will retry artifact=links_0.5.2_linux_amd64.rpm error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_linux_amd64.rpm": EOF try=3
         • uploading to release      file=dist/links_0.5.2_freebsd_amd64.tar.gz name=links_0.5.2_freebsd_amd64.tar.gz
         • uploading to release      file=dist/links_0.5.2_linux_amd64.rpm name=links_0.5.2_linux_amd64.rpm
         • failed to upload artifact, will retry artifact=links_0.5.2_freebsd_amd64.tar.gz error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_freebsd_amd64.tar.gz": write tcp 10.1.0.4:52754->140.82.113.13:443: use of closed network connection try=4
         • failed to upload artifact, will retry artifact=links_0.5.2_linux_amd64.rpm error=POST https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_linux_amd64.rpm: 422 Validation Failed [{Resource:ReleaseAsset Field:name Code:already_exists Message:}] try=4
         • uploading to release      file=dist/links_0.5.2_freebsd_amd64.tar.gz name=links_0.5.2_freebsd_amd64.tar.gz
         • failed to upload artifact, will retry artifact=links_0.5.2_freebsd_amd64.tar.gz error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_freebsd_amd64.tar.gz": write tcp 10.1.0.4:52758->140.82.113.13:443: use of closed network connection try=5
         • uploading to release      file=dist/links_0.5.2_freebsd_amd64.tar.gz name=links_0.5.2_freebsd_amd64.tar.gz
         • failed to upload artifact, will retry artifact=links_0.5.2_freebsd_amd64.tar.gz error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_freebsd_amd64.tar.gz": EOF try=6
         • uploading to release      file=dist/links_0.5.2_freebsd_amd64.tar.gz name=links_0.5.2_freebsd_amd64.tar.gz
         • failed to upload artifact, will retry artifact=links_0.5.2_freebsd_amd64.tar.gz error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_freebsd_amd64.tar.gz": write tcp 10.1.0.4:52770->140.82.113.13:443: write: broken pipe try=7
         • uploading to release      file=dist/links_0.5.2_freebsd_amd64.tar.gz name=links_0.5.2_freebsd_amd64.tar.gz
         • failed to upload artifact, will retry artifact=links_0.5.2_freebsd_amd64.tar.gz error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_freebsd_amd64.tar.gz": write tcp 10.1.0.4:52772->140.82.113.13:443: use of closed network connection try=8
         • uploading to release      file=dist/links_0.5.2_freebsd_amd64.tar.gz name=links_0.5.2_freebsd_amd64.tar.gz
         • failed to upload artifact, will retry artifact=links_0.5.2_freebsd_amd64.tar.gz error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_freebsd_amd64.tar.gz": write tcp 10.1.0.4:52774->140.82.113.13:443: use of closed network connection try=9
         • uploading to release      file=dist/links_0.5.2_freebsd_amd64.tar.gz name=links_0.5.2_freebsd_amd64.tar.gz
         • failed to upload artifact, will retry artifact=links_0.5.2_freebsd_amd64.tar.gz error=Post "https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_freebsd_amd64.tar.gz": write tcp 10.1.0.4:52786->140.82.113.13:443: use of closed network connection try=10
   ⨯ release failed after 63.39s error=github/gitlab/gitea releases: failed to publish artifacts: failed to upload links_0.5.2_windows_amd64.zip after 1 tries: POST https://uploads.github.com/repos/lrstanley/links/releases/31633537/assets?name=links_0.5.2_windows_amd64.zip: 422 Validation Failed [{Resource:ReleaseAsset Field:name Code:already_exists Message:}]
Error: The process '/opt/hostedtoolcache/goreleaser-action/0.147.0/x64/goreleaser' failed with exit code 1
@crazy-max
Copy link
Member

crazy-max commented Nov 22, 2020

@lrstanley As you can see in the logs, the action actually found the right tag based on GITHUB_REF env var (#239):

✅ GoReleaser installed successfully
✅ v0.5.3 tag found for commit 'a1d277f'
🏃 Running GoReleaser...

But yes GoReleaser itself found the previous one:

• releasing v0.5.2, commit a1d277ff3b61a39d61f1ed135c97643ad054d8aa

Maybe translate the logic here to GoReleaser? WDYT @caarlos0?:

export async function getTag(): Promise<string> {
try {
if ((process.env.GITHUB_REF || '').startsWith('refs/tags')) {
const tag = (process.env.GITHUB_REF || '').split('/').pop();
if (tag !== '' && tag !== undefined) {
return tag;
}
}
return await git(['tag', '--points-at', `${process.env.GITHUB_SHA}`, '--sort', '-version:creatordate']).then(
tags => {
if (tags.length == 0) {
return git(['describe', '--tags', '--abbrev=0']);
}
return tags.split('\n')[0];
}
);
} catch (err) {
return '';
}
}

@caarlos0
Copy link
Member

Sounds good @crazy-max, want to open a pr or should I?

@crazy-max
Copy link
Member

@caarlos0 Hum actually I could set GORELEASER_CURRENT_TAG in the action instead no? This would avoid hacky things on the main repo for GitHub Actions.

@caarlos0
Copy link
Member

Hmm that might work as well

nieomylnieja added a commit to nobl9/terraform-provider-nobl9 that referenced this issue Mar 1, 2024
## Motivation

Goreleaser is not interpreting the correct tag, here's a related issue:
goreleaser/goreleaser-action#255. The
workaround is to set an env var `GORELEASER_CURRENT_TAG`.
I also sneaked some minor changes to how acceptance tests are run so
that we can provide it with ref to run against.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants