From 33e78be6c20aa23c55bc761117a2d88d43dfb6da Mon Sep 17 00:00:00 2001 From: Antonin Bas Date: Thu, 2 Sep 2021 09:27:28 -0700 Subject: [PATCH] Use "go install" to install the tools required by "make verify" (#2698) To avoid the following warning when using Go 1.17 (default version for Antrea): go get: installing executables with 'go get' in module mode is deprecated. See https://golang.org/doc/go-get-install-deprecation Signed-off-by: Antonin Bas --- Makefile | 4 ++-- hack/verify-spelling.sh | 20 +++++++++++++++----- hack/verify-toc.sh | 19 ++++++++++++------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 23244a32ddd..37e88740a78 100644 --- a/Makefile +++ b/Makefile @@ -382,9 +382,9 @@ endif .PHONY: verify verify: @echo "===> Verifying spellings <===" - $(CURDIR)/hack/verify-spelling.sh + GO=$(GO) $(CURDIR)/hack/verify-spelling.sh @echo "===> Verifying Table of Contents <===" - $(CURDIR)/hack/verify-toc.sh + GO=$(GO) $(CURDIR)/hack/verify-toc.sh @echo "===> Verifying documentation formatting for website <===" $(CURDIR)/hack/verify-docs-for-website.sh diff --git a/hack/verify-spelling.sh b/hack/verify-spelling.sh index 23097a38a96..f20c6c1e83c 100755 --- a/hack/verify-spelling.sh +++ b/hack/verify-spelling.sh @@ -14,30 +14,40 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This script checks commonly misspelled English words. This script is a -# slight modification of the kubernetes/hack/verify-spelling.sh. +# This script checks commonly misspelled English words. This script is inspired +# by kubernetes/hack/verify-spelling.sh. set -o errexit set -o nounset set -o pipefail +# if Go environment variable is set, use it as it is, otherwise default to "go" +: "${GO:=go}" TOOL_VERSION="v0.3.4" +GO_VERSION="$(${GO} version | awk '{print $3}')" +function version_lt() { test "$(printf '%s\n' "$@" | sort -rV | head -n 1)" != "$1"; } + +if version_lt "${GO_VERSION}" "go1.16"; then + # See https://golang.org/doc/go-get-install-deprecation + echo "Running this script requires Go >= 1.16, please upgrade" + exit 1 +fi + ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" cd "${ROOT}" TMP_DIR=$(mktemp -d) +# cleanup exitHandler() ( echo "Cleaning up temporary directory" rm -rf "${TMP_DIR}" ) trap exitHandler EXIT -cd "${TMP_DIR}" -GO111MODULE=on GOBIN="${TMP_DIR}" go get "github.com/client9/misspell/cmd/misspell@${TOOL_VERSION}" +GOBIN="${TMP_DIR}" ${GO} install "github.com/client9/misspell/cmd/misspell@${TOOL_VERSION}" export PATH="${TMP_DIR}:${PATH}" -cd "${ROOT}" # Check spelling and ignore skipped files. RES=0 diff --git a/hack/verify-toc.sh b/hack/verify-toc.sh index d8c75a9c93f..56283a82bdc 100755 --- a/hack/verify-toc.sh +++ b/hack/verify-toc.sh @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This script is a copy of script maintained in +# This script is inspired by the one maintained in # https://github.com/kubernetes/enhancements set -o errexit @@ -23,6 +23,15 @@ set -o pipefail TOOL_VERSION=$(head hack/mdtoc-version) +GO_VERSION="$(${GO} version | awk '{print $3}')" +function version_lt() { test "$(printf '%s\n' "$@" | sort -rV | head -n 1)" != "$1"; } + +if version_lt "${GO_VERSION}" "go1.16"; then + # See https://golang.org/doc/go-get-install-deprecation + echo "Running this script requires Go >= 1.16, please upgrade" + exit 1 +fi + # cd to the root path ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" cd "${ROOT}" @@ -32,17 +41,13 @@ TMP_DIR=$(mktemp -d) # cleanup exitHandler() ( - echo "Cleaning up..." + echo "Cleaning up temporary directory" rm -rf "${TMP_DIR}" ) trap exitHandler EXIT -# perform go get in a temp dir as we are not tracking this version in a go module -# if we do the go get in the repo, it will create / update a go.mod and go.sum -cd "${TMP_DIR}" -GO111MODULE=on GOBIN="${TMP_DIR}" go get "github.com/tallclair/mdtoc@${TOOL_VERSION}" +GOBIN="${TMP_DIR}" ${GO} install "github.com/tallclair/mdtoc@${TOOL_VERSION}" export PATH="${TMP_DIR}:${PATH}" -cd "${ROOT}" echo "Checking table of contents are up to date..." # Verify tables of contents are up-to-date