versionize-docs.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. # Copyright 2015 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. # Updates the docs to be ready to be used as release docs for a particular
  16. # version.
  17. # Example usage:
  18. # ./versionize-docs.sh release-1.1
  19. set -o errexit
  20. set -o nounset
  21. set -o pipefail
  22. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
  23. RELEASE_BRANCH=${1-}
  24. # MAJOR_AND_MINOR_VERSION is expected to be something like "v1.1"
  25. MAJOR_AND_MINOR_VERSION="v${RELEASE_BRANCH#release-}"
  26. if [ "$#" -lt 1 ]; then
  27. echo "Usage: versionize-docs.sh <release-branch>, e.g., versionize-docs.sh release-1.1."
  28. echo "The <release-branch> is used to rewrites link URL, which should always point to a release branch, NOT a tag like v1.1.1."
  29. exit 1
  30. fi
  31. SED=sed
  32. if which gsed &>/dev/null; then
  33. SED=gsed
  34. fi
  35. if ! ($SED --version 2>&1 | grep -q GNU); then
  36. echo "!!! GNU sed is required. If on OS X, use 'brew install gnu-sed'."
  37. exit 1
  38. fi
  39. echo "+++ Versioning documentation and examples"
  40. # Update the docs to match this version.
  41. HTML_PREVIEW_PREFIX="https://htmlpreview.github.io/\?https://github.com/kubernetes/kubernetes/blob"
  42. # Update the include directory in definitions.md and operations.md.
  43. DIRECTORY_KEY_WORDS="<REPLACE-WITH-RELEASE-VERSION>"
  44. md_dirs=(docs examples)
  45. md_files=()
  46. for dir in "${md_dirs[@]}"; do
  47. md_files+=($( find "${dir}" -name "*.md" -type f ))
  48. done
  49. for doc in "${md_files[@]}"; do
  50. $SED -ri \
  51. -e '/<!-- BEGIN STRIP_FOR_RELEASE -->/,/<!-- END STRIP_FOR_RELEASE -->/d' \
  52. -e "s|(releases.k8s.io)/[^/]+|\1/${RELEASE_BRANCH}|g" \
  53. "${doc}"
  54. # Replace /HEAD in html preview links with /RELEASE_BRANCH
  55. $SED -ri -e "s|(${HTML_PREVIEW_PREFIX})/HEAD|\1/${RELEASE_BRANCH}|g" "${doc}"
  56. # Replace <REPLACE-WITH-RELEASE-VERSION> with MAJOR_AND_MINOR_VERSION.
  57. $SED -ri -e "s|${DIRECTORY_KEY_WORDS}|${MAJOR_AND_MINOR_VERSION}|g" "${doc}"
  58. is_versioned_tag="<!-- BEGIN MUNGE: IS_VERSIONED -->
  59. <!-- TAG IS_VERSIONED -->
  60. <!-- END MUNGE: IS_VERSIONED -->"
  61. if ! grep -q "${is_versioned_tag}" "${doc}"; then
  62. echo -e "\n\n${is_versioned_tag}\n\n" >> "${doc}"
  63. fi
  64. done
  65. # Update kubectl cmd files so that kubectl docs generated from them are as
  66. # expected.
  67. go_dirs=(pkg/kubectl/cmd)
  68. go_files=()
  69. for dir in "${go_dirs[@]}"; do
  70. go_files+=($( find "${dir}" -name "*.go" -type f ))
  71. done
  72. # Update API descriptions as well
  73. go_files+=(pkg/api/v[0-9]*/types.go)
  74. go_files+=(pkg/api/unversioned/types.go)
  75. go_files+=(pkg/apis/*/v[0-9]*/types.go)
  76. go_files+=(pkg/apis/*/types.go)
  77. for file in "${go_files[@]}"; do
  78. $SED -ri \
  79. -e "s|(releases.k8s.io)/[^/]+|\1/${RELEASE_BRANCH}|g" \
  80. -e "s|(${HTML_PREVIEW_PREFIX})/HEAD|\1/${RELEASE_BRANCH}|g" \
  81. "${file}"
  82. done
  83. ${KUBE_ROOT}/hack/update-munge-docs.sh
  84. ${KUBE_ROOT}/hack/update-generated-swagger-docs.sh
  85. ${KUBE_ROOT}/hack/update-swagger-spec.sh
  86. ${KUBE_ROOT}/hack/update-generated-protobuf.sh
  87. ./hack/update-api-reference-docs.sh