github.com/zppinho/prow@v0.0.0-20240510014325-1738badeb017/cmd/deck/validate-static-files.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2021 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  # check-file ensures that all static links are valid
    21  check-file() {
    22    for path in $(grep -h -o -E '/static[^"]+' $1); do
    23        local target=prow/cmd/deck$path
    24        if [[ ! -f "$target" ]]; then
    25            echo "  ERROR: $path not found at $target in $1" >&2
    26            return 1
    27        else
    28            echo "  found $path link to $target"
    29        fi
    30    done
    31  }
    32  
    33  fail=()
    34  for arg in "$@"; do
    35      echo Validating "$arg":
    36      check-file "$arg" && echo "  PASS: $arg" || fail+=("$arg")
    37  done
    38  if [[ "${#fail[@]}" -eq 0 ]]; then
    39      exit 0
    40  fi
    41  echo "FAIL: bad links in the following files:" >&2
    42  for bad in "${fail[@]}"; do
    43      echo "  $bad" >&2
    44  done
    45  exit 1