diff --git a/Makefile b/Makefile index 861dffe..0cae1a5 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,8 @@ PREFIX=~/.local GOVERSION=1.23 GO=container OUT=katenary -BLD_CMD=go build -ldflags="-X 'katenary/generator.Version=$(VERSION)'" -o $(OUT) ./cmd/katenary +RELEASE="" +BLD_CMD=go build -ldflags="-X 'katenary/generator.Version=$(RELEASE)$(VERSION)'" -o $(OUT) ./cmd/katenary GOOS=linux GOARCH=amd64 SIGNER=metal3d@gmail.com diff --git a/cmd/katenary/main.go b/cmd/katenary/main.go index f6da974..bcdf2ba 100644 --- a/cmd/katenary/main.go +++ b/cmd/katenary/main.go @@ -35,7 +35,7 @@ func buildRootCmd() *cobra.Command { } rootCmd.Example = ` katenary convert -c docker-compose.yml -o ./charts` - rootCmd.Version = generator.Version + rootCmd.Version = generator.GetVersion() rootCmd.CompletionOptions.DisableDescriptions = false rootCmd.CompletionOptions.DisableNoDescFlag = false @@ -233,7 +233,7 @@ func generateVersionCommand() *cobra.Command { Use: "version", Short: "Print the version number of Katenary", Run: func(cmd *cobra.Command, args []string) { - println(generator.Version) + println(generator.GetVersion()) }, } } diff --git a/generator/version.go b/generator/version.go index 9602118..b528773 100644 --- a/generator/version.go +++ b/generator/version.go @@ -1,4 +1,24 @@ package generator +import ( + "runtime/debug" + "strings" +) + // Version is the version of katenary. It is set at compile time. var Version = "master" // changed at compile time + +// 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 { + if strings.HasPrefix(Version, "release-") { + return Version + } + // get the version from the build info + v, ok := debug.ReadBuildInfo() + if ok { + return v.Main.Version + "-" + v.GoVersion + } + return Version +}