fix: recover version from BuildInfo for go-installed binaries#26
Merged
Conversation
`go install github.com/coingecko/coingecko-cli@vX.Y.Z` does not pass ldflags, so the binary always reported version="dev" — breaking `cg version`, the on-launch update reminder, and `cg update`. Fall back to runtime/debug.BuildInfo (Main.Version, vcs.revision, vcs.time) when ldflags weren't injected. Also guard `cg update` against true dev builds where neither source provides a version. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
khooihzhz
approved these changes
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
go install github.com/coingecko/coingecko-cli@vX.Y.Zdoes not pass ldflags, so the resulting binary always reportedversion="dev". This brokecg version(showed "vdev"), the on-launch update reminder (skipped on "dev"), andcg update(offered to "upgrade" from "vdev" to the latest tag). Recover the real version fromruntime/debug.BuildInfowhen ldflags weren't injected, and guardcg updateagainst true dev builds where no version source is available.Changes
cmd/root.go: addresolveBuildInfo()which fills inversion,commit, anddatefromdebug.ReadBuildInfo()(Main.Version,vcs.revision, vcs.time) when the ldflag-injected values are still defaults. Called from
init()sorootCmd.Versionreflects theresolved value.
cmd/update.go: refuse to runcg updatewhenversionis still "dev" or empty after BuildInfo resolution — returns a clear errorpointing the user at the README install instructions instead of presenting a nonsense "vdev → vX.Y.Z" prompt.
cmd/update_test.go: addTestRunUpdate_RejectsDevBuildcovering both "dev" and empty-string cases; updateTestRunUpdate_InvalidMethodto set a real version so it isn't blocked by the new guard.Test plan
make testpasses locallygo install github.com/coingecko/coingecko-cli@v1.1.0thencoingecko-cli versionshowscg v1.1.0(notvdev)coingecko-cli updateon the go-installed binary correctly reports "Already up to date" or proceeds with a real versioncomparison
go build -o cg . && ./cg updatereturns the dev-build error (since plaingo buildhas no module BuildInfo with a release tag)make build && ./cg updateuses the ldflag-injected version as before (no regression for goreleaser/Homebrew builds)cg versionon the Homebrew binary still showscg v1.1.0with commit/date populated from ldflags (BuildInfo fallback onlyfills defaults)