fix(version): fall back to embedded build info when ldflags absent #130

Merged
lerko merged 1 commits from fix/version-buildinfo-fallback into main 2026-06-12 22:53:34 +00:00
Owner

Found during rc.4 housekeeping: go install gitea.lerkolabs.com/lerkolabs/uptop/cmd/uptop@v0.1.0-rc.4 works (proxy.golang.org reaches Gitea — verified cold-cache), but the resulting binary reports uptop dev because version injection is GoReleaser-ldflags-only.

Fix: an init() reads debug.ReadBuildInfo() when the ldflags defaults are untouched — info.Main.Version carries the requested module version for go-install builds, and vcs stamps fill commit/date for checkout builds. Feeds both --version and the TUI footer (same var).

Build path Before After
GoReleaser release 0.1.0-rc.4 (sha, date) unchanged
go install @tag dev 0.1.0-rc.4
go build in checkout dev Go-stamped pseudo-version + revision

printVersion now omits unknown commit/date instead of printing (none, unknown). Verified: release-sim ldflags build prints identically to today; local build prints stamped version; cmd tests + lint green.

Found during rc.4 housekeeping: `go install gitea.lerkolabs.com/lerkolabs/uptop/cmd/uptop@v0.1.0-rc.4` works (proxy.golang.org reaches Gitea — verified cold-cache), but the resulting binary reports `uptop dev` because version injection is GoReleaser-ldflags-only. Fix: an `init()` reads `debug.ReadBuildInfo()` when the ldflags defaults are untouched — `info.Main.Version` carries the requested module version for go-install builds, and vcs stamps fill commit/date for checkout builds. Feeds both `--version` and the TUI footer (same var). | Build path | Before | After | |---|---|---| | GoReleaser release | `0.1.0-rc.4 (sha, date)` | unchanged | | `go install @tag` | `dev` | `0.1.0-rc.4` | | `go build` in checkout | `dev` | Go-stamped pseudo-version + revision | `printVersion` now omits unknown commit/date instead of printing `(none, unknown)`. Verified: release-sim ldflags build prints identically to today; local build prints stamped version; cmd tests + lint green.
lerko added 1 commit 2026-06-12 22:41:44 +00:00
fix(version): fall back to embedded build info when ldflags absent
CI / test (pull_request) Successful in 1m49s
CI / lint (pull_request) Successful in 1m11s
CI / vulncheck (pull_request) Successful in 51s
9ee5908af5
go install module@tag compiles without GoReleaser's ldflags, so
--version reported "dev" and the TUI footer matched. The module
version and vcs stamps are embedded in every binary; read them via
debug.ReadBuildInfo when the ldflags defaults are untouched. Release
builds unchanged — ldflags still win.
lerko merged commit 9ee5908af5 into main 2026-06-12 22:53:34 +00:00
lerko deleted branch fix/version-buildinfo-fallback 2026-06-12 22:53:34 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: lerkolabs/uptop#130