From 06725e7fbb5bc094181be282228e09423162662d Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Fri, 28 Sep 2018 16:15:41 -0700 Subject: [PATCH] Add scripts for running go vet and go fmt --- hack/update-gofmt | 19 +++++++++++++++++++ hack/verify-all | 22 ++++++++++++++++++++++ hack/verify-gofmt | 28 ++++++++++++++++++++++++++++ hack/verify-govet | 23 +++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100755 hack/update-gofmt create mode 100755 hack/verify-all create mode 100755 hack/verify-gofmt create mode 100755 hack/verify-govet diff --git a/hack/update-gofmt b/hack/update-gofmt new file mode 100755 index 0000000000..0f2f694f18 --- /dev/null +++ b/hack/update-gofmt @@ -0,0 +1,19 @@ +#!/bin/bash + +# Copyright 2018 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 -euo pipefail + +find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -w diff --git a/hack/verify-all b/hack/verify-all new file mode 100755 index 0000000000..b727caab2f --- /dev/null +++ b/hack/verify-all @@ -0,0 +1,22 @@ +#!/bin/bash + +# Copyright 2018 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 -euo pipefail + +PKG_ROOT=$(git rev-parse --show-toplevel) + +${PKG_ROOT}/hack/verify-gofmt +${PKG_ROOT}/hack/verify-govet diff --git a/hack/verify-gofmt b/hack/verify-gofmt new file mode 100755 index 0000000000..bfb77d254b --- /dev/null +++ b/hack/verify-gofmt @@ -0,0 +1,28 @@ +#!/bin/bash + +# Copyright 2018 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 -euo pipefail + +echo "Verifying gofmt" + +diff=$(find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -d 2>&1) +if [[ -n "${diff}" ]]; then + echo "${diff}" + echo + echo "Please run hack/update-gofmt to fix the issue(s)" + exit 1 +fi +echo "No issue found" diff --git a/hack/verify-govet b/hack/verify-govet new file mode 100755 index 0000000000..03d9599698 --- /dev/null +++ b/hack/verify-govet @@ -0,0 +1,23 @@ +#!/bin/bash + +# Copyright 2018 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 -euo pipefail + +echo "Verifying govet" + +go vet $(go list ./... | grep -v vendor) + +echo "Done"