Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update golangci-lint to newer faster version #16636

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/static_checks_etc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected].1
run: go install github.com/golangci/golangci-lint/cmd/[email protected].2

- name: Clean Env
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
Expand Down
36 changes: 31 additions & 5 deletions misc/git/hooks/golangci-lint
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,44 @@
# 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
echo "golangci-lint not found. Installing version $REQUIRED_VERSION..."
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
Expand Down
Loading