|
14 | 14 | # limitations under the License.
|
15 | 15 |
|
16 | 16 | # Required version of golangci-lint
|
17 |
| -REQUIRED_VERSION="v1.60.1" |
| 17 | +REQUIRED_VERSION="v1.60.2" |
| 18 | + |
| 19 | +# Function to compare versions in pure Bash |
| 20 | +version_greater_or_equal() { |
| 21 | + local IFS=. |
| 22 | + local i |
| 23 | + local ver1=($1) |
| 24 | + local ver2=($2) |
| 25 | + |
| 26 | + # Fill empty fields in ver1 with zeros |
| 27 | + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do |
| 28 | + ver1[i]=0 |
| 29 | + done |
| 30 | + # Fill empty fields in ver2 with zeros |
| 31 | + for ((i=${#ver2[@]}; i<${#ver1[@]}; i++)); do |
| 32 | + ver2[i]=0 |
| 33 | + done |
| 34 | + |
| 35 | + for ((i=0; i<${#ver1[@]}; i++)); do |
| 36 | + if ((10#${ver1[i]} > 10#${ver2[i]})); then |
| 37 | + return 0 |
| 38 | + elif ((10#${ver1[i]} < 10#${ver2[i]})); then |
| 39 | + return 1 |
| 40 | + fi |
| 41 | + done |
| 42 | + return 0 |
| 43 | +} |
18 | 44 |
|
19 | 45 | # Check if golangci-lint is installed and capture the version
|
20 | 46 | if ! command -v golangci-lint >/dev/null 2>&1; then
|
21 | 47 | echo "golangci-lint not found. Installing version $REQUIRED_VERSION..."
|
22 | 48 | go install github.com/golangci/golangci-lint/cmd/golangci-lint@$REQUIRED_VERSION
|
23 | 49 | else
|
24 | 50 | VERSION_OUTPUT=$(golangci-lint --version)
|
25 |
| - INSTALLED_VERSION=$(echo "$VERSION_OUTPUT" | sed -n 's/^golangci-lint has version \([v0-9.]*\).*/\1/p') |
26 |
| - if [ "$INSTALLED_VERSION" != "$REQUIRED_VERSION" ]; then |
27 |
| - echo "golangci-lint version $INSTALLED_VERSION found, but $REQUIRED_VERSION is required." |
28 |
| - echo "Installing correct version $REQUIRED_VERSION..." |
| 51 | + INSTALLED_VERSION=$(echo "$VERSION_OUTPUT" | sed -n 's/^golangci-lint has version v\([0-9.]*\).*/\1/p') |
| 52 | + if ! version_greater_or_equal "$INSTALLED_VERSION" "${REQUIRED_VERSION#v}"; then |
| 53 | + echo "golangci-lint version $INSTALLED_VERSION found, but $REQUIRED_VERSION or newer is required." |
| 54 | + echo "Installing version $REQUIRED_VERSION..." |
29 | 55 | go install github.com/golangci/golangci-lint/cmd/golangci-lint@$REQUIRED_VERSION
|
30 | 56 | fi
|
31 | 57 | fi
|
|
0 commit comments