[cli] Pick version from the github tag

This commit is contained in:
Neeraj Gupta 2024-03-13 11:38:30 +05:30 committed by Neeraj Gupta
parent 2711a227fc
commit e42422407c
4 changed files with 19 additions and 5 deletions

View file

@ -12,7 +12,7 @@ import (
"github.com/spf13/cobra"
)
const AppVersion = "0.1.11"
var version string
var ctrl *pkg.ClICtrl
@ -34,8 +34,9 @@ func GenerateDocs() error {
// 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.
func Execute(controller *pkg.ClICtrl) {
func Execute(controller *pkg.ClICtrl, ver string) {
ctrl = controller
version = ver
err := rootCmd.Execute()
if err != nil {
os.Exit(1)

View file

@ -12,7 +12,7 @@ var versionCmd = &cobra.Command{
Short: "Prints the current version",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Version %s\n", AppVersion)
fmt.Printf("Version %s\n", version)
},
}

View file

@ -15,6 +15,8 @@ import (
"strings"
)
var AppVersion = "0.1.12"
func main() {
cliDBPath, err := GetCLIConfigPath()
if secrets.IsRunningInContainer() {
@ -73,7 +75,7 @@ func main() {
}
return
}
cmd.Execute(&ctrl)
cmd.Execute(&ctrl, AppVersion)
}
func initConfig(cliConfigPath string) {

View file

@ -1,5 +1,16 @@
#!/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
mkdir -p bin
@ -29,7 +40,7 @@ do
fi
# 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
echo "Built for $OS ($ARCH) as bin/$BINARY_NAME"