Skip to content

Commit 27cc32b

Browse files
committed
Add verify-gofmt as a Bazel test.
Also, moved --flaky_test_attempts=3 out of .bazelrc since it was annoying.
1 parent a6952bc commit 27cc32b

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

.bazelrc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@
22
build --verbose_failures
33
test --test_output=errors
44

5-
# Retry tests up to 3 times if they fail.
6-
test --flaky_test_attempts=3
7-
85
# Include git version info
96
build --workspace_status_command hack/print-workspace-status.sh

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ endef
500500
@echo "$$BAZEL_TEST_HELP_INFO"
501501
else
502502
bazel-test:
503-
bazel test //cmd/... //pkg/... //federation/... //plugin/... //third_party/... //hack/... //hack:verify-all
503+
bazel test --flaky_test_attempts=3 //cmd/... //pkg/... //federation/... //plugin/... //third_party/... //hack/... //hack:verify-all
504504
endif
505505

506506
ifeq ($(PRINT_HELP),y)

hack/BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,21 @@ sh_test(
2727
tags = ["manual"],
2828
)
2929

30+
sh_test(
31+
name = "verify-gofmt",
32+
srcs = ["verify-gofmt.sh"],
33+
data = [
34+
"//:all-srcs",
35+
"@io_bazel_rules_go_toolchain//:toolchain",
36+
],
37+
tags = ["manual"],
38+
)
39+
3040
test_suite(
3141
name = "verify-all",
3242
tags = ["manual"],
3343
tests = [
3444
"verify-boilerplate",
45+
"verify-gofmt",
3546
],
3647
)

hack/verify-gofmt.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ set -o pipefail
2323
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
2424
source "${KUBE_ROOT}/hack/lib/init.sh"
2525

26-
kube::golang::verify_go_version
27-
2826
cd "${KUBE_ROOT}"
2927

28+
# Prefer bazel's gofmt.
29+
gofmt="external/io_bazel_rules_go_toolchain/bin/gofmt"
30+
if [[ ! -x "${gofmt}" ]]; then
31+
gofmt=$(which gofmt)
32+
kube::golang::verify_go_version
33+
fi
34+
3035
find_files() {
3136
find . -not \( \
3237
\( \
@@ -38,14 +43,13 @@ find_files() {
3843
-o -wholename '*/third_party/*' \
3944
-o -wholename '*/vendor/*' \
4045
-o -wholename './staging' \
46+
-o -wholename '*/bindata.go' \
4147
\) -prune \
4248
\) -name '*.go'
4349
}
4450

45-
GOFMT="gofmt -s -w"
46-
bad_files=$(find_files | xargs $GOFMT -l)
47-
if [[ -n "${bad_files}" ]]; then
48-
echo "!!! '$GOFMT' needs to be run on the following files: "
49-
echo "${bad_files}"
51+
diff=$(find_files | xargs ${gofmt} -d -s 2>&1)
52+
if [[ -n "${diff}" ]]; then
53+
echo "${diff}"
5054
exit 1
5155
fi

0 commit comments

Comments
 (0)