sigs.k8s.io/cluster-api-provider-azure@v1.14.3/hack/verify-starlark.sh (about) 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 SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" 21 ROOT_PATH="$(cd "${SCRIPT_DIR}"/.. && pwd)" 22 23 VERSION="0.29.0" 24 25 MODE="check" 26 27 if [[ "$*" == "fix" ]]; then 28 MODE="fix" 29 fi 30 31 if [[ "${OSTYPE}" == "linux"* ]]; then 32 BINARY="buildifier" 33 elif [[ "${OSTYPE}" == "darwin"* ]]; then 34 BINARY="buildifier.mac" 35 fi 36 37 # create a temporary directory 38 TMP_DIR=$(mktemp -d) 39 OUT="${TMP_DIR}/out.log" 40 41 # cleanup on exit 42 capz::verify-starlark::cleanup() { 43 ret=0 44 if [[ -s "${OUT}" ]]; then 45 echo "Found errors:" 46 cat "${OUT}" 47 echo "" 48 echo "run make format-tiltfile to fix the errors" 49 ret=1 50 fi 51 echo "Cleaning up..." 52 rm -rf "${TMP_DIR}" 53 exit ${ret} 54 } 55 trap capz::verify-starlark::cleanup EXIT 56 57 BUILDIFIER="${SCRIPT_DIR}/tools/bin/buildifier/${VERSION}/buildifier" 58 59 if [ ! -f "$BUILDIFIER" ]; then 60 # install buildifier 61 cd "${TMP_DIR}" || exit 62 curl --retry 3 -L "https://github.com/bazelbuild/buildtools/releases/download/${VERSION}/${BINARY}" -o "${TMP_DIR}/buildifier" 63 chmod +x "${TMP_DIR}/buildifier" 64 cd "${ROOT_PATH}" 65 mkdir -p "$(dirname "$0")/tools/bin/buildifier/${VERSION}" 66 mv "${TMP_DIR}/buildifier" "$BUILDIFIER" 67 fi 68 69 echo "Running buildifier..." 70 cd "${ROOT_PATH}" || exit 71 "${BUILDIFIER}" -mode=${MODE} Tiltfile >> "${OUT}" 2>&1