From 1b07b0d6488b7a049994ee1a39b8855d06d60799 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 22 Jan 2021 16:14:37 -0800 Subject: [PATCH] Fix bug in golint script when no files The script would get a 1 return code from grep when there are no files in a directory, after filtering generated filenames. This would cause the script to exit unexpectedly. --- hack/verify-golint.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hack/verify-golint.sh b/hack/verify-golint.sh index c6f7022bd96..bbed8ceeb89 100755 --- a/hack/verify-golint.sh +++ b/hack/verify-golint.sh @@ -69,7 +69,13 @@ for p in "${all_packages[@]}"; do # completely. # Ref: https://github.com/kubernetes/kubernetes/pull/67675 # Ref: https://github.com/golang/lint/issues/68 - failedLint=$(find "$p"/*.go | grep -vE "(zz_generated.*.go|generated.pb.go|generated.proto|types_swagger_doc_generated.go)" | xargs -L1 golint 2>/dev/null) + + files=$(find "$p"/*.go \ + | grep -vE "(zz_generated.*.go|generated.pb.go|generated.proto|types_swagger_doc_generated.go)" || true) + if [ -z "${files}" ]; then + continue + fi + failedLint=$(echo "${files}" | xargs -L1 golint 2>/dev/null) kube::util::array_contains "$p" "${failing_packages[@]}" && in_failing=$? || in_failing=$? if [[ -n "${failedLint}" ]] && [[ "${in_failing}" -ne "0" ]]; then errors+=( "${failedLint}" )