fix(version): report module version for go-install builds#68
Merged
Conversation
Binaries installed with 'go install github.com/api7/a7/cmd/a7@<tag>' bypass the Makefile/GoReleaser ldflags, so 'a7 version' reported 'dev' with unknown commit and date. Fall back to runtime/debug.ReadBuildInfo: the Go module version fills Version, and vcs.revision/vcs.time fill Commit/Date for source builds. Values injected via ldflags still take precedence. This also fixes 'a7 update' treating go-installed binaries as dev builds when comparing against the latest release. Audited for the same bug class: internal/version is the only ldflags-injected metadata in the repo.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR enhances the version package to resolve build metadata from Go's runtime debug info at startup. It imports ChangesBuild Metadata Resolution
🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
5 tasks
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
a7 versionreportsdevwith unknown commit/date when the binary is installed withgo install github.com/api7/a7/cmd/a7@v1.0.0. The version fields are only populated via-ldflags -X(Makefile / GoReleaser), whichgo installnever applies.internal/versionnow falls back toruntime/debug.ReadBuildInfo():Version: filled from the Go module version (e.g.v1.0.0) when not injected via ldflagsCommit/Date: filled from thevcs.revision/vcs.timebuild settings when available (source builds)make buildand GoReleaser output are unchangedThis also fixes
a7 updatefor go-installed binaries: it no longer hits thedevbuild path and can compare the current version against the latest release.Test plan
internal/version/version_test.go)go build ./... && go test ./...passesgo install github.com/api7/a7/cmd/a7@<tag>previously printeddev, now prints the tag versiongo buildfrom a clone now reports version, commit, and build time from VCS infoTestVersion,TestVersion_ContainsCommitInfo) only assert output shape, unaffectedBug-class audit
Class: build metadata that only exists when ldflags are applied.
internal/versionis the only ldflags-injected metadata in the repo (checked Makefile and .goreleaser.yml), so no other call sites are affected. The same bug exists in a6 and is fixed by the matching PR api7/a6#55.Summary by CodeRabbit