docs.sh 1.8 KB
Newer Older
Y
Yu Yang 已提交
1 2 3 4 5 6 7 8 9
#!/bin/bash

# Add set -e, cd to directory.
source ./common.sh

# Compile Documentation only.
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWITH_GPU=OFF -DWITH_DOC=ON
make paddle_docs paddle_docs_cn

L
Luo Tao 已提交
10 11
# check websites for broken links
set +e
L
Luo Tao 已提交
12 13
for i in cn en; do
  linkchecker doc/$i/html/index.html
L
Luo Tao 已提交
14 15 16 17
  if [ $? -ne 0 ]; then
    exit 1
  fi
done
L
Luo Tao 已提交
18
set -e
L
Luo Tao 已提交
19

Y
Yu Yang 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
# 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
# gh-pages branch is used for PaddlePaddle.org. The English version of 
# 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"

# If is not a Github pull request, and in master branch.
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH"  ]; then
  exit 0
fi

# Clone the repo to output directory
git clone $REPO output
cd output

# checkout github page branch
git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH

# remove old docs. mv new docs.
rm -rf doc doc_cn
L
Luo Tao 已提交
48 49
mv ../doc/cn/html doc_cn
mv ../doc/en/html doc
Y
Yu Yang 已提交
50 51 52 53 54 55 56 57 58 59

# Check is there anything changed.
set +e
git diff --exit-code >/dev/null
if [ $? -eq 0 ]; then
  echo "No changes to the output on this push; exiting."
  exit 0
fi
set -e

Y
Yu Yang 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
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