chore(version): Get the version following how katenary is installed
This commit is contained in:
3
Makefile
3
Makefile
@@ -7,7 +7,8 @@ PREFIX=~/.local
|
|||||||
GOVERSION=1.23
|
GOVERSION=1.23
|
||||||
GO=container
|
GO=container
|
||||||
OUT=katenary
|
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
|
GOOS=linux
|
||||||
GOARCH=amd64
|
GOARCH=amd64
|
||||||
SIGNER=metal3d@gmail.com
|
SIGNER=metal3d@gmail.com
|
||||||
|
@@ -35,7 +35,7 @@ func buildRootCmd() *cobra.Command {
|
|||||||
}
|
}
|
||||||
rootCmd.Example = ` katenary convert -c docker-compose.yml -o ./charts`
|
rootCmd.Example = ` katenary convert -c docker-compose.yml -o ./charts`
|
||||||
|
|
||||||
rootCmd.Version = generator.Version
|
rootCmd.Version = generator.GetVersion()
|
||||||
rootCmd.CompletionOptions.DisableDescriptions = false
|
rootCmd.CompletionOptions.DisableDescriptions = false
|
||||||
rootCmd.CompletionOptions.DisableNoDescFlag = false
|
rootCmd.CompletionOptions.DisableNoDescFlag = false
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ func generateVersionCommand() *cobra.Command {
|
|||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Print the version number of Katenary",
|
Short: "Print the version number of Katenary",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
println(generator.Version)
|
println(generator.GetVersion())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,24 @@
|
|||||||
package generator
|
package generator
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime/debug"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
// Version is the version of katenary. It is set at compile time.
|
// Version is the version of katenary. It is set at compile time.
|
||||||
var Version = "master" // changed 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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user