Skip to content

Fix version output for go install installations #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2025

Conversation

fgksgf
Copy link
Member

@fgksgf fgksgf commented Jul 7, 2025

Summary

Fixes the issue where license-eye --version outputs version dev instead of the correct version number when installed via go install.

Problem

When users install license-eye using go install github.com/apache/skywalking-eyes/cmd/[email protected], the version command shows "dev" instead of "v0.7.0". This happens because:

  1. go install builds directly from source without using the Makefile
  2. The Makefile uses -ldflags to inject version information at build time
  3. Without these build flags, the version defaults to "dev"

Solution

Added a fallback mechanism that reads version information from Go's build metadata when ldflags injection is not available:

  1. First priority: Version injected via -ldflags (existing behavior)
  2. Second priority: Version from runtime/debug.ReadBuildInfo() (new fallback)
  3. Last resort: "dev" (existing default)

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 <[email protected]>
@fgksgf fgksgf requested a review from Copilot July 7, 2025 08:19
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/debug and added an init function to override the version variable 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 init fallback correctly reads info.Main.Version and updates the version variable as expected.
func init() {

@fgksgf fgksgf added this to the 0.8.0 milestone Jul 7, 2025
@wu-sheng wu-sheng requested a review from kezhenxu94 July 7, 2025 08:56
@kezhenxu94 kezhenxu94 merged commit 9a20e0c into main Jul 7, 2025
1 check passed
@fgksgf fgksgf deleted the fix-version-output-for-go-install branch July 7, 2025 09:08
@liubog2008
Copy link

@kezhenxu94 Could you please release a new version?

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.

3 participants