From 3246968a34a375e0b4a4003d7127f75d32556207 Mon Sep 17 00:00:00 2001 From: ZeljkoBenovic Date: Wed, 17 Aug 2022 12:39:22 +0200 Subject: [PATCH 1/3] Added more information to the version command * Added commit hash info * Added build timestamp info * Renamed version to Release version --- Makefile | 9 +++++++-- command/version/result.go | 11 +++++++++-- command/version/version.go | 4 +++- versioning/versioning.go | 6 +++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 190aa3b9f6..9fb2c5b210 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,13 @@ protoc: .PHONY: build build: $(eval LATEST_VERSION = $(shell git describe --tags --abbrev=0)) - $(eval COMMIT_HASH = $(shell git rev-parse --short HEAD)) - go build -ldflags="-X 'github.com/0xPolygon/polygon-edge/versioning.Version=$(LATEST_VERSION)+$(COMMIT_HASH)'" main.go + $(eval COMMIT_HASH = $(shell git rev-parse HEAD)) + $(eval TIME = $(shell date)) + go build -o polygon-edge -ldflags="\ + -X 'github.com/0xPolygon/polygon-edge/versioning.Version=$(LATEST_VERSION)' \ + -X 'github.com/0xPolygon/polygon-edge/versioning.Commit=$(COMMIT_HASH)'\ + -X 'github.com/0xPolygon/polygon-edge/versioning.BuildTime=$(TIME)'" \ + main.go .PHONY: lint lint: diff --git a/command/version/result.go b/command/version/result.go index 4da1e21334..11b0bcfaf3 100644 --- a/command/version/result.go +++ b/command/version/result.go @@ -1,9 +1,16 @@ package version +import "fmt" + type VersionResult struct { - Version string `json:"version"` + Version string `json:"version"` + Commit string `json:"commit"` + BuildTime string `json:"buildTime"` } func (r *VersionResult) GetOutput() string { - return r.Version + return fmt.Sprintf("\n[VERSION INFO]\n"+ + "Release version: %s \n"+ + "Commit hash: %s\n"+ + "Build time: %s", r.Version, r.Commit, r.BuildTime) } diff --git a/command/version/version.go b/command/version/version.go index b8f5e30854..a44091c3b1 100644 --- a/command/version/version.go +++ b/command/version/version.go @@ -21,7 +21,9 @@ func runCommand(cmd *cobra.Command, _ []string) { outputter.SetCommandResult( &VersionResult{ - Version: versioning.Version, + Version: versioning.Version, + Commit: versioning.Commit, + BuildTime: versioning.BuildTime, }, ) } diff --git a/versioning/versioning.go b/versioning/versioning.go index 354640ddab..be9838504c 100644 --- a/versioning/versioning.go +++ b/versioning/versioning.go @@ -2,8 +2,12 @@ package versioning var ( // Version is the main version at the moment. + // Commit is the git commit that the binary was built on + // BuildTime is the timestamp of the build // Embedded by --ldflags on build time // Versioning should follow the SemVer guidelines // https://semver.org/ - Version = "v0.1.0" + Version string + Commit string + BuildTime string ) From 021d6c2961b67719c67c11a675411d085f3fc634 Mon Sep 17 00:00:00 2001 From: ZeljkoBenovic Date: Wed, 31 Aug 2022 21:44:56 +0200 Subject: [PATCH 2/3] added git branch info --- Makefile | 2 ++ command/version/result.go | 4 +++- command/version/version.go | 1 + versioning/versioning.go | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9fb2c5b210..3ee276f86f 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,12 @@ protoc: build: $(eval LATEST_VERSION = $(shell git describe --tags --abbrev=0)) $(eval COMMIT_HASH = $(shell git rev-parse HEAD)) + $(eval BRANCH = $(shell git rev-parse --abbrev-ref HEAD | tr -d '\040\011\012\015\n')) $(eval TIME = $(shell date)) go build -o polygon-edge -ldflags="\ -X 'github.com/0xPolygon/polygon-edge/versioning.Version=$(LATEST_VERSION)' \ -X 'github.com/0xPolygon/polygon-edge/versioning.Commit=$(COMMIT_HASH)'\ + -X 'github.com/0xPolygon/polygon-edge/versioning.Branch=$(BRANCH)'\ -X 'github.com/0xPolygon/polygon-edge/versioning.BuildTime=$(TIME)'" \ main.go diff --git a/command/version/result.go b/command/version/result.go index 11b0bcfaf3..6f78330cc4 100644 --- a/command/version/result.go +++ b/command/version/result.go @@ -5,12 +5,14 @@ import "fmt" type VersionResult struct { Version string `json:"version"` Commit string `json:"commit"` + Branch string `json:"branch"` BuildTime string `json:"buildTime"` } func (r *VersionResult) GetOutput() string { return fmt.Sprintf("\n[VERSION INFO]\n"+ "Release version: %s \n"+ + "Git branch: %s\n"+ "Commit hash: %s\n"+ - "Build time: %s", r.Version, r.Commit, r.BuildTime) + "Build time: %s", r.Version, r.Branch, r.Commit, r.BuildTime) } diff --git a/command/version/version.go b/command/version/version.go index a44091c3b1..b71e889247 100644 --- a/command/version/version.go +++ b/command/version/version.go @@ -23,6 +23,7 @@ func runCommand(cmd *cobra.Command, _ []string) { &VersionResult{ Version: versioning.Version, Commit: versioning.Commit, + Branch: versioning.Branch, BuildTime: versioning.BuildTime, }, ) diff --git a/versioning/versioning.go b/versioning/versioning.go index be9838504c..05bfa70ed6 100644 --- a/versioning/versioning.go +++ b/versioning/versioning.go @@ -8,6 +8,7 @@ var ( // Versioning should follow the SemVer guidelines // https://semver.org/ Version string + Branch string Commit string BuildTime string ) From f3eed73e61d93fbad1f36a453390a7ffc932cd36 Mon Sep 17 00:00:00 2001 From: ZeljkoBenovic Date: Fri, 2 Sep 2022 17:03:34 +0200 Subject: [PATCH 3/3] switch to helper.FormatKV output --- command/version/result.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/command/version/result.go b/command/version/result.go index 6f78330cc4..146dbee32c 100644 --- a/command/version/result.go +++ b/command/version/result.go @@ -1,6 +1,10 @@ package version -import "fmt" +import ( + "bytes" + "fmt" + "github.com/0xPolygon/polygon-edge/command/helper" +) type VersionResult struct { Version string `json:"version"` @@ -10,9 +14,15 @@ type VersionResult struct { } func (r *VersionResult) GetOutput() string { - return fmt.Sprintf("\n[VERSION INFO]\n"+ - "Release version: %s \n"+ - "Git branch: %s\n"+ - "Commit hash: %s\n"+ - "Build time: %s", r.Version, r.Branch, r.Commit, r.BuildTime) + var buffer bytes.Buffer + + buffer.WriteString("\n[VERSION INFO]\n") + buffer.WriteString(helper.FormatKV([]string{ + fmt.Sprintf("Release version|%s", r.Version), + fmt.Sprintf("Git branch|%s", r.Branch), + fmt.Sprintf("Commit hash|%s", r.Commit), + fmt.Sprintf("Build time|%s", r.BuildTime), + })) + + return buffer.String() }