From 3f87ca25507059444b2d350560d6800e38468e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Taylor?= Date: Thu, 22 Aug 2024 15:16:43 +0200 Subject: [PATCH] Update golangci-lint to newer faster version (#16636) Signed-off-by: Andres Taylor --- .github/workflows/static_checks_etc.yml | 2 +- misc/git/hooks/golangci-lint | 36 +++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/.github/workflows/static_checks_etc.yml b/.github/workflows/static_checks_etc.yml index 5f04992ea09..2bc19808642 100644 --- a/.github/workflows/static_checks_etc.yml +++ b/.github/workflows/static_checks_etc.yml @@ -193,7 +193,7 @@ jobs: - name: Install golangci-lint if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true' - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1 + run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.2 - name: Clean Env if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true' diff --git a/misc/git/hooks/golangci-lint b/misc/git/hooks/golangci-lint index 8a596dac507..21313316a12 100755 --- a/misc/git/hooks/golangci-lint +++ b/misc/git/hooks/golangci-lint @@ -14,7 +14,33 @@ # limitations under the License. # Required version of golangci-lint -REQUIRED_VERSION="v1.60.1" +REQUIRED_VERSION="v1.60.2" + +# Function to compare versions in pure Bash +version_greater_or_equal() { + local IFS=. + local i + local ver1=($1) + local ver2=($2) + + # Fill empty fields in ver1 with zeros + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do + ver1[i]=0 + done + # Fill empty fields in ver2 with zeros + for ((i=${#ver2[@]}; i<${#ver1[@]}; i++)); do + ver2[i]=0 + done + + for ((i=0; i<${#ver1[@]}; i++)); do + if ((10#${ver1[i]} > 10#${ver2[i]})); then + return 0 + elif ((10#${ver1[i]} < 10#${ver2[i]})); then + return 1 + fi + done + return 0 +} # Check if golangci-lint is installed and capture the version if ! command -v golangci-lint >/dev/null 2>&1; then @@ -22,10 +48,10 @@ if ! command -v golangci-lint >/dev/null 2>&1; then go install github.com/golangci/golangci-lint/cmd/golangci-lint@$REQUIRED_VERSION else VERSION_OUTPUT=$(golangci-lint --version) - INSTALLED_VERSION=$(echo "$VERSION_OUTPUT" | sed -n 's/^golangci-lint has version \([v0-9.]*\).*/\1/p') - if [ "$INSTALLED_VERSION" != "$REQUIRED_VERSION" ]; then - echo "golangci-lint version $INSTALLED_VERSION found, but $REQUIRED_VERSION is required." - echo "Installing correct version $REQUIRED_VERSION..." + INSTALLED_VERSION=$(echo "$VERSION_OUTPUT" | sed -n 's/^golangci-lint has version v\([0-9.]*\).*/\1/p') + if ! version_greater_or_equal "$INSTALLED_VERSION" "${REQUIRED_VERSION#v}"; then + echo "golangci-lint version $INSTALLED_VERSION found, but $REQUIRED_VERSION or newer is required." + echo "Installing version $REQUIRED_VERSION..." go install github.com/golangci/golangci-lint/cmd/golangci-lint@$REQUIRED_VERSION fi fi