volcano.sh/volcano@v1.9.0/hack/verify-golangci-lint.sh (about)

     1  #!/bin/bash
     2  
     3  # Copyright 2014 The Kubernetes Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  set -o errexit
    18  set -o nounset
    19  set -o pipefail
    20  
    21  KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
    22  GOPATH=$(go env GOPATH | awk -F ':' '{print $1}')
    23  
    24  # check if golangci-lint installed
    25  function check_golangci-lint() {
    26    echo "checking whether golangci-lint has been installed"
    27    command -v golangci-lint >/dev/null 2>&1
    28    if [[ $? -ne 0 ]]; then
    29      echo "installing golangci-lint ."
    30      curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2
    31      if [[ $? -ne 0 ]]; then
    32        echo "golangci-lint installed failed, exiting."
    33        exit 1
    34      fi
    35  
    36      export PATH=$PATH:$GOPATH/bin
    37    else
    38      echo "found golangci-lint"
    39    fi
    40  }
    41  
    42  # run golangci-lint run to check codes
    43  function golangci-lint_run() {
    44    echo "begin run golangci-lint"
    45    cd ${KUBE_ROOT}
    46    ret=0
    47    golangci-lint run -v || ret=$?
    48    if [ $ret -eq 0 ]; then
    49      echo "SUCCESS: golangci-lint verified."
    50    else
    51      echo "FAILED: golangci-lint stale."
    52      echo
    53      echo "Please review the above warnings. You can test via './hack/verify-golangci-lint.sh' or 'make lint'."
    54      echo "If the above warnings do not make sense, you can exempt this warning with a comment"
    55      echo " (if your reviewer is okay with it)."
    56      echo "In general please prefer to fix the error, we have already disabled specific lints"
    57      echo " that the project chooses to ignore."
    58      echo "See: https://golangci-lint.run/usage/false-positives/"
    59      echo
    60      exit 1
    61    fi
    62  }
    63  
    64  set +e
    65  check_golangci-lint
    66  set -e
    67  
    68  set +e
    69  golangci-lint_run
    70  set -e