From 2a040342bab0a76ca7baeaf0412708a39b4bafa3 Mon Sep 17 00:00:00 2001 From: Alvin Huang <17609145+alvin-huang@users.noreply.github.com> Date: Tue, 14 Jul 2020 15:17:45 -0400 Subject: [PATCH] remove GIT_DESCRIBE variable since we have a revision line (#8310) --- .circleci/bash_env.sh | 3 +-- GNUmakefile | 5 +---- build-support/functions/10-util.sh | 19 +++++-------------- build-support/functions/20-build.sh | 12 ++++++------ version/version.go | 13 +------------ 5 files changed, 14 insertions(+), 38 deletions(-) diff --git a/.circleci/bash_env.sh b/.circleci/bash_env.sh index 57e9dc108a..9ebd055d8b 100644 --- a/.circleci/bash_env.sh +++ b/.circleci/bash_env.sh @@ -3,6 +3,5 @@ export GIT_COMMIT=$(git rev-parse --short HEAD) export GIT_COMMIT_YEAR=$(git show -s --format=%cd --date=format:%Y HEAD) export GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true) -export GIT_DESCRIBE=$(git describe --tags --always --match "v*") export GIT_IMPORT=github.com/hashicorp/consul/version -export GOLDFLAGS="-X ${GIT_IMPORT}.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X ${GIT_IMPORT}.GitDescribe=${GIT_DESCRIBE}" \ No newline at end of file +export GOLDFLAGS="-X ${GIT_IMPORT}.GitCommit=${GIT_COMMIT}${GIT_DIRTY} \ No newline at end of file diff --git a/GNUmakefile b/GNUmakefile index fc7c3b3070..b328df91de 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -21,9 +21,8 @@ ASSETFS_PATH?=agent/bindata_assetfs.go GIT_COMMIT?=$(shell git rev-parse --short HEAD) GIT_COMMIT_YEAR?=$(shell git show -s --format=%cd --date=format:%Y HEAD) GIT_DIRTY?=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true) -GIT_DESCRIBE?=$(shell git describe --tags --always --match "v*") GIT_IMPORT=github.com/hashicorp/consul/version -GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) -X $(GIT_IMPORT).GitDescribe=$(GIT_DESCRIBE) +GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) PROTOFILES?=$(shell find . -name '*.proto' | grep -v 'vendor/') PROTOGOFILES=$(PROTOFILES:.proto=.pb.go) @@ -124,7 +123,6 @@ export BUILD_CONTAINER_NAME export GIT_COMMIT export GIT_COMMIT_YEAR export GIT_DIRTY -export GIT_DESCRIBE export GOTAGS export GOLDFLAGS @@ -282,7 +280,6 @@ test-docker: linux go-build-image -e 'GIT_COMMIT=$(GIT_COMMIT)' \ -e 'GIT_COMMIT_YEAR=$(GIT_COMMIT_YEAR)' \ -e 'GIT_DIRTY=$(GIT_DIRTY)' \ - -e 'GIT_DESCRIBE=$(GIT_DESCRIBE)' \ $(TEST_PARALLELIZATION) \ $(TEST_DOCKER_RESOURCE_CONSTRAINTS) \ $(TEST_MODCACHE_VOL) \ diff --git a/build-support/functions/10-util.sh b/build-support/functions/10-util.sh index d55a3e26ec..59e714d536 100644 --- a/build-support/functions/10-util.sh +++ b/build-support/functions/10-util.sh @@ -110,7 +110,7 @@ function parse_version { # Arguments: # $1 - Path to the top level Consul source # $2 - boolean value for whether the release version should be parsed from the source - # $3 - boolean whether to use GIT_DESCRIBE and GIT_COMMIT environment variables + # $3 - boolean whether to use GIT_COMMIT environment variable # $4 - boolean whether to omit the version part of the version string. (optional) # # Return: @@ -134,7 +134,6 @@ function parse_version { local use_git_env="$3" local omit_version="$4" - local git_version="" local git_commit="" if test -z "${include_release}" @@ -149,7 +148,6 @@ function parse_version { if is_set "${use_git_env}" then - git_version="${GIT_DESCRIBE}" git_commit="${GIT_COMMIT}" fi @@ -172,11 +170,6 @@ function parse_version { done local version="${version_main}" - # override the version from source with the value of the GIT_DESCRIBE env var if present - if test -n "${git_version}" - then - version="${git_version}" - fi local rel_ver="" if is_set "${include_release}" @@ -184,9 +177,8 @@ function parse_version { # Default to pre-release from the source rel_ver="${release_main}" - # When no GIT_DESCRIBE env var is present and no release is in the source then we - # are definitely in dev mode - if test -z "${git_version}" -a -z "${rel_ver}" && is_set "${use_git_env}" + # When no release is in the source then we are definitely in dev mode + if test -z "${rel_ver}" && is_set "${use_git_env}" then rel_ver="dev" fi @@ -220,7 +212,7 @@ function get_version { # Arguments: # $1 - Path to the top level Consul source # $2 - Whether the release version should be parsed from source (optional) - # $3 - Whether to use GIT_DESCRIBE and GIT_COMMIT environment variables + # $3 - Whether to use GIT_COMMIT environment variable # # Returns: # 0 - success (the version is also echoed to stdout) @@ -519,9 +511,8 @@ function update_git_env { export GIT_COMMIT=$(git rev-parse --short HEAD) export GIT_DIRTY=$(test -n "$(git status --porcelain)" && echo "+CHANGES") - export GIT_DESCRIBE=$(git describe --tags --always --match "v*") export GIT_IMPORT=github.com/hashicorp/consul/version - export GOLDFLAGS="-X ${GIT_IMPORT}.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X ${GIT_IMPORT}.GitDescribe=${GIT_DESCRIBE}" + export GOLDFLAGS="-X ${GIT_IMPORT}.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" return 0 } diff --git a/build-support/functions/20-build.sh b/build-support/functions/20-build.sh index 6648dfd898..eb9bf4e641 100644 --- a/build-support/functions/20-build.sh +++ b/build-support/functions/20-build.sh @@ -64,13 +64,13 @@ function build_ui { then commit_hash=$(git rev-parse --short HEAD) fi - + local commit_year="${GIT_COMMIT_YEAR}" if test -z "${commit_year}" then commit_year=$(git show -s --format=%cd --date=format:%Y HEAD) fi - + local logo_type="${CONSUL_BINARY_TYPE}" if test "$logo_type" != "oss" then @@ -140,7 +140,7 @@ function build_assetfs { # * - error # # Note: - # The GIT_COMMIT, GIT_DIRTY and GIT_DESCRIBE environment variables will be used if present + # The GIT_COMMIT and GIT_DIRTY environment variables will be used if present if ! test -d "$1" then @@ -157,7 +157,7 @@ function build_assetfs { pushd ${sdir} > /dev/null status "Creating the Go Build Container with image: ${image_name}" - local container_id=$(docker create -it -e GIT_COMMIT=${GIT_COMMIT} -e GIT_DIRTY=${GIT_DIRTY} -e GIT_DESCRIBE=${GIT_DESCRIBE} ${image_name} make static-assets ASSETFS_PATH=bindata_assetfs.go) + local container_id=$(docker create -it -e GIT_COMMIT=${GIT_COMMIT} -e GIT_DIRTY=${GIT_DIRTY} ${image_name} make static-assets ASSETFS_PATH=bindata_assetfs.go) local ret=$? if test $ret -eq 0 then @@ -436,7 +436,7 @@ function build_consul_local { if test "${arch}" != "amd64" then continue - fi + fi ;; "linux" ) # build all the binaries for Linux @@ -444,7 +444,7 @@ function build_consul_local { *) continue ;; - esac + esac echo "---> ${osarch}" diff --git a/version/version.go b/version/version.go index e3b92b831c..dd97273ac2 100644 --- a/version/version.go +++ b/version/version.go @@ -8,8 +8,7 @@ import ( var ( // The git commit that was compiled. These will be filled in by the // compiler. - GitCommit string - GitDescribe string + GitCommit string // The main version number that is being run at the moment. // @@ -27,23 +26,13 @@ var ( // for displaying to humans. func GetHumanVersion() string { version := Version - if GitDescribe != "" { - version = GitDescribe - } - release := VersionPrerelease - if GitDescribe == "" && release == "" { - release = "dev" - } if release != "" { if !strings.HasSuffix(version, "-"+release) { // if we tagged a prerelease version then the release is in the version already version += fmt.Sprintf("-%s", release) } - if GitCommit != "" { - version += fmt.Sprintf(" (%s)", GitCommit) - } } // Strip off any single quotes added by the git information.