From 7e03a4aed73b3e39cc44b930aadd4a0efd1b05eb Mon Sep 17 00:00:00 2001 From: Joel Thompson Date: Thu, 19 Oct 2017 16:30:19 -0400 Subject: [PATCH] Explicitly check go version in build (#3309) * Explicitly check go version in build Several GH issues have been opened by people trying to use an older version of Go to build Vault (e.g., #3307 is the most recent). This adds an explicit check to the build to hopefully make it more clear to users in the future. * Also add checking for go patch version * Up minimum go version And fix a comment * Bump travis to go1.9.1 --- .travis.yml | 2 +- Makefile | 3 +++ scripts/goversioncheck.sh | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 scripts/goversioncheck.sh diff --git a/.travis.yml b/.travis.yml index aa214be8bc..fb29df5f6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ services: - docker go: - - 1.9 + - 1.9.1 matrix: allow_failures: diff --git a/Makefile b/Makefile index 68c9543eec..8aa19d1712 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,8 @@ EXTERNAL_TOOLS=\ BUILD_TAGS?=vault GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor) +GO_VERSION_MIN=1.9.1 + default: dev # bin generates the releaseable binaries for Vault @@ -61,6 +63,7 @@ vet: # prep runs `go generate` to build the dynamically generated # source files. prep: + @sh -c "'$(CURDIR)/scripts/goversioncheck.sh' '$(GO_VERSION_MIN)'" go generate $(go list ./... | grep -v /vendor/) cp .hooks/* .git/hooks/ diff --git a/scripts/goversioncheck.sh b/scripts/goversioncheck.sh new file mode 100755 index 0000000000..083998e1d5 --- /dev/null +++ b/scripts/goversioncheck.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +GO_VERSION_MIN=$1 +echo "==> Checking that build is using go version >= $1..." + +GO_VERSION=$(go version | grep -o 'go[0-9]\+\.[0-9]\+\(\.[0-9]\+\)\?' | tr -d 'go') + + +IFS="." read -r -a GO_VERSION_ARR <<< "$GO_VERSION" +IFS="." read -r -a GO_VERSION_REQ <<< "$GO_VERSION_MIN" + +if [[ ${GO_VERSION_ARR[0]} -lt ${GO_VERSION_REQ[0]} || + ( ${GO_VERSION_ARR[0]} -eq ${GO_VERSION_REQ[0]} && + ( ${GO_VERSION_ARR[1]} -lt ${GO_VERSION_REQ[1]} || + ( ${GO_VERSION_ARR[1]} -eq ${GO_VERSION_REQ[1]} && ${GO_VERSION_ARR[2]} -lt ${GO_VERSION_REQ[2]} ))) + ]]; then + echo "Vault requires go $GO_VERSION_MIN to build; found $GO_VERSION." + exit 1 +fi