This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-eyes.git
The following commit(s) were added to refs/heads/main by this push:
new 9a20e0c Fix version output for go install installations (#203)
9a20e0c is described below
commit 9a20e0c14c8dead3404be1b92c78d4ad048c1144
Author: Hoshea <[email protected]>
AuthorDate: Mon Jul 7 16:58:29 2025 +0800
Fix version output for go install installations (#203)
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]>
---
commands/version.go | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/commands/version.go b/commands/version.go
index 6d1772f..c84b155 100644
--- a/commands/version.go
+++ b/commands/version.go
@@ -17,4 +17,17 @@
package commands
+import (
+ "runtime/debug"
+)
+
var version = "dev"
+
+func init() {
+ // Try to get version from build info first (for go install)
+ if info, ok := debug.ReadBuildInfo(); ok {
+ if info.Main.Version != "" && info.Main.Version != "(devel)" {
+ version = info.Main.Version
+ }
+ }
+}