Skip to content

Commit

Permalink
Use "go install" to install the tools required by "make verify" (#2698)
Browse files Browse the repository at this point in the history
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 <abas@vmware.com>
  • Loading branch information
antoninbas authored Sep 2, 2021
1 parent ff1bf06 commit 33e78be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 15 additions & 5 deletions hack/verify-spelling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions hack/verify-toc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Expand All @@ -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
Expand Down

0 comments on commit 33e78be

Please sign in to comment.