sigs.k8s.io/cluster-api-provider-aws@v1.5.5/hack/verify-shellcheck.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2022 The Kubernetes Authors.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  # This has been copied from https://github.com/kubernetes-sigs/cluster-api/blob/release-1.1/hack/verify-shellcheck.sh
    17  
    18  set -o errexit
    19  set -o nounset
    20  set -o pipefail
    21  
    22  VERSION="v0.7.0"
    23  
    24  OS="unknown"
    25  if [[ "${OSTYPE}" == "linux"* ]]; then
    26    OS="linux"
    27  elif [[ "${OSTYPE}" == "darwin"* ]]; then
    28    OS="darwin"
    29  fi
    30  
    31  # shellcheck source=./hack/utils.sh
    32  source "$(dirname "$0")/utils.sh"
    33  ROOT_PATH=$(get_root_path)
    34  
    35  # create a temporary directory
    36  TMP_DIR=$(mktemp -d)
    37  OUT="${TMP_DIR}/out.log"
    38  
    39  # cleanup on exit
    40  cleanup() {
    41    ret=0
    42    if [[ -s "${OUT}" ]]; then
    43      echo "Found errors:"
    44      cat "${OUT}"
    45      ret=1
    46    fi
    47    echo "Cleaning up..."
    48    rm -rf "${TMP_DIR}"
    49    exit ${ret}
    50  }
    51  trap cleanup EXIT
    52  
    53  
    54  SHELLCHECK="./$(dirname "$0")/tools/bin/shellcheck/${VERSION}/shellcheck"
    55  
    56  if [ ! -f "$SHELLCHECK" ]; then
    57    # install buildifier
    58    cd "${TMP_DIR}" || exit
    59    DOWNLOAD_FILE="shellcheck-${VERSION}.${OS}.x86_64.tar.xz"
    60    curl -L "https://github.com/koalaman/shellcheck/releases/download/${VERSION}/${DOWNLOAD_FILE}" -o "${TMP_DIR}/shellcheck.tar.xz"
    61    tar xf "${TMP_DIR}/shellcheck.tar.xz"
    62    cd "${ROOT_PATH}"
    63    mkdir -p "$(dirname "$0")/tools/bin/shellcheck/${VERSION}"
    64    mv "${TMP_DIR}/shellcheck-${VERSION}/shellcheck" "$SHELLCHECK"
    65  fi
    66  
    67  echo "Running shellcheck..."
    68  cd "${ROOT_PATH}" || exit
    69  IGNORE_FILES=$(find . -name "*.sh" | grep "third_party\|tilt_modules")
    70  echo "Ignoring shellcheck on ${IGNORE_FILES}"
    71  FILES=$(find . -name "*.sh" -not -path "./tilt_modules/*" -not -path "*third_party*")
    72  while read -r file; do
    73      "$SHELLCHECK" -x "$file" >> "${OUT}" 2>&1
    74  done <<< "$FILES"