fix: long version info not displayed correctly in release builds#1374
fix: long version info not displayed correctly in release builds#1374
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1374 +/- ##
==========================================
+ Coverage 67.59% 72.61% +5.01%
==========================================
Files 300 300
Lines 11054 11067 +13
==========================================
+ Hits 7472 8036 +564
+ Misses 2641 2133 -508
+ Partials 941 898 -43
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| @@ -1,5 +1,7 @@ | |||
| package version | |||
|
|
|||
| import "runtime/debug" | |||
There was a problem hiding this comment.
Why use runtime/debug at all if we inject the values anyways?
There was a problem hiding this comment.
debug.ReadBuildInfo()is still used as a fallback in case the binary was not built using goreleaser.
This is useful for example for go install. Also I think some package managers run custom builds.
There was a problem hiding this comment.
Could you add a comment about this somewhere in this file please?
.goreleaser.yml
Outdated
| - -w | ||
| - -X {{ .ModulePath }}/internal/version.version={{ .Version }} | ||
| - -X {{ .ModulePath }}/internal/version.versionPrerelease={{- if .IsSnapshot -}}dev+{{ .ShortCommit }}{{- end -}} | ||
| - -X {{ .ModulePath }}/internal/version.commit={{ .Commit }} |
There was a problem hiding this comment.
According to goreleaser, this template value is deprecated: https://goreleaser.com/customization/general/templates/
We should probably use .FullCommit instead.
| // Modified specifies whether the git worktree was dirty during build time | ||
| Modified = func() bool { | ||
| return getSettingsValue("vcs.modified", "false") == "true" | ||
| }() |
There was a problem hiding this comment.
What about using goreleaser's .IsGitDirty template variable to set this value?
Goreleaser allows injecting the
vcs.revisionandvcs.timevariables directly using ldflags, which is more reliable than usingdebug.ReadBuildInfo()and should fix the long version output for GitHub releases.debug.ReadBuildInfo()is still used as a fallback in case the binary was not built using goreleaser. Thego mod tidybefore hook was removed from the goreleaser config as we already keep our go mod tidied using renovate.