github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/hack/verify-variables.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  # GoFmt apparently is changing @ head...
    18  
    19  set -o errexit
    20  set -o nounset
    21  set -o pipefail
    22  
    23  ROOT=$(dirname "${BASH_SOURCE}")/..
    24  
    25  function print_file() {
    26    grep "export" "${1}" | cut -f2 -d" " | cut -f1 -d"=" | sort
    27  }
    28  
    29  function find_files() {
    30    echo $(ls "${ROOT}/jobs/" | grep ".sh")
    31  }
    32  
    33  function find_duplicates() {
    34    if [[ "$(print_file $1 | wc -l)" -ne "$(print_file $1 | uniq | wc -l)" ]]; then
    35      diff <(print_file $1) <(print_file $1 | uniq) | sed "s/^/^$f /g" | grep "<" 1>&2
    36      echo "${1}"
    37    fi
    38  }
    39  
    40  bad_files=""
    41  
    42  for f in $(find_files); do
    43    duplicates=$(find_duplicates "${ROOT}/jobs/$f")
    44    if [[ -n "${duplicates}" ]]; then
    45      bad_files=$(echo "${bad_files}" && echo "${f}")
    46    fi
    47  done
    48  
    49  if [[ -n "${bad_files}" ]]; then
    50    echo "Found duplicate declarations in files"
    51    exit 1
    52  fi