-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathversion.go
More file actions
39 lines (32 loc) · 831 Bytes
/
version.go
File metadata and controls
39 lines (32 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright IBM Corp. 2023, 2026
// SPDX-License-Identifier: MPL-2.0
package main
import (
"fmt"
"runtime/debug"
)
var (
// These vars will be set by goreleaser.
version string
commit string
)
func getVersion() string {
// Prefer global version as it's set by goreleaser via ldflags
// https://goreleaser.com/cookbooks/using-main.version/
if version != "" {
if commit != "" {
version = fmt.Sprintf("%s from commit: %s", version, commit)
}
return version
}
// If not built with goreleaser, check the binary for VCS revision/module version info
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return fmt.Sprintf("commit: %s", setting.Value)
}
}
return fmt.Sprintf("module: %s", info.Main.Version)
}
return "local"
}