Skip to content

Commit

Permalink
Update golangci-lint to newer faster version (#16636)
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay authored Aug 22, 2024
1 parent feb845a commit 3f87ca2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
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

0 comments on commit 3f87ca2

Please sign in to comment.