Skip to content

Fix version output for go install installations#203

Merged
kezhenxu94 merged 1 commit intomainfrom
fix-version-output-for-go-install
Jul 7, 2025
Merged

Fix version output for go install installations#203
kezhenxu94 merged 1 commit intomainfrom
fix-version-output-for-go-install

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/license-eye@v0.7.0, 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 <noreply@anthropic.com>
@fgksgf fgksgf requested a review from Copilot July 7, 2025 08:19
Copy link

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.

4 participants