Skip to content

fix: recover version from BuildInfo for go-installed binaries#26

Merged
irisyann merged 1 commit into
mainfrom
fix/version-buildinfo-fallback
May 7, 2026
Merged

fix: recover version from BuildInfo for go-installed binaries#26
irisyann merged 1 commit into
mainfrom
fix/version-buildinfo-fallback

Conversation

@irisyann
Copy link
Copy Markdown
Contributor

@irisyann irisyann commented May 7, 2026

Summary

go install github.com/coingecko/coingecko-cli@vX.Y.Z does not pass ldflags, so the resulting binary always reported version="dev". This broke cg version (showed "vdev"), the on-launch update reminder (skipped on "dev"), and cg update (offered to "upgrade" from "vdev" to the latest tag). Recover the real version from runtime/debug.BuildInfo when ldflags weren't injected, and guard cg update against true dev builds where no version source is available.

Changes

  • cmd/root.go: add resolveBuildInfo() which fills in version, commit, and date from debug.ReadBuildInfo() (Main.Version,
    vcs.revision, vcs.time) when the ldflag-injected values are still defaults. Called from init() so rootCmd.Version reflects the
    resolved value.
  • cmd/update.go: refuse to run cg update when version is still "dev" or empty after BuildInfo resolution — returns a clear error
    pointing the user at the README install instructions instead of presenting a nonsense "vdev → vX.Y.Z" prompt.
  • cmd/update_test.go: add TestRunUpdate_RejectsDevBuild covering both "dev" and empty-string cases; update
    TestRunUpdate_InvalidMethod to set a real version so it isn't blocked by the new guard.

Test plan

  • make test passes locally
  • go install github.com/coingecko/coingecko-cli@v1.1.0 then coingecko-cli version shows cg v1.1.0 (not vdev)
  • coingecko-cli update on the go-installed binary correctly reports "Already up to date" or proceeds with a real version
    comparison
  • go build -o cg . && ./cg update returns the dev-build error (since plain go build has no module BuildInfo with a release tag)
  • make build && ./cg update uses the ldflag-injected version as before (no regression for goreleaser/Homebrew builds)
  • cg version on the Homebrew binary still shows cg v1.1.0 with commit/date populated from ldflags (BuildInfo fallback only
    fills defaults)

`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>
@irisyann irisyann self-assigned this May 7, 2026
@irisyann irisyann requested a review from a team May 7, 2026 06:37
@irisyann irisyann merged commit c4ca69a into main May 7, 2026
3 checks passed
@irisyann irisyann deleted the fix/version-buildinfo-fallback branch May 7, 2026 08:46
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 this pull request may close these issues.

2 participants