Skip to content

Commit

Permalink
Merge pull request #24206 from chaodaiG/misspell-makerule
Browse files Browse the repository at this point in the history
Run verify spelling with make rules
  • Loading branch information
k8s-ci-robot authored Nov 2, 2021
2 parents 52bd593 + bda917b commit e3f25e5
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,9 @@ update-file-perms:
hack/make-rules/update/file-perms.sh
verify-file-perms:
hack/make-rules/verify/file-perms.sh
update-spelling:
hack/make-rules/update/misspell.sh
verify-spelling:
hack/make-rules/verify/misspell.sh
#################################################################################
.PHONY: unit test verify go-lint update-gofmt verify-gofmt
.PHONY: unit test verify go-lint update-gofmt verify-gofmt update-spelling verify-spelling
42 changes: 42 additions & 0 deletions hack/make-rules/update/misspell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Copyright 2021 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.

set -o nounset
set -o errexit
set -o pipefail

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd -P)"
cd $REPO_ROOT

echo "Ensuring go version."
source ./hack/build/setup-go.sh

# build misspell
echo "Install misspell."
cd "hack/tools"
go build -o "${REPO_ROOT}/_bin/misspell" github.com/client9/misspell/cmd/misspell
cd "${REPO_ROOT}"

find -L . -type f -not \( \
\( \
-path '*/vendor/*' \
-o -path '*/static/*' \
-o -path '*/third_party/*' \
-o -path '*/node_modules/*' \
-o -path '*/localdata/*' \
-o -path 'go.mod' \
-o -path './hack/tools/go.sum' \
\) -prune \
\) -exec "${REPO_ROOT}/_bin/misspell" '{}' +
5 changes: 5 additions & 0 deletions hack/make-rules/verify/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ if [[ "${VERIFY_FILE_PERMS:-true}" == "true" ]]; then
hack/make-rules/verify/file-perms.sh || res=1
cd "${REPO_ROOT}"
fi
if [[ "${VERIFY_SPELLING:-true}" == "true" ]]; then
echo "verifying spelling ..."
hack/make-rules/verify/misspell.sh || res=1
cd "${REPO_ROOT}"
fi

# exit based on verify scripts
if [[ "${res}" = 0 ]]; then
Expand Down
84 changes: 84 additions & 0 deletions hack/make-rules/verify/misspell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash
# Copyright 2021 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.

set -o nounset
set -o errexit
set -o pipefail

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd -P)"
cd $REPO_ROOT

BIN_DIR="${REPO_ROOT}/_bin/misspell"
mkdir -p "$BIN_DIR"
MISSPELL="${BIN_DIR}/misspell"

echo "Ensuring go version."
source ./hack/build/setup-go.sh

# build misspell
echo "Install misspell."
cd "hack/tools"
go build -o "$MISSPELL" github.com/client9/misspell/cmd/misspell
cd "${REPO_ROOT}"

trap 'echo ERROR: found unexpected instance of "Git"hub, use github or GitHub' ERR

echo "Check for word 'github'..."
# Unit test: Git"hub (remove ")
# Appear to need to use this if statement on mac to get the not grep to work
if find -L . -type f -not \( \
\( \
-path '*/vendor/*' \
-o -path '*/external/*' \
-o -path '*/static/*' \
-o -path '*/third_party/*' \
-o -path '*/node_modules/*' \
-o -path '*/localdata/*' \
-o -path '*/gubernator/*' \
-o -path '*/prow/bugzilla/client_test.go' \
-o -path './.git/*' \
-o -path './_bin/*' \
-o -path './_output/*' \
-o -path './_artifacts/*' \
-o -path './bazel-*/*' \
\) -prune \
\) -exec grep -Hn 'Git'hub '{}' '+' ; then
echo "Failed"
false
fi


trap 'echo ERROR: bad spelling, fix with hack/update-spelling.sh' ERR

echo "Check for spelling..."
# Unit test: lang auge (remove space)
find -L . -type f -not \( \
\( \
-path '*/vendor/*' \
-o -path '*/external/*' \
-o -path '*/static/*' \
-o -path '*/third_party/*' \
-o -path '*/node_modules/*' \
-o -path '*/localdata/*' \
-o -path './.git/*' \
-o -path './_bin/*' \
-o -path './_output/*' \
-o -path './_artifacts/*' \
-o -path './bazel-*/*' \
-o -path './hack/tools/go.sum' \
\) -prune \
\) -exec "$MISSPELL" '{}' '+'

echo 'PASS: No spelling issues detected'
3 changes: 2 additions & 1 deletion hack/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module k8s.io/test-infra/hack/tools
go 1.16

require (
github.com/bazelbuild/buildtools v0.0.0-20211007154642-8dd79e56e98e // indirect
github.com/bazelbuild/buildtools v0.0.0-20211007154642-8dd79e56e98e
github.com/client9/misspell v0.3.4
github.com/golangci/golangci-lint v1.42.1
gotest.tools/gotestsum v1.7.0
k8s.io/code-generator v0.22.2
Expand Down
1 change: 1 addition & 0 deletions hack/tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ github.com/chavacava/garif v0.0.0-20210405164556-e8a0a408d6af/go.mod h1:Qjyv4H3/
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
Expand Down
2 changes: 2 additions & 0 deletions hack/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ import (

// bazel-related tools
_ "github.com/bazelbuild/buildtools/buildozer"

_ "github.com/client9/misspell/cmd/misspell"
)

0 comments on commit e3f25e5

Please sign in to comment.