Skip to content

Commit

Permalink
fix: inconsistent version number openGemini#520 (openGemini#522)
Browse files Browse the repository at this point in the history
Signed-off-by: Bomin Zhang <[email protected]>
  • Loading branch information
localvar authored Mar 8, 2024
1 parent a44507b commit cc84423
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 100 deletions.
22 changes: 17 additions & 5 deletions app/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,24 @@ Usage: %s run [flags]
Write process ID to a file.
`

const VERSION = `openGemini version info:
// Version information, the value is set by the build script
var (
Version string
GitCommit string
GitBranch string
BuildTime string
)

// FullVersion returns the full version string.
func FullVersion(app string) string {
const format = `openGemini version info:
%s: %s
git: %s %s
os: %s
arch: %s
`
arch: %s`

return fmt.Sprintf(format, app, Version, GitBranch, GitCommit, runtime.GOOS, runtime.GOARCH)
}

// Options represents the command line options that can be parsed.
type Options struct {
Expand Down Expand Up @@ -279,8 +291,8 @@ type ServerInfo struct {
BuildTime string
}

func (i *ServerInfo) FullVersion() string {
return fmt.Sprintf(VERSION, i.App, i.Version, i.Branch, i.Commit, runtime.GOOS, runtime.GOARCH)
func (si *ServerInfo) FullVersion() string {
return FullVersion(string(si.App))
}

func LogStarting(name string, info *ServerInfo) {
Expand Down
1 change: 0 additions & 1 deletion app/ts-cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var (

// Execute executes the root command.
func Execute() {
rootCmd.AddCommand()
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand Down
6 changes: 4 additions & 2 deletions app/ts-cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ limitations under the License.
package cmd

import (
"fmt"

"github.com/openGemini/openGemini/app"
"github.com/spf13/cobra"
)

const TsCli = "ts-cli"

func init() {
rootCmd.AddCommand(versionCmd)
}
Expand All @@ -31,5 +32,6 @@ var versionCmd = &cobra.Command{
Short: "Display the version of openGemini CLI",
Long: `Display the version of openGemini CLI.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(app.FullVersion("ts-cli"))
},
}
6 changes: 3 additions & 3 deletions app/ts-cli/geminicli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import (
"github.com/influxdata/influxdb/client"
"github.com/influxdata/influxdb/models"
"github.com/olekukonko/tablewriter"
"github.com/openGemini/openGemini/app"
"github.com/openGemini/openGemini/app/ts-cli/geminiql"
"github.com/openGemini/openGemini/lib/util/lifted/influx/influxql"
"golang.org/x/term"
)

const (
CLIENT_VERSION = "0.1.0"
DEFAULT_FORMAT = "column"
DEFAULT_HOST = "localhost"
DEFAULT_PORT = 8086
Expand Down Expand Up @@ -150,7 +150,7 @@ func (c *CommandLine) Connect(addr string) error {
config.URL = url
}

config.UserAgent = "openGemini CLI/" + CLIENT_VERSION
config.UserAgent = "openGemini CLI/" + app.Version
config.Proxy = http.ProxyFromEnvironment

client, err := c.clientCreator(config)
Expand Down Expand Up @@ -481,7 +481,7 @@ func (c *CommandLine) clientBatchPoints(db string, rp string, raw string) *clien
}

func (c *CommandLine) Run() error {
fmt.Printf("openGemini CLI %s (rev-%s)\n", CLIENT_VERSION, "revision")
fmt.Printf("openGemini CLI %s (rev-%s)\n", app.Version, "revision")
fmt.Println("Please use `quit`, `exit` or `Ctrl-D` to exit this program.")
completer := NewCompleter()
p := prompt.New(
Expand Down
11 changes: 0 additions & 11 deletions app/ts-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,20 @@ limitations under the License.
package main

import (
"fmt"
"os"
"runtime"

parse "github.com/influxdata/influxdb/cmd"
"github.com/openGemini/openGemini/app"
"github.com/openGemini/openGemini/app/ts-cli/analyzer"
"github.com/openGemini/openGemini/app/ts-cli/cmd"
)

var (
TsVersion = "v1.1.0rc0"
TsCommit string
TsBranch string
)

func main() {
doRun(os.Args[1:]...)
}

func doRun(args ...string) {
name, _ := parse.ParseCommandName(args)
switch name {
case "version":
fmt.Printf(app.VERSION, cmd.TsCli, TsVersion, TsBranch, TsCommit, runtime.GOOS, runtime.GOARCH)
case "analyze":
az := analyzer.NewAnalyzer()
az.Analyze(args[1])
Expand Down
15 changes: 4 additions & 11 deletions app/ts-data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,16 @@ import (
"github.com/openGemini/openGemini/lib/errno"
)

var (
TsVersion = "v1.1.0rc0"
TsCommit string
TsBranch string
TsBuildTime string
)

func main() {
app.InitParse()
errno.SetNode(errno.NodeData)

info := app.ServerInfo{
App: config.AppData,
Version: TsVersion,
Commit: TsCommit,
Branch: TsBranch,
BuildTime: TsBuildTime,
Version: app.Version,
Commit: app.GitCommit,
Branch: app.GitBranch,
BuildTime: app.BuildTime,
}

cmdStore := store.NewCommand(info, true)
Expand Down
15 changes: 4 additions & 11 deletions app/ts-meta/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,15 @@ import (
"github.com/openGemini/openGemini/lib/errno"
)

var (
TsVersion = "v1.1.0rc0"
TsCommit string
TsBranch string
TsBuildTime string
)

func main() {
errno.SetNode(errno.NodeMeta)
app.InitParse()
info := app.ServerInfo{
App: config.AppMeta,
Version: TsVersion,
Commit: TsCommit,
Branch: TsBranch,
BuildTime: TsBuildTime,
Version: app.Version,
Commit: app.GitCommit,
Branch: app.GitBranch,
BuildTime: app.BuildTime,
}

app.Run(os.Args[1:], run.NewCommand(info, true))
Expand Down
22 changes: 7 additions & 15 deletions app/ts-monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"fmt"
"os"
"runtime"

"github.com/VictoriaMetrics/VictoriaMetrics/lib/procutil"
"github.com/influxdata/influxdb/cmd"
Expand All @@ -33,13 +32,6 @@ import (
"go.uber.org/zap"
)

var (
TsVersion = "v1.1.0rc0"
TsCommit string
TsBranch string
TsBuildTime string
)

const TsMonitor = "ts-monitor"

var (
Expand Down Expand Up @@ -69,10 +61,10 @@ func doRun(args ...string) error {
mainCmd := app.NewCommand()
info := app.ServerInfo{
App: config.AppMonitor,
Version: TsVersion,
Commit: TsCommit,
Branch: TsBranch,
BuildTime: TsBuildTime,
Version: app.Version,
Commit: app.GitCommit,
Branch: app.GitBranch,
BuildTime: app.BuildTime,
}
mainCmd.Info = info
mainCmd.Logo = app.MONITORLOGO
Expand All @@ -86,8 +78,8 @@ func doRun(args ...string) error {
mainCmd.Logger = logger.NewLogger(errno.ModuleUnknown)
mainCmd.Command = &cobra.Command{
Use: monitorUsage,
Version: TsVersion,
ValidArgs: []string{TsBranch, TsCommit, TsBuildTime},
Version: app.Version,
ValidArgs: []string{app.GitBranch, app.GitCommit, app.BuildTime},
DisableFlagParsing: true,
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Fprint(os.Stdout, app.MONITORLOGO)
Expand Down Expand Up @@ -121,7 +113,7 @@ func doRun(args ...string) error {
util.MustClose(mainCmd)
mainCmd.Logger.Info("Monitor shutdown successfully!")
case "version":
fmt.Printf(app.VERSION, TsMonitor, TsVersion, TsBranch, TsCommit, runtime.GOOS, runtime.GOARCH)
fmt.Println(app.FullVersion(TsMonitor))
default:
return fmt.Errorf(monitorUsage)
}
Expand Down
15 changes: 4 additions & 11 deletions app/ts-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,16 @@ import (
"github.com/openGemini/openGemini/lib/errno"
)

var (
TsVersion = "v1.1.0rc0"
TsCommit string
TsBranch string
TsBuildTime string
)

func main() {
app.InitParse()
errno.SetNode(errno.NodeServer)

info := app.ServerInfo{
App: config.AppSingle,
Version: TsVersion,
Commit: TsCommit,
Branch: TsBranch,
BuildTime: TsBuildTime,
Version: app.Version,
Commit: app.GitCommit,
Branch: app.GitBranch,
BuildTime: app.BuildTime,
}

cmdMeta := meta.NewCommand(info, false)
Expand Down
15 changes: 4 additions & 11 deletions app/ts-sql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,15 @@ import (
"github.com/openGemini/openGemini/lib/errno"
)

var (
TsVersion = "v1.1.0rc0"
TsCommit string
TsBranch string
TsBuildTime string
)

func main() {
errno.SetNode(errno.NodeSql)
app.InitParse()
info := app.ServerInfo{
App: config.AppSql,
Version: TsVersion,
Commit: TsCommit,
Branch: TsBranch,
BuildTime: TsBuildTime,
Version: app.Version,
Commit: app.GitCommit,
Branch: app.GitBranch,
BuildTime: app.BuildTime,
}

app.Run(os.Args[1:], ingestserver.NewCommand(info))
Expand Down
15 changes: 4 additions & 11 deletions app/ts-store/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,15 @@ import (
"github.com/openGemini/openGemini/lib/errno"
)

var (
TsVersion = "v1.1.0rc0"
TsCommit string
TsBranch string
TsBuildTime string
)

func main() {
app.InitParse()
errno.SetNode(errno.NodeStore)
info := app.ServerInfo{
App: config.AppStore,
Version: TsVersion,
Commit: TsCommit,
Branch: TsBranch,
BuildTime: TsBuildTime,
Version: app.Version,
Commit: app.GitCommit,
Branch: app.GitBranch,
BuildTime: app.BuildTime,
}

app.Run(os.Args[1:], run.NewCommand(info, true))
Expand Down
17 changes: 9 additions & 8 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,17 @@ def build(version=None,
if len(tags) > 0:
build_command += "-tags {} ".format(','.join(tags))

if static:
build_command += "-ldflags=\"-s -X main.TsVersion={} -X main.TsBranch={} -X main.TsCommit={}\" ".format(version,
get_current_branch(),
get_current_commit())
else:
build_command += "-ldflags=\"-X main.TsVersion={} -X main.TsBranch={} -X main.TsCommit={}\" ".format(version,
get_current_branch(),
get_current_commit())
if static:
build_command += "-a -installsuffix cgo "
ldflags = "-ldflags=\"-s -X {package}.Version={version} -X {package}.GitBranch={branch} -X {package}.GitCommit={commit}\" "
else:
ldflags = "-ldflags=\"-X {package}.Version={version} -X {package}.GitBranch={branch} -X {package}.GitCommit={commit}\" "

build_command += ldflags.format(
package = "github.com/openGemini/openGemini/app",
version = version,
branch = get_current_branch(),
commit = get_current_commit())

build_command += path
start_time = datetime.utcnow()
Expand Down

0 comments on commit cc84423

Please sign in to comment.