From d374f38ce6cf7e77d2529424c911d7a96bad7543 Mon Sep 17 00:00:00 2001 From: dongjiang Date: Fri, 14 Feb 2025 17:17:57 +0800 Subject: [PATCH] change variable name by codereview Signed-off-by: dongjiang --- hack/util.sh | 4 ++-- pkg/version/base.go | 8 ++++---- pkg/version/version.go | 34 +++++++++++++++++----------------- pkg/version/version_test.go | 18 +++++++++--------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/hack/util.sh b/hack/util.sh index e56f1e65e609..a115dd35bccb 100755 --- a/hack/util.sh +++ b/hack/util.sh @@ -715,7 +715,7 @@ function util::version_ldflags() { # Git information GIT_VERSION=$(util::get_version) # Git revision - GIT_REVISION=$(util::get_revision) + GIT_ABBREVIATIVE_COMMIT=$(util::get_revision) GIT_COMMIT_HASH=$(git rev-parse HEAD) if git_status=$(git status --porcelain 2>/dev/null) && [[ -z ${git_status} ]]; then GIT_TREESTATE="clean" @@ -726,7 +726,7 @@ function util::version_ldflags() { LDFLAGS="-X github.com/karmada-io/karmada/pkg/version.gitVersion=${GIT_VERSION} \ -X github.com/karmada-io/karmada/pkg/version.gitCommit=${GIT_COMMIT_HASH} \ -X github.com/karmada-io/karmada/pkg/version.gitTreeState=${GIT_TREESTATE} \ - -X github.com/karmada-io/karmada/pkg/version.gitRevision=${GIT_REVISION} \ + -X github.com/karmada-io/karmada/pkg/version.gitAbbreviativeCommit=${GIT_ABBREVIATIVE_COMMIT} \ -X github.com/karmada-io/karmada/pkg/version.buildDate=${BUILDDATE}" echo $LDFLAGS } diff --git a/pkg/version/base.go b/pkg/version/base.go index a812bda33470..46d60c0a8cf2 100644 --- a/pkg/version/base.go +++ b/pkg/version/base.go @@ -23,10 +23,10 @@ package version // version for ad-hoc builds (e.g. `go build`) that cannot get the version // information from git. var ( - gitVersion = "v0.0.0-master" - gitCommit = "unknown" // sha1 from git, output of $(git rev-parse HEAD) - gitTreeState = "unknown" // state of git tree, either "clean" or "dirty" - gitRevision = "unknown" // short sha1 for git, output of $(git rev-parse --short HEAD) + gitVersion = "v0.0.0-master" + gitCommit = "unknown" // sha1 from git, output of $(git rev-parse HEAD) + gitTreeState = "unknown" // state of git tree, either "clean" or "dirty" + gitAbbreviativeCommit = "unknown" // short sha1 from git, output of $(git rev-parse --short HEAD) buildDate = "unknown" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ') ) diff --git a/pkg/version/version.go b/pkg/version/version.go index 75ceb52862ae..1b4544940520 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -25,14 +25,14 @@ import ( // Info contains versioning information. type Info struct { - GitVersion string `json:"gitVersion"` - GitCommit string `json:"gitCommit"` - GitRevision string `json:"gitRevision"` - GitTreeState string `json:"gitTreeState"` - BuildDate string `json:"buildDate"` - GoVersion string `json:"goVersion"` - Compiler string `json:"compiler"` - Platform string `json:"platform"` + GitVersion string `json:"gitVersion"` + GitCommit string `json:"gitCommit"` + GitAbbreviativeCommit string `json:"gitAbbreviativeCommit"` + GitTreeState string `json:"gitTreeState"` + BuildDate string `json:"buildDate"` + GoVersion string `json:"goVersion"` + Compiler string `json:"compiler"` + Platform string `json:"platform"` } // String returns a Go-syntax representation of the Info. @@ -44,14 +44,14 @@ func (info Info) String() string { // what code a binary was built from. func Get() Info { return Info{ - GitVersion: gitVersion, - GitRevision: gitRevision, - GitCommit: gitCommit, - GitTreeState: gitTreeState, - BuildDate: buildDate, - GoVersion: runtime.Version(), - Compiler: runtime.Compiler, - Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), + GitVersion: gitVersion, + GitAbbreviativeCommit: gitAbbreviativeCommit, + GitCommit: gitCommit, + GitTreeState: gitTreeState, + BuildDate: buildDate, + GoVersion: runtime.Version(), + Compiler: runtime.Compiler, + Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), } } @@ -68,7 +68,7 @@ func NewCollector(program string) prometheus.Collector { ), ConstLabels: prometheus.Labels{ "version": Get().GitVersion, - "revision": Get().GitRevision, + "revision": Get().GitAbbreviativeCommit, "goversion": runtime.Version(), "goos": runtime.GOOS, "goarch": runtime.GOARCH, diff --git a/pkg/version/version_test.go b/pkg/version/version_test.go index 32921221104e..4a98b00e7920 100644 --- a/pkg/version/version_test.go +++ b/pkg/version/version_test.go @@ -29,16 +29,16 @@ func TestInfo_String(t *testing.T) { { name: "test1", info: Info{ - GitVersion: "1.3.0", - GitCommit: "da070e68f3318410c8c70ed8186a2bc4736dacbd", - GitTreeState: "clean", - GitRevision: "851c78564", - BuildDate: "2022-08-31T13:09:22Z", - GoVersion: "go1.18.3", - Compiler: "gc", - Platform: "linux/amd64", + GitVersion: "1.3.0", + GitCommit: "da070e68f3318410c8c70ed8186a2bc4736dacbd", + GitTreeState: "clean", + GitAbbreviativeCommit: "851c78564", + BuildDate: "2022-08-31T13:09:22Z", + GoVersion: "go1.18.3", + Compiler: "gc", + Platform: "linux/amd64", }, - want: `version.Info{GitVersion:"1.3.0", GitCommit:"da070e68f3318410c8c70ed8186a2bc4736dacbd", GitRevision:"851c78564", GitTreeState:"clean", BuildDate:"2022-08-31T13:09:22Z", GoVersion:"go1.18.3", Compiler:"gc", Platform:"linux/amd64"}`, + want: `version.Info{GitVersion:"1.3.0", GitCommit:"da070e68f3318410c8c70ed8186a2bc4736dacbd", GitAbbreviativeCommit:"851c78564", GitTreeState:"clean", BuildDate:"2022-08-31T13:09:22Z", GoVersion:"go1.18.3", Compiler:"gc", Platform:"linux/amd64"}`, }, } for _, tt := range tests {