| 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 |
|
| 30 |
set -e |
| 31 |
|
| 32 |
# Find out the gRPC version and print it |
| 33 |
GRPC_VERSION="$(grep -m1 -Eo ' version: .*' build_handwritten.yaml | grep -Eo '[0-9][^ ]*')" |
| 34 |
echo "Generating documents for version ${GRPC_VERSION}..." |
| 35 |
|
| 36 |
# Specifies your GitHub user name or generates documents locally |
| 37 |
if [ $# -eq 0 ]; then |
| 38 |
read -r -p "- Are you sure to generate documents without pushing to GitHub? [y/N] " response |
| 39 |
if [[ "${response[0]}" =~ ^([yY][eE][sS]|[yY])$ ]]; then |
| 40 |
GITHUB_USER='' |
| 41 |
else |
| 42 |
echo "Generation stopped" |
| 43 |
exit 1 |
| 44 |
fi |
| 45 |
else |
| 46 |
if [ $# -eq 1 ]; then |
| 47 |
GITHUB_USER=$1 |
| 48 |
else |
| 49 |
echo "Too many arguments!" |
| 50 |
exit 1 |
| 51 |
fi |
| 52 |
fi |
| 53 |
|
| 54 |
# Exits on pending changes; please double check for unwanted code changes |
| 55 |
git diff --exit-code |
| 56 |
git submodule update --init --recursive |
| 57 |
|
| 58 |
# Changes to project root |
| 59 |
dir=$(dirname "${0}") |
| 60 |
cd "${dir}/../../.." |
| 61 |
|
| 62 |
# Clones the API reference GitHub Pages branch |
| 63 |
PAGES_PATH="/tmp/gh-pages" |
| 64 |
rm -rf "${PAGES_PATH}" |
| 65 |
git clone -o upstream --single-branch https://github.com/grpc/grpc -b gh-pages "${PAGES_PATH}" |
| 66 |
|
| 67 |
# Generates Core / C++ / ObjC / PHP documents |
| 68 |
rm -rf "${PAGES_PATH}/core" "${PAGES_PATH}/cpp" "${PAGES_PATH}/objc" "${PAGES_PATH}/php" |
| 69 |
echo "Generating Core / C++ / ObjC / PHP documents in Docker..." |
| 70 |
docker run --rm -it \ |
| 71 |
-v "$(pwd)":/work/grpc \ |
| 72 |
--user "$(id -u):$(id -g)" \ |
| 73 |
hrektts/doxygen /work/grpc/tools/doxygen/run_doxygen.sh |
| 74 |
mv doc/ref/c++/html "${PAGES_PATH}/cpp" |
| 75 |
mv doc/ref/core/html "${PAGES_PATH}/core" |
| 76 |
mv doc/ref/objc/html "${PAGES_PATH}/objc" |
| 77 |
mv doc/ref/php/html "${PAGES_PATH}/php" |
| 78 |
|
| 79 |
# Generates Python documents |
| 80 |
rm -rf "${PAGES_PATH}/python" |
| 81 |
echo "Generating Python documents in Docker..." |
| 82 |
docker run --rm -it \ |
| 83 |
-v "$(pwd)":/work \ |
| 84 |
-w /work \ |
| 85 |
--user "$(id -u):$(id -g)" \ |
| 86 |
python:3.8 tools/distrib/docgen/_generate_python_doc.sh |
| 87 |
mv doc/build "${PAGES_PATH}/python" |
| 88 |
|
| 89 |
# At this point, document generation is finished. |
| 90 |
echo "=================================================================" |
| 91 |
echo " Successfully generated documents for version ${GRPC_VERSION}." |
| 92 |
echo "=================================================================" |
| 93 |
|
| 94 |
echo "Generated docs are in ${PAGES_PATH}, use the internal release script to create a PR." |