Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Use go.mod for verify-spelling
Browse files Browse the repository at this point in the history
Mirrors the approach used in kubernetes/kubernetes, avoids the
spurious failure.
  • Loading branch information
justinsb committed Mar 21, 2021
1 parent 8a86ef9 commit bc2382e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
2 changes: 2 additions & 0 deletions hack/tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This directory contains a stub go module used to track version of development
tools like the ones needed for linting or updating bazel BUILD files.
5 changes: 5 additions & 0 deletions hack/tools/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module sigs.k8s.io/etcdadm/hack/tools

go 1.16

require github.com/client9/misspell v0.3.4
2 changes: 2 additions & 0 deletions hack/tools/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
24 changes: 24 additions & 0 deletions hack/tools/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package tools is used to track binary dependencies with go modules
// https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module
package tools

import (
// linting tools
_ "github.com/client9/misspell/cmd/misspell"
)
21 changes: 7 additions & 14 deletions hack/verify-spelling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,23 @@ exitHandler() (
)
trap exitHandler EXIT

# pull misspell
export GO111MODULE=on
URL="https://github.com/client9/misspell"
echo "Cloning ${URL} in ${TMP_DIR}..."
git clone --quiet --depth=1 "${URL}" "${TMP_DIR}"
pushd "${TMP_DIR}" > /dev/null
go mod init misspell
popd > /dev/null

# build misspell
BIN_PATH="${TMP_DIR}/cmd/misspell"
pushd "${BIN_PATH}" > /dev/null
echo "Building misspell..."
go build > /dev/null
popd > /dev/null
pushd "hack/tools" >/dev/null
MISSPELL_CMD="${TMP_DIR}/misspell"
GO111MODULE=on go build -o ${MISSPELL_CMD} github.com/client9/misspell/cmd/misspell
popd

# check spelling
RES=0
ERROR_LOG="${TMP_DIR}/errors.log"
echo "Checking spelling..."
git ls-files | grep -v -e vendor | xargs "${BIN_PATH}/misspell" > "${ERROR_LOG}"
git ls-files | grep -v -e vendor | xargs "${MISSPELL_CMD}" > "${ERROR_LOG}"
if [[ -s "${ERROR_LOG}" ]]; then
sed 's/^/error: /' "${ERROR_LOG}" # add 'error' to each line to highlight in e2e status
echo "Found spelling errors!"
RES=1
else
echo "No spelling errors found"
fi
exit "${RES}"

0 comments on commit bc2382e

Please sign in to comment.