diff --git a/BUILD.bazel b/BUILD.bazel index a708dee4b3..e1c402a000 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -21,3 +21,10 @@ go_library( ], importpath = "k8s.io/kops", ) + +load("@io_k8s_repo_infra//defs:run_in_workspace.bzl", "workspace_binary") + +workspace_binary( + name = "gofmt", + cmd = "@go_sdk//:bin/gofmt", +) diff --git a/Makefile b/Makefile index e01c69975c..fdf4dab0eb 100644 --- a/Makefile +++ b/Makefile @@ -500,20 +500,7 @@ dep-ensure: dep-prereqs .PHONY: gofmt gofmt: - gofmt -w -s channels/ - gofmt -w -s cloudmock/ - gofmt -w -s cmd/ - gofmt -w -s examples/ - gofmt -w -s nodeup/ - gofmt -w -s util/ - gofmt -w -s upup/pkg/ - gofmt -w -s pkg/ - gofmt -w -s tests/ - gofmt -w -s protokube/cmd - gofmt -w -s protokube/pkg - gofmt -w -s protokube/tests - gofmt -w -s dns-controller/cmd - gofmt -w -s dns-controller/pkg + find -name "*.go" | grep -v vendor | xargs bazel run //:gofmt -- -w -s .PHONY: goimports goimports: diff --git a/WORKSPACE b/WORKSPACE index 56e19a9e57..284cbf72e9 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -113,3 +113,10 @@ http_file( urls = ["https://kubeupv2.s3.amazonaws.com/kops/1.11.1/linux/amd64/utils.tar.gz"], sha256 = "0e685eb751a32f782705311049b2592c4724add6f19ffdad1e7ce4f55816d7d8", ) + +git_repository( + name = "io_k8s_repo_infra", + commit = "4ce715fbe67d8fbed05ec2bb47a148e754100a4b", + remote = "https://github.com/kubernetes/repo-infra.git", + shallow_since = "1517262872 -0800", +) diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh index 7fed894e4e..00bd9a0894 100755 --- a/hack/verify-gofmt.sh +++ b/hack/verify-gofmt.sh @@ -16,9 +16,9 @@ . $(dirname "${BASH_SOURCE}")/common.sh -GOFMT="gofmt -s -w" +GOFMT="bazel run //:gofmt -- -s -w" -bad_files=$(git ls-files "*.go" | grep -v vendor | xargs -I {} $GOFMT -l {}) +bad_files=$(git ls-files "*.go" | grep -v vendor | xargs $GOFMT -l) if [[ -n "${bad_files}" ]]; then echo "FAIL: '$GOFMT' needs to be run on the following files: " echo "${bad_files}"