Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[cli] Pick version from the github tag

Neeraj Guptae42422407ccd
diff --git a/cli/cmd/root.go b/cli/cmd/root.go
index 0b53f41622..e7f3378a44 100644
--- a/cli/cmd/root.go
+++ b/cli/cmd/root.go
@@ -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)
diff --git a/cli/cmd/version.go b/cli/cmd/version.go
index 9d5194bc77..3431bcfc31 100644
--- a/cli/cmd/version.go
+++ b/cli/cmd/version.go
@@ -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)
},
}
diff --git a/cli/main.go b/cli/main.go
index f9ad0fa067..157c11fd87 100644
--- a/cli/main.go
+++ b/cli/main.go
@@ -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) {
diff --git a/cli/release.sh b/cli/release.sh
index ac0106bd07..b3946c3810 100755
--- a/cli/release.sh
+++ b/cli/release.sh
@@ -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"