From 10b916eb28a8aed07df80d8c305a40b7f073d739 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Wed, 19 Sep 2018 17:03:04 +0100 Subject: [PATCH] Merge PR #2318: Simplify version handling, rely on git describe --- .circleci/config.yml | 1 + Makefile | 10 +++++----- PENDING.md | 1 + client/lcd/lcd_test.go | 9 ++++++--- version/command.go | 9 ++------- version/version.go | 8 +------- 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 269d4ca94..a62c61fd3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -154,6 +154,7 @@ jobs: command: | export PATH="$GOBIN:$PATH" make install + export VERSION="$(git describe --tags --long | sed 's/v\(.*\)/\1/')" for pkg in $(go list github.com/cosmos/cosmos-sdk/... | grep -v github.com/cosmos/cosmos-sdk/cmd/gaia/cli_test | grep -v '/simulation' | circleci tests split --split-by=timings); do id=$(basename "$pkg") GOCACHE=off go test -timeout 8m -race -coverprofile=/tmp/workspace/profiles/$id.out -covermode=atomic "$pkg" | tee "/tmp/logs/$id-$RANDOM.log" diff --git a/Makefile b/Makefile index a2c51b6df..60c213871 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation') PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation') -COMMIT_HASH := $(shell git rev-parse --short HEAD) +VERSION := $(shell git describe --tags --long | sed 's/v\(.*\)/\1/') BUILD_TAGS = netgo ledger -BUILD_FLAGS = -tags "${BUILD_TAGS}" -ldflags "-X github.com/cosmos/cosmos-sdk/version.GitCommit=${COMMIT_HASH}" +BUILD_FLAGS = -tags "${BUILD_TAGS}" -ldflags "-X github.com/cosmos/cosmos-sdk/version.Version=${VERSION}" GCC := $(shell command -v gcc 2> /dev/null) LEDGER_ENABLED ?= true UNAME_S := $(shell uname -s) @@ -142,10 +142,10 @@ test_examples: @go test -count 1 -p 1 `go list github.com/cosmos/cosmos-sdk/examples/democoin/cli_test` -tags=cli_test test_unit: - @go test $(PACKAGES_NOSIMULATION) + @VERSION=$(VERSION) go test $(PACKAGES_NOSIMULATION) test_race: - @go test -race $(PACKAGES_NOSIMULATION) + @VERSION=$(VERSION) go test -race $(PACKAGES_NOSIMULATION) test_sim_modules: @echo "Running individual module simulations..." @@ -175,7 +175,7 @@ test_sim_gaia_profile: @go test -benchmem -run=^$$ github.com/cosmos/cosmos-sdk/cmd/gaia/app -bench ^BenchmarkFullGaiaSimulation$$ -SimulationEnabled=true -SimulationNumBlocks=$(SIM_NUM_BLOCKS) -SimulationBlockSize=$(SIM_BLOCK_SIZE) -SimulationCommit=$(SIM_COMMIT) -timeout 24h -cpuprofile cpu.out -memprofile mem.out test_cover: - @bash tests/test_cover.sh + @export VERSION=$(VERSION); bash tests/test_cover.sh test_lint: gometalinter.v2 --config=tools/gometalinter.json ./... diff --git a/PENDING.md b/PENDING.md index cf1dcd899..cafe2025a 100644 --- a/PENDING.md +++ b/PENDING.md @@ -107,6 +107,7 @@ IMPROVEMENTS * [x/stake] Improve speed of GetValidator, which was shown to be a performance bottleneck. [#2046](https://github.com/tendermint/tendermint/pull/2200) * [genesis] \#2229 Ensure that there are no duplicate accounts or validators in the genesis state. * Add SDK validation to `config.toml` (namely disabling `create_empty_blocks`) \#1571 + * \#1941(https://github.com/cosmos/cosmos-sdk/issues/1941) Version is now inferred via `git describe --tags`. * SDK * [tools] Make get_vendor_deps deletes `.vendor-new` directories, in case scratch files are present. diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 7bd629cb1..263b112b2 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "net/http" + "os" "regexp" "testing" "time" @@ -25,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" tests "github.com/cosmos/cosmos-sdk/tests" sdk "github.com/cosmos/cosmos-sdk/types" + version "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" "github.com/cosmos/cosmos-sdk/x/gov" @@ -34,6 +36,7 @@ import ( func init() { cryptoKeys.BcryptSecurityParameter = 1 + version.Version = os.Getenv("VERSION") } func TestKeys(t *testing.T) { @@ -124,16 +127,16 @@ func TestVersion(t *testing.T) { res, body := Request(t, port, "GET", "/version", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - reg, err := regexp.Compile(`\d+\.\d+\.\d+(-dev)?`) + reg, err := regexp.Compile(`\d+\.\d+\.\d+.*`) require.Nil(t, err) match := reg.MatchString(body) - require.True(t, match, body) + require.True(t, match, body, fmt.Sprintf("%s", body)) // node info res, body = Request(t, port, "GET", "/node_version", nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - reg, err = regexp.Compile(`\d+\.\d+\.\d+(-dev)?`) + reg, err = regexp.Compile(`\d+\.\d+\.\d+.*`) require.Nil(t, err) match = reg.MatchString(body) require.True(t, match, body) diff --git a/version/command.go b/version/command.go index 2cff1bbe9..8f47dba8f 100644 --- a/version/command.go +++ b/version/command.go @@ -17,15 +17,10 @@ var ( // return version of CLI/node and commit hash func GetVersion() string { - v := Version - if GitCommit != "" { - v = v + "-" + GitCommit - } - return v + return Version } // CMD func printVersion(cmd *cobra.Command, args []string) { - v := GetVersion() - fmt.Println(v) + fmt.Println(GetVersion()) } diff --git a/version/version.go b/version/version.go index 8bfea9577..407797eeb 100644 --- a/version/version.go +++ b/version/version.go @@ -1,11 +1,5 @@ //nolint package version -const Maj = "0" -const Min = "24" -const Fix = "2" - -const Version = "0.24.2" - // GitCommit set by build flags -var GitCommit = "" +var Version = ""