all_lang_docgen.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #! /bin/bash
  2. # Copyright 2020 The gRPC 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. # A script to automatically generate API references and push to GitHub.
  17. # This script covers Core/C++/ObjC/C#/PHP/Python. Due to lack of tooling for
  18. # Cython, Python document generation unfortunately needs to compile everything.
  19. # So, this script will take couple minutes to run.
  20. #
  21. # Generate and push:
  22. #
  23. # tools/distrib/docgen/all_lang-docgen.sh YOUR_GITHUB_USERNAME
  24. #
  25. # Just generate:
  26. #
  27. # tools/distrib/docgen/all_lang-docgen.sh
  28. #
  29. set -e
  30. # Find out the gRPC version and print it
  31. GRPC_VERSION="$(grep -m1 -Eo ' version: .*' build_handwritten.yaml | grep -Eo '[0-9][^ ]*')"
  32. echo "Generating documents for version ${GRPC_VERSION}..."
  33. # Specifies your GitHub user name or generates documents locally
  34. if [ $# -eq 0 ]; then
  35. read -r -p "- Are you sure to generate documents without pushing to GitHub? [y/N] " response
  36. if [[ "${response[0]}" =~ ^([yY][eE][sS]|[yY])$ ]]; then
  37. GITHUB_USER=''
  38. else
  39. echo "Generation stopped"
  40. exit 1
  41. fi
  42. else
  43. if [ $# -eq 1 ]; then
  44. GITHUB_USER=$1
  45. else
  46. echo "Too many arguments!"
  47. exit 1
  48. fi
  49. fi
  50. # Exits on pending changes; please double check for unwanted code changes
  51. git diff --exit-code
  52. git submodule update --init --recursive
  53. # Changes to project root
  54. dir=$(dirname "${0}")
  55. cd "${dir}/../../.."
  56. # Clones the API reference GitHub Pages branch
  57. PAGES_PATH="/tmp/gh-pages"
  58. rm -rf "${PAGES_PATH}"
  59. git clone --single-branch https://github.com/grpc/grpc -b gh-pages "${PAGES_PATH}"
  60. # Generates Core / C++ / ObjC / PHP documents
  61. rm -rf "${PAGES_PATH}/core" "${PAGES_PATH}/cpp" "${PAGES_PATH}/objc" "${PAGES_PATH}/php"
  62. echo "Generating Core / C++ / ObjC / PHP documents in Docker..."
  63. docker run --rm -it \
  64. -v "$(pwd)":/work/grpc \
  65. --user "$(id -u):$(id -g)" \
  66. hrektts/doxygen /work/grpc/tools/doxygen/run_doxygen.sh
  67. mv doc/ref/c++/html "${PAGES_PATH}/cpp"
  68. mv doc/ref/core/html "${PAGES_PATH}/core"
  69. mv doc/ref/objc/html "${PAGES_PATH}/objc"
  70. mv doc/ref/php/html "${PAGES_PATH}/php"
  71. # Generates C# documents
  72. rm -rf "${PAGES_PATH}/csharp"
  73. echo "Generating C# documents in Docker..."
  74. docker run --rm -it \
  75. -v "$(pwd)":/work \
  76. -w /work/src/csharp/docfx \
  77. --user "$(id -u):$(id -g)" \
  78. tsgkadot/docker-docfx:latest docfx
  79. mv src/csharp/docfx/html "${PAGES_PATH}/csharp"
  80. # Generates Python documents
  81. rm -rf "${PAGES_PATH}/python"
  82. echo "Generating Python documents in Docker..."
  83. docker run --rm -it \
  84. -v "$(pwd)":/work \
  85. -w /work \
  86. --user "$(id -u):$(id -g)" \
  87. python:3.8 tools/distrib/docgen/_generate_python_doc.sh
  88. mv doc/build "${PAGES_PATH}/python"
  89. # At this point, document generation is finished.
  90. echo "================================================================="
  91. echo " Successfully generated documents for version ${GRPC_VERSION}."
  92. echo "================================================================="
  93. # Uploads to GitHub
  94. if [[ -n "${GITHUB_USER}" ]]; then
  95. BRANCH_NAME="doc-${GRPC_VERSION}"
  96. (cd "${PAGES_PATH}"
  97. git remote add "${GITHUB_USER}" "git@github.com:${GITHUB_USER}/grpc.git"
  98. git checkout -b "${BRANCH_NAME}"
  99. git add --all
  100. git commit -m "Auto-update documentation for gRPC ${GRPC_VERSION}"
  101. git push --set-upstream "${GITHUB_USER}" "${BRANCH_NAME}"
  102. )
  103. echo "Please check https://github.com/${GITHUB_USER}/grpc/tree/${BRANCH_NAME} for generated documents."
  104. echo "Click https://github.com/grpc/grpc/compare/gh-pages...${GITHUB_USER}:${BRANCH_NAME} to create a PR."
  105. else
  106. echo "Please check ${PAGES_PATH} for generated documents."
  107. fi