From 7605b69cf2b9173bda93ff4b8618e9bc276bd19b Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Sun, 28 Jul 2024 14:00:18 -0700 Subject: [PATCH] make golangci-lint run locally with correct version Signed-off-by: Michael Grosser --- .gitignore | 3 +++ hack/verify-staticcheck.sh | 21 ++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 69e535bdc180..4022d9327b1f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,8 +10,11 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out + +# Folders used by make _tmp/ _output/ +bin/ # Dependency directories (remove the comment below to include it) # vendor/ diff --git a/hack/verify-staticcheck.sh b/hack/verify-staticcheck.sh index 43793fad17d7..2c5947d8523e 100755 --- a/hack/verify-staticcheck.sh +++ b/hack/verify-staticcheck.sh @@ -13,32 +13,31 @@ # See the License for the specific language governing permissions and # limitations under the License. +# - download golangci-lint if needed (replace existing if incorrect version) +# - run golangci-lint set -o errexit set -o nounset set -o pipefail REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -GOLANGCI_LINT_VER="v1.59.0" +GOLANGCI_LINT_VER="1.59.0" +GOLANGCI_LINT="./bin/golangci-lint" cd "${REPO_ROOT}" -source "hack/util.sh" +mkdir -p bin -if util::cmd_exist golangci-lint ; then - echo "Using golangci-lint version:" - golangci-lint version -else - echo "Installing golangci-lint ${GOLANGCI_LINT_VER}" - # https://golangci-lint.run/usage/install/#other-ci - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VER} +if ! (test -f "${GOLANGCI_LINT}" && ${GOLANGCI_LINT} --version | grep " ${GOLANGCI_LINT_VER} " >/dev/null); then + rm -f ${GOLANGCI_LINT} && echo "Installing ${GOLANGCI_LINT} ${GOLANGCI_LINT_VER}" + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b bin -d "v${GOLANGCI_LINT_VER}" fi -if golangci-lint run; then +if ${GOLANGCI_LINT} run; then echo 'Congratulations! All Go source files have passed staticcheck.' else echo # print one empty line, separate from warning messages. echo 'Please review the above warnings.' - echo 'Tips: The golangci-lint might help you fix some issues, try with the command "golangci-lint run --fix".' + echo "Tips: The ${GOLANGCI_LINT} might help you fix some issues, try with the command "${GOLANGCI_LINT} run --fix"." echo 'If the above warnings do not make sense, feel free to file an issue.' exit 1 fi