Updated makefile to include git commit

This commit is contained in:
Carlos Salguero
2019-09-07 16:16:44 -03:00
parent 8af89a638d
commit 737c5de9af
5 changed files with 47 additions and 38 deletions

View File

@@ -3,13 +3,14 @@ pkgs = $(shell find . -type d -name "pt-*" -exec basename {} \;)
VERSION="3.0.13"
BUILD=$(shell date +%FT%T%z)
GOVERSION=$(shell go version | cut --delimiter=" " -f3)
COMMIT=$(shell git rev-list -1 HEAD)
GOUTILSDIR ?= $(GOPATH)/bin
PREFIX=$(shell pwd)
TOP_DIR=$(shell git rev-parse --show-toplevel)
BIN_DIR=$(shell git rev-parse --show-toplevel)/bin
SRC_DIR=$(shell git rev-parse --show-toplevel)/src/go
LDFLAGS="-X main.Version=${VERSION} -X main.Build=${BUILD} -X main.GoVersion=${GOVERSION} -s -w"
LDFLAGS="-X main.Version=${VERSION} -X main.Build=${BUILD} -X main.GoVersion=${GOVERSION} -X main.Commit=${COMMIT} -s -w"
TEST_PSMDB_VERSION?=3.6
TEST_MONGODB_FLAVOR?=percona/percona-server-mongodb

View File

@@ -38,9 +38,10 @@ const (
)
var (
Build string = "01-01-1980"
GoVersion string = "1.8"
Version string = "3.0.1"
Build string = "01-01-1980" //nolint
GoVersion string = "1.8" //nolint
Version string = "3.0.1" //nolint
Commit string //nolint
)
type cliOptions struct {
@@ -90,6 +91,7 @@ func main() {
fmt.Println(TOOLNAME)
fmt.Printf("Version %s\n", Version)
fmt.Printf("Build: %s using %s\n", Build, GoVersion)
fmt.Printf("Commit: %s\n", Commit)
return
}
@@ -98,10 +100,8 @@ func main() {
advice, err := versioncheck.CheckUpdates(TOOLNAME, Version)
if err != nil {
log.Infof("cannot check version updates: %s", err.Error())
} else {
if advice != "" {
log.Warn(advice)
}
} else if advice != "" {
log.Warn(advice)
}
}

View File

@@ -41,9 +41,10 @@ const (
)
var (
Build string = "01-01-1980"
GoVersion string = "1.8"
Version string = "3.0.1"
Build string = "01-01-1980" // nolint
GoVersion string = "1.8" // nolint
Version string = "3.0.1" // nolint
Commit string // nolint
)
type TimedStats struct {
@@ -126,20 +127,20 @@ type clusterwideInfo struct {
}
type cliOptions struct {
Help bool
Host string
User string
Password string
AuthDB string
LogLevel string
OutputFormat string
SSLCAFile string
SSLPEMKeyFile string
RunningOpsSamples int
RunningOpsInterval int
Help bool
Version bool
NoVersionCheck bool
NoRunningOps bool
OutputFormat string
RunningOpsSamples int
RunningOpsInterval int
SSLCAFile string
SSLPEMKeyFile string
}
type collectedInfo struct {
@@ -179,6 +180,7 @@ func main() {
fmt.Println(TOOLNAME)
fmt.Printf("Version %s\n", Version)
fmt.Printf("Build: %s using %s\n", Build, GoVersion)
fmt.Printf("Commit: %s\n", Commit)
return
}
@@ -187,10 +189,8 @@ func main() {
advice, err := versioncheck.CheckUpdates(TOOLNAME, Version)
if err != nil {
log.Infof("cannot check version updates: %s", err.Error())
} else {
if advice != "" {
log.Infof(advice)
}
} else if advice != "" {
log.Infof(advice)
}
}
@@ -203,9 +203,12 @@ func main() {
if err := client.Connect(ctx); err != nil {
log.Fatalf("Cannot connect to MongoDB: %s", err)
}
defer client.Disconnect(ctx)
defer client.Disconnect(ctx) // nolint
hostnames, err := util.GetHostnames(ctx, client)
if err != nil {
log.Errorf("Cannot get hostnames: %s", err)
}
log.Debugf("hostnames: %v", hostnames)
ci := &collectedInfo{}
@@ -288,39 +291,39 @@ func formatResults(ci *collectedInfo, format string) ([]byte, error) {
t := template.Must(template.New("replicas").Parse(templates.Replicas))
if err := t.Execute(buf, ci.ReplicaMembers); err != nil {
return nil, errors.Wrap(err, "cannnot parse replicas section of the output template")
return nil, errors.Wrap(err, "cannot parse replicas section of the output template")
}
t = template.Must(template.New("hosttemplateData").Parse(templates.HostInfo))
if err := t.Execute(buf, ci.HostInfo); err != nil {
return nil, errors.Wrap(err, "cannnot parse hosttemplateData section of the output template")
return nil, errors.Wrap(err, "cannot parse hosttemplateData section of the output template")
}
t = template.Must(template.New("runningOps").Parse(templates.RunningOps))
if err := t.Execute(buf, ci.RunningOps); err != nil {
return nil, errors.Wrap(err, "cannnot parse runningOps section of the output template")
return nil, errors.Wrap(err, "cannot parse runningOps section of the output template")
}
t = template.Must(template.New("ssl").Parse(templates.Security))
if err := t.Execute(buf, ci.SecuritySettings); err != nil {
return nil, errors.Wrap(err, "cannnot parse ssl section of the output template")
return nil, errors.Wrap(err, "cannot parse ssl section of the output template")
}
if ci.OplogInfo != nil && len(ci.OplogInfo) > 0 {
t = template.Must(template.New("oplogInfo").Parse(templates.Oplog))
if err := t.Execute(buf, ci.OplogInfo[0]); err != nil {
return nil, errors.Wrap(err, "cannnot parse oplogInfo section of the output template")
return nil, errors.Wrap(err, "cannot parse oplogInfo section of the output template")
}
}
t = template.Must(template.New("clusterwide").Parse(templates.Clusterwide))
if err := t.Execute(buf, ci.ClusterWideInfo); err != nil {
return nil, errors.Wrap(err, "cannnot parse clusterwide section of the output template")
return nil, errors.Wrap(err, "cannot parse clusterwide section of the output template")
}
t = template.Must(template.New("balancer").Parse(templates.BalancerStats))
if err := t.Execute(buf, ci.BalancerStats); err != nil {
return nil, errors.Wrap(err, "cannnot parse balancer section of the output template")
return nil, errors.Wrap(err, "cannot parse balancer section of the output template")
}
}
@@ -566,7 +569,8 @@ func getNodeType(ctx context.Context, client *mongo.Client) (string, error) {
return "mongod", nil
}
func getOpCountersStats(ctx context.Context, client *mongo.Client, count int, sleep time.Duration) (*opCounters, error) {
func getOpCountersStats(ctx context.Context, client *mongo.Client, count int,
sleep time.Duration) (*opCounters, error) {
oc := &opCounters{}
prevOpCount := &opCounters{}
ss := proto.ServerStatus{}

View File

@@ -18,9 +18,10 @@ import (
)
var (
version = "dev"
commit = "none"
date = "unknown"
Build string = "01-01-1980" //nolint
Commit string //nolint
GoVersion string = "1.8" //nolint
Version string = "3.0.1" //nolint
)
type connOpts struct {
@@ -190,7 +191,8 @@ func safeConnString(opts connOpts, dbName string) string {
func parseCommandLineOpts(args []string) (cliOptions, error) {
app := kingpin.New("pt-pg-summary", "Percona Toolkit - PostgreSQL Summary")
// version, commit and date will be set at build time by the compiler -ldflags param
app.Version(fmt.Sprintf("%s version %s, git commit %s, date: %s", app.Name, version, commit, date))
app.Version(fmt.Sprintf("%s version %s\nGIT commit %s\nDate: %s\nGo version: %s",
app.Name, Version, Commit, Build, GoVersion))
opts := cliOptions{app: app}
app.Flag("ask-pass", "Prompt for a password when connecting to PostgreSQL").

View File

@@ -84,9 +84,10 @@ var (
"pt-mysql-summary --host=$mysql-host --port=$mysql-port --user=$mysql-user --password=$mysql-pass",
}
Build string = "01-01-1980"
GoVersion string = "1.8"
Version string = "3.0.1"
Build string = "01-01-1980" //nolint
GoVersion string = "1.8" //nolint
Version string = "3.0.1" //nolint
Commit string //nolint
)
func main() {
@@ -177,7 +178,8 @@ func processCliParams(baseTempPath string, usageWriter io.Writer) (*cliOptions,
}
// Add support for --version flag
app.Version(TOOLNAME + "\nVersion " + Version + "\nBuild: " + Build + " using " + GoVersion)
app.Version(TOOLNAME + "\nVersion " + Version + "\nBuild: " + Build + " using " + GoVersion +
" Go version: " + GoVersion)
opts := &cliOptions{
CollectCommand: app.Command(collectCmd, "Collect, sanitize, pack and encrypt data from pt-tools."),