build_doc.sh 2.4 KB
Newer Older
Y
Yu Yang 已提交
1
#!/bin/bash
Y
Yi Wang 已提交
2 3 4 5 6
set -e

# Create the build directory for CMake.
mkdir -p $TRAVIS_BUILD_DIR/build
cd $TRAVIS_BUILD_DIR/build
Y
Yu Yang 已提交
7

W
wuyi05 已提交
8
# Compile Documentation only.
9
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWITH_GPU=OFF -DWITH_MKL=OFF -DWITH_DOC=ON
10
make -j `nproc` gen_proto_py
11
make -j `nproc` paddle_python
L
Luo Tao 已提交
12
make -j `nproc` paddle_docs paddle_docs_cn paddle_api_docs
L
Luo Tao 已提交
13 14
make -j `nproc` print_operators_doc
paddle/pybind/print_operators_doc > doc/en/html/operators.json
Y
Yu Yang 已提交
15

L
Luo Tao 已提交
16
# check websites for broken links
17 18
linkchecker doc/en/html/index.html
linkchecker doc/cn/html/index.html
L
Luo Tao 已提交
19
linkchecker doc/api/en/html/index.html
L
Luo Tao 已提交
20

Y
Yu Yang 已提交
21 22 23 24 25 26
# Parse Github URL
REPO=`git config remote.origin.url`
SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
SHA=`git rev-parse --verify HEAD`

# Documentation branch name
W
wuyi05 已提交
27
# gh-pages branch is used for PaddlePaddle.org. The English version of
Y
Yu Yang 已提交
28 29 30 31 32 33 34 35
# documentation in `doc` directory, and the chinese version in `doc_cn`
# directory.
TARGET_BRANCH="gh-pages"

# Only deploy master branch to build latest documentation.
SOURCE_BRANCH="master"

# Clone the repo to output directory
L
Luo Tao 已提交
36
mkdir output
Y
Yu Yang 已提交
37 38 39
git clone $REPO output
cd output

Y
Yu Yang 已提交
40 41 42 43 44 45 46 47 48 49 50
function deploy_docs() {
  SOURCE_BRANCH=$1
  DIR=$2
  # If is not a Github pull request
  if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
    exit 0
  fi
  # If it is not watched branch.
  if [ "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
    return
  fi
Y
Yu Yang 已提交
51

Y
Yu Yang 已提交
52 53
  # checkout github page branch
  git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
W
wuyi05 已提交
54

Y
Yu Yang 已提交
55 56 57
  mkdir -p ${DIR}
  # remove old docs. mv new docs.
  set +e
L
Luo Tao 已提交
58
  rm -rf ${DIR}/doc ${DIR}/doc_cn ${DIR}/api_doc
Y
Yu Yang 已提交
59
  set -e
D
daming-lu 已提交
60 61
  cp -r ../doc/cn/html ${DIR}/doc_cn
  cp -r ../doc/en/html ${DIR}/doc
L
Luo Tao 已提交
62
  cp -r ../doc/api/en/html ${DIR}/api_doc
Y
Yu Yang 已提交
63 64 65
  git add .
}

W
wuyi05 已提交
66
deploy_docs "master" "."
Y
Yu Yang 已提交
67
deploy_docs "develop" "./develop/"
Y
Yu Yang 已提交
68 69 70

# Check is there anything changed.
set +e
Y
Yu Yang 已提交
71
git diff --cached --exit-code >/dev/null
Y
Yu Yang 已提交
72 73 74 75 76 77
if [ $? -eq 0 ]; then
  echo "No changes to the output on this push; exiting."
  exit 0
fi
set -e

Y
Yu Yang 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
if [ -n $SSL_KEY ]; then  # Only push updated docs for github.com/PaddlePaddle/Paddle.
  # Commit
  git add .
  git config user.name "Travis CI"
  git config user.email "paddle-dev@baidu.com"
  git commit -m "Deploy to GitHub Pages: ${SHA}"
  # Set ssh private key
  openssl aes-256-cbc -K $SSL_KEY -iv $SSL_IV -in ../../paddle/scripts/travis/deploy_key.enc -out deploy_key -d
  chmod 600 deploy_key
  eval `ssh-agent -s`
  ssh-add deploy_key

  # Push
  git push $SSH_REPO $TARGET_BRANCH

fi