|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2018 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 -euo pipefail |
| 17 | + |
| 18 | +# This script is intended to be used via subtree in a top-level directory: |
| 19 | +# <repo>/ |
| 20 | +# repo-infra/ |
| 21 | +# verify/ |
| 22 | +# Or via vendoring and passing root directory as vendor/repo-infra/verify-*.sh --rootdir **full path to your repo dir** |
| 23 | +# <repo>/ |
| 24 | +# vendor/ |
| 25 | +# repo-infra/ |
| 26 | +# ... |
| 27 | +# |
| 28 | + |
| 29 | + |
| 30 | +SILENT=true |
| 31 | +REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. |
| 32 | + |
| 33 | +# Convert long opts to short ones to read through getopts |
| 34 | +for arg in "$@"; do |
| 35 | + shift |
| 36 | + case "$arg" in |
| 37 | + "--rootdir") set -- "$@" "-r";; |
| 38 | + *) |
| 39 | + set -- "$@" "$arg" |
| 40 | + ;; |
| 41 | + esac |
| 42 | +done |
| 43 | + |
| 44 | +OPTIND=1 |
| 45 | +while getopts "vr:" opt; do |
| 46 | + case ${opt} in |
| 47 | + v) |
| 48 | + SILENT=false |
| 49 | + ;; |
| 50 | + r) |
| 51 | + REPO_ROOT=${OPTARG} |
| 52 | + ;; |
| 53 | + \?) |
| 54 | + echo "Invalid flag: -${OPTARG}" >&2 |
| 55 | + exit 1 |
| 56 | + ;; |
| 57 | + esac |
| 58 | +done |
| 59 | + |
| 60 | +shift "$(($OPTIND-1))" |
| 61 | + |
| 62 | +echo "Working directory: ${REPO_ROOT}" |
| 63 | + |
| 64 | +GO_TOOLS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/go-tools" |
| 65 | + |
| 66 | +function run-cmd { |
| 67 | + if ${SILENT}; then |
| 68 | + "$@" &> /dev/null |
| 69 | + else |
| 70 | + "$@" |
| 71 | + fi |
| 72 | +} |
| 73 | + |
| 74 | +# Some useful colors. |
| 75 | +if [[ -z "${color_start-}" ]]; then |
| 76 | + declare -r color_start="\033[" |
| 77 | + declare -r color_red="${color_start}0;31m" |
| 78 | + declare -r color_yellow="${color_start}0;33m" |
| 79 | + declare -r color_green="${color_start}0;32m" |
| 80 | + declare -r color_norm="${color_start}0m" |
| 81 | +fi |
| 82 | + |
| 83 | +function run-checks { |
| 84 | + local -r pattern=$1 |
| 85 | + local -r runner=$2 |
| 86 | + |
| 87 | + for t in $(ls ${pattern}) |
| 88 | + do |
| 89 | + echo -e "Verifying ${t}" |
| 90 | + local start=$(date +%s) |
| 91 | + cd $REPO_ROOT && run-cmd "${runner}" "${t}" && tr=$? || tr=$? |
| 92 | + local elapsed=$(($(date +%s) - ${start})) |
| 93 | + if [[ ${tr} -eq 0 ]]; then |
| 94 | + echo -e "${color_green}SUCCESS${color_norm} ${t}\t${elapsed}s" |
| 95 | + else |
| 96 | + echo -e "${color_red}FAILED${color_norm} ${t}\t${elapsed}s" |
| 97 | + ret=1 |
| 98 | + fi |
| 99 | + done |
| 100 | +} |
| 101 | + |
| 102 | +if ${SILENT} ; then |
| 103 | + echo "Running in silent mode, run with -v if you want to see script logs." |
| 104 | +fi |
| 105 | + |
| 106 | +ret=0 |
| 107 | +run-checks "${GO_TOOLS_DIR}/*.sh" bash |
| 108 | +exit ${ret} |
0 commit comments