2023-12-06 15:24:02 +01:00
|
|
|
package generator
|
|
|
|
|
2024-11-26 16:47:37 +01:00
|
|
|
import (
|
2025-07-10 15:15:25 +02:00
|
|
|
"regexp"
|
2024-11-26 16:47:37 +01:00
|
|
|
"runtime/debug"
|
2025-08-22 08:33:32 +00:00
|
|
|
"strings"
|
2024-11-26 16:47:37 +01:00
|
|
|
)
|
|
|
|
|
2023-12-06 15:24:02 +01:00
|
|
|
// Version is the version of katenary. It is set at compile time.
|
|
|
|
var Version = "master" // changed at compile time
|
2024-11-26 16:47:37 +01:00
|
|
|
|
|
|
|
// GetVersion return the version of katneary. It's important to understand that
|
|
|
|
// the version is set at compile time for the github release. But, it the user get
|
|
|
|
// katneary using `go install`, the version should be different.
|
|
|
|
func GetVersion() string {
|
2025-07-10 15:15:25 +02:00
|
|
|
// try to get the semantic version from the Version variable (theorically set at compile time)
|
2025-07-11 09:17:33 +02:00
|
|
|
if reg := regexp.MustCompile(`^v?\d+.\d+.\d+.*|^release-.*`); reg.MatchString(Version) {
|
2025-08-22 08:33:32 +00:00
|
|
|
Version = strings.Replace(Version, "release-", "v", 1)
|
|
|
|
if Version[0] != 'v' {
|
|
|
|
Version = "v" + Version
|
|
|
|
}
|
2024-11-26 16:47:37 +01:00
|
|
|
return Version
|
|
|
|
}
|
2025-08-22 08:33:32 +00:00
|
|
|
if reg := regexp.MustCompile(`^releases/.*`); reg.MatchString(Version) {
|
|
|
|
return strings.Replace(Version, "releases/", "v", 1)
|
|
|
|
}
|
2025-07-10 15:15:25 +02:00
|
|
|
|
|
|
|
// OK... let's try to get the version from the build info
|
|
|
|
// get the version from the build info (when installed with go install)
|
2025-07-11 09:17:33 +02:00
|
|
|
if v, ok := debug.ReadBuildInfo(); ok {
|
2024-11-26 16:47:37 +01:00
|
|
|
return v.Main.Version + "-" + v.GoVersion
|
|
|
|
}
|
2025-07-10 15:15:25 +02:00
|
|
|
|
|
|
|
// OK... none worked, so we return the default version
|
2024-11-26 16:47:37 +01:00
|
|
|
return Version
|
|
|
|
}
|