verify-linkcheck.sh 1.8 KB

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