Fix version output for go install installations#203
Merged
kezhenxu94 merged 1 commit intomainfrom Jul 7, 2025
Merged
Conversation
When users install license-eye via `go install`, the version shows "dev" instead of the correct version number. This happens because go install doesn't use the Makefile's -ldflags to inject version information. This fix adds a fallback mechanism that reads version information from build metadata when ldflags injection is not available, while maintaining full compatibility with existing build processes. Changes: - Add runtime/debug import to read build information - Implement version fallback: ldflags → build info → "dev" - Maintain backward compatibility with existing Makefile builds - Users installing via go install will now see correct version 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull Request Overview
Adds a fallback mechanism to read version information from Go build metadata when ldflags injection isn’t available, ensuring license-eye --version reports the correct module version on go install.
- Imported
runtime/debugand added aninitfunction to override theversionvariable based on build info. - Retains the default
"dev"fallback if no valid version is found.
Comments suppressed due to low confidence (2)
commands/version.go:27
- [nitpick] Expand this comment to explain the full version resolution order (1. ldflags override, 2. build info, 3. default) so future maintainers understand the intended priority.
// Try to get version from build info first (for go install)
commands/version.go:26
- Add a unit test (or integration test) to verify that when no ldflags are provided, the
initfallback correctly readsinfo.Main.Versionand updates theversionvariable as expected.
func init() {
kezhenxu94
approved these changes
Jul 7, 2025
|
@kezhenxu94 Could you please release a new version? |
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
Fixes the issue where
license-eye --versionoutputsversion devinstead of the correct version number when installed viago install.Problem
When users install license-eye using
go install github.com/apache/skywalking-eyes/cmd/license-eye@v0.7.0, the version command shows "dev" instead of "v0.7.0". This happens because:go installbuilds directly from source without using the Makefile-ldflagsto inject version information at build timeSolution
Added a fallback mechanism that reads version information from Go's build metadata when ldflags injection is not available:
-ldflags(existing behavior)runtime/debug.ReadBuildInfo()(new fallback)