Skip to content

Commit 65f8e5e

Browse files
authored
internal/version: make version available when installed via go install github.com/elastic/elastic-package (#648)
This makes to output of elastic-package version informative when the go.mod-based install within integrations is used.
1 parent 692de4c commit 65f8e5e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

internal/version/version.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package version
66

77
import (
8+
"runtime/debug"
89
"strconv"
910
"time"
1011
)
@@ -20,6 +21,17 @@ var (
2021
Tag string
2122
)
2223

24+
// Set Tag to version stored in modinfo if it is not available from the builder.
25+
func init() {
26+
if Tag != "" {
27+
return
28+
}
29+
info, ok := debug.ReadBuildInfo()
30+
if ok && info.Main.Version != "(devel)" {
31+
Tag = info.Main.Version
32+
}
33+
}
34+
2335
// BuildTimeFormatted method returns the build time preserving the RFC3339 format.
2436
func BuildTimeFormatted() string {
2537
if BuildTime == "unknown" {

0 commit comments

Comments
 (0)