verify-munge-docs.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. git_upstream=$(kube::util::git_upstream_remote_name)
  21. : ${git_upstream:="upstream"}
  22. kube::golang::setup_env
  23. make -C "${KUBE_ROOT}/" WHAT=cmd/mungedocs
  24. # Find binary
  25. mungedocs=$(kube::util::find-binary "mungedocs")
  26. DOCROOT="${KUBE_ROOT}/docs/"
  27. EXAMPLEROOT="${KUBE_ROOT}/examples/"
  28. # mungedocs --verify can (and should) be run on the real docs, otherwise their
  29. # links will be distorted. --verify means that it will not make changes.
  30. # --verbose gives us output we can use for a diff.
  31. "${mungedocs}" "--verify=true" "--verbose=true" "--upstream=${git_upstream}" "--root-dir=${DOCROOT}" && ret=0 || ret=$?
  32. if [[ $ret -eq 1 ]]; then
  33. echo "${DOCROOT} is out of date. Please run hack/update-munge-docs.sh"
  34. exit 1
  35. fi
  36. if [[ $ret -gt 1 ]]; then
  37. echo "Error running mungedocs"
  38. exit 1
  39. fi
  40. "${mungedocs}" "--verify=true" "--verbose=true" "--upstream=${git_upstream}" "--root-dir=${EXAMPLEROOT}" && ret=0 || ret=$?
  41. if [[ $ret -eq 1 ]]; then
  42. echo "${EXAMPLEROOT} is out of date. Please run hack/update-munge-docs.sh"
  43. exit 1
  44. fi
  45. if [[ $ret -gt 1 ]]; then
  46. echo "Error running mungedocs"
  47. exit 1
  48. fi
  49. "${mungedocs}" "--verify=true" "--verbose=true" \
  50. "--upstream=${git_upstream}" \
  51. "--skip-munges=unversioned-warning,analytics" \
  52. "--norecurse" \
  53. "--root-dir=${KUBE_ROOT}/" && ret=0 || ret=$?
  54. if [[ $ret -eq 1 ]]; then
  55. echo "${KUBE_ROOT}/ is out of date. Please run hack/update-munge-docs.sh"
  56. exit 1
  57. elif [[ $ret -gt 1 ]]; then
  58. echo "Error running mungedocs."
  59. exit 1
  60. fi
  61. needsanalytics=($(kube::util::gen-analytics "${KUBE_ROOT}" 1))
  62. if [[ ${#needsanalytics[@]} -ne 0 ]]; then
  63. echo -e "Some md files are missing ga-beacon analytics link:"
  64. printf '%s\n' "${needsanalytics[@]}"
  65. ret=1
  66. fi
  67. if [[ $ret -eq 0 ]]; then
  68. echo "Docs are properly munged."
  69. else
  70. echo "Docs need munging. Please run hack/update-munge-docs.sh"
  71. exit 1
  72. fi
  73. # ex: ts=2 sw=2 et filetype=sh