|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2019 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 | +# set -o errexit |
| 17 | +set -o nounset |
| 18 | +set -o pipefail |
| 19 | + |
| 20 | +OS="unknown" |
| 21 | +if [[ "${OSTYPE}" == "linux"* ]]; then |
| 22 | + OS="linux" |
| 23 | +elif [[ "${OSTYPE}" == "darwin"* ]]; then |
| 24 | + OS="darwin" |
| 25 | +fi |
| 26 | + |
| 27 | +# shellcheck source=./hack/utils.sh |
| 28 | +source "$(dirname "$0")/utils.sh" |
| 29 | +ROOT_PATH=$(get_root_path) |
| 30 | + |
| 31 | +# create a temporary directory |
| 32 | +TMP_DIR=$(mktemp -d) |
| 33 | + |
| 34 | +# cleanup on exit |
| 35 | +cleanup() { |
| 36 | + echo "Cleaning up..." |
| 37 | + rm -rf "${TMP_DIR}" |
| 38 | +} |
| 39 | +trap cleanup EXIT |
| 40 | + |
| 41 | +# install shellcheck (x64 only!) |
| 42 | +cd "${TMP_DIR}" || exit |
| 43 | +VERSION="shellcheck-v0.7.0" |
| 44 | +DOWNLOAD_FILE="${VERSION}.${OS}.x86_64.tar.xz" |
| 45 | +curl https://storage.googleapis.com/shellcheck/"${DOWNLOAD_FILE}" -O ${DOWNLOAD_FILE} |
| 46 | +tar xf "${DOWNLOAD_FILE}" |
| 47 | +cd "${VERSION}" || exit |
| 48 | + |
| 49 | +echo "Running shellcheck..." |
| 50 | +cd "${ROOT_PATH}" || exit |
| 51 | +OUT="${TMP_DIR}/out.log" |
| 52 | +IGNORE_FILES=$(find . -name "*.sh" | grep third_party) |
| 53 | +echo "Ignoring shellcheck on ${IGNORE_FILES}" |
| 54 | +FILES=$(find . -name "*.sh" | grep -v third_party) |
| 55 | +while read -r file; do |
| 56 | + "${TMP_DIR}/${VERSION}/shellcheck" -x "$file" >> "${OUT}" 2>&1 |
| 57 | +done <<< "$FILES" |
| 58 | + |
| 59 | +if [[ -s "${OUT}" ]]; then |
| 60 | + echo "Found errors:" |
| 61 | + cat "${OUT}" |
| 62 | + exit 1 |
| 63 | +fi |
0 commit comments