From 7835dbb547c37e6ee9ff366aecbd1f8fc6dfbb07 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Mon, 7 Jan 2019 06:18:08 +0000 Subject: [PATCH] enable gofmt golint govet and CI on windows --- .travis.yml | 2 ++ Makefile | 3 +++ hack/update-gofmt.sh | 19 +++++++++++++++++++ hack/verify-all.sh | 23 +++++++++++++++++++++++ hack/verify-gofmt.sh | 28 ++++++++++++++++++++++++++++ hack/verify-golint.sh | 27 +++++++++++++++++++++++++++ hack/verify-govet.sh | 23 +++++++++++++++++++++++ 7 files changed, 125 insertions(+) create mode 100755 hack/update-gofmt.sh create mode 100755 hack/verify-all.sh create mode 100755 hack/verify-gofmt.sh create mode 100755 hack/verify-golint.sh create mode 100755 hack/verify-govet.sh diff --git a/.travis.yml b/.travis.yml index a0204a60a..506de5da8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,8 @@ go: - "1.11.4" script: + - hack/verify-all.sh - make test - make azurefile + - make azurefile-windows - make azurefile-container diff --git a/Makefile b/Makefile index 7efed308d..b1908ceb9 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,9 @@ test: azurefile: if [ ! -d ./vendor ]; then dep ensure -vendor-only; fi CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-X github.com/andyzhangx/azurefile-csi-driver/pkg/azurefile.vendorVersion=$(IMAGE_VERSION) -extldflags "-static"' -o _output/azurefileplugin ./pkg/azurefileplugin +azurefile-windows: + if [ ! -d ./vendor ]; then dep ensure -vendor-only; fi + CGO_ENABLED=0 GOOS=windows go build -a -ldflags '-X github.com/andyzhangx/azurefile-csi-driver/pkg/azurefile.vendorVersion=$(IMAGE_VERSION) -extldflags "-static"' -o _output/azurefileplugin.exe ./pkg/azurefileplugin azurefile-container: azurefile docker build --no-cache -t $(IMAGE_TAG) -f ./pkg/azurefileplugin/Dockerfile . push: azurefile-container diff --git a/hack/update-gofmt.sh b/hack/update-gofmt.sh new file mode 100755 index 000000000..0f2f694f1 --- /dev/null +++ b/hack/update-gofmt.sh @@ -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.sh b/hack/verify-all.sh new file mode 100755 index 000000000..8c1312201 --- /dev/null +++ b/hack/verify-all.sh @@ -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 + +PKG_ROOT=$(git rev-parse --show-toplevel) + +${PKG_ROOT}/hack/verify-gofmt.sh +${PKG_ROOT}/hack/verify-govet.sh +${PKG_ROOT}/hack/verify-golint.sh diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh new file mode 100755 index 000000000..bfb77d254 --- /dev/null +++ b/hack/verify-gofmt.sh @@ -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-golint.sh b/hack/verify-golint.sh new file mode 100755 index 000000000..89942cb6b --- /dev/null +++ b/hack/verify-golint.sh @@ -0,0 +1,27 @@ +#!/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 + +if ! which golangci-lint > /dev/null; then + echo "Cannot find golangci-lint. Installing golangci-lint..." + go get -v github.com/golangci/golangci-lint/cmd/golangci-lint +fi + +golangci-lint run --deadline=10m + +echo "Congratulations! All Go source files have been linted." + diff --git a/hack/verify-govet.sh b/hack/verify-govet.sh new file mode 100755 index 000000000..03d959969 --- /dev/null +++ b/hack/verify-govet.sh @@ -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"