[cli] Pick version from the github tag
This commit is contained in:
parent
2711a227fc
commit
e42422407c
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
const AppVersion = "0.1.11"
|
var version string
|
||||||
|
|
||||||
var ctrl *pkg.ClICtrl
|
var ctrl *pkg.ClICtrl
|
||||||
|
|
||||||
|
@ -34,8 +34,9 @@ func GenerateDocs() error {
|
||||||
|
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||||
func Execute(controller *pkg.ClICtrl) {
|
func Execute(controller *pkg.ClICtrl, ver string) {
|
||||||
ctrl = controller
|
ctrl = controller
|
||||||
|
version = ver
|
||||||
err := rootCmd.Execute()
|
err := rootCmd.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -12,7 +12,7 @@ var versionCmd = &cobra.Command{
|
||||||
Short: "Prints the current version",
|
Short: "Prints the current version",
|
||||||
Long: ``,
|
Long: ``,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
fmt.Printf("Version %s\n", AppVersion)
|
fmt.Printf("Version %s\n", version)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var AppVersion = "0.1.12"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cliDBPath, err := GetCLIConfigPath()
|
cliDBPath, err := GetCLIConfigPath()
|
||||||
if secrets.IsRunningInContainer() {
|
if secrets.IsRunningInContainer() {
|
||||||
|
@ -73,7 +75,7 @@ func main() {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cmd.Execute(&ctrl)
|
cmd.Execute(&ctrl, AppVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initConfig(cliConfigPath string) {
|
func initConfig(cliConfigPath string) {
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Fetch the latest tag that starts with "cli-"
|
||||||
|
# shellcheck disable=SC2046
|
||||||
|
# shellcheck disable=SC2006
|
||||||
|
LATEST_TAG=$(git describe --tags `git rev-list --tags='cli-*' --max-count=1`)
|
||||||
|
|
||||||
|
# Check if the LATEST_TAG variable is empty
|
||||||
|
if [ -z "$LATEST_TAG" ]; then
|
||||||
|
echo "No 'cli-' tag found. Exiting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
VERSION=${LATEST_TAG#cli-}
|
||||||
# Create a "bin" directory if it doesn't exist
|
# Create a "bin" directory if it doesn't exist
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
|
|
||||||
|
@ -29,7 +40,7 @@ do
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Build the binary and place it in the "bin" directory
|
# Build the binary and place it in the "bin" directory
|
||||||
go build -ldflags="-s -w" -trimpath -o "bin/$BINARY_NAME" main.go
|
go build -ldflags="-X main.AppVersion=${VERSION} -s -w" -trimpath -o "bin/$BINARY_NAME" main.go
|
||||||
|
|
||||||
# Print a message indicating the build is complete for the current OS and architecture
|
# Print a message indicating the build is complete for the current OS and architecture
|
||||||
echo "Built for $OS ($ARCH) as bin/$BINARY_NAME"
|
echo "Built for $OS ($ARCH) as bin/$BINARY_NAME"
|
||||||
|
|
Loading…
Reference in a new issue