verify-linkcheck.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. # Copyright 2014 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. set -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
  19. source "${KUBE_ROOT}/hack/lib/init.sh"
  20. kube::golang::setup_env
  21. make -C "${KUBE_ROOT}" WHAT=cmd/linkcheck
  22. linkcheck=$(kube::util::find-binary "linkcheck")
  23. kube::util::ensure-temp-dir
  24. OUTPUT="${KUBE_TEMP}"/linkcheck-output
  25. cleanup() {
  26. rm -rf "${OUTPUT}"
  27. }
  28. trap "cleanup" EXIT SIGINT
  29. mkdir -p "$OUTPUT"
  30. APIROOT="${KUBE_ROOT}/pkg/api/"
  31. APISROOT="${KUBE_ROOT}/pkg/apis/"
  32. DOCROOT="${KUBE_ROOT}/docs/"
  33. ROOTS=($APIROOT $APISROOT $DOCROOT)
  34. found_invalid=false
  35. for root in "${ROOTS[@]}"; do
  36. "${linkcheck}" "--root-dir=${root}" 2> >(tee -a "${OUTPUT}/error" >&2) && ret=0 || ret=$?
  37. if [[ $ret -eq 1 ]]; then
  38. echo "Failed: found invalid links in ${root}."
  39. found_invalid=true
  40. fi
  41. if [[ $ret -gt 1 ]]; then
  42. echo "Error running linkcheck"
  43. exit 1
  44. fi
  45. done
  46. if [ ${found_invalid} = true ]; then
  47. echo "Summary of invalid links:"
  48. cat ${OUTPUT}/error
  49. exit 1
  50. fi
  51. # ex: ts=2 sw=2 et filetype=sh