blob: 33ec6ab3ab10a35ed09217d43649f70bda7d93ea [file] [log] [blame]
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +02001#!/bin/bash
2# Update Doxygen documentation after push to 'master'.
3# Author: @pah
4
5set -e
6
Philipp A. Hartmann71618942017-07-10 21:32:16 +02007DOXYGEN_VER=doxygen-1.8.13
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +02008DOXYGEN_TAR=${DOXYGEN_VER}.linux.bin.tar.gz
9DOXYGEN_URL="http://ftp.stack.nl/pub/users/dimitri/${DOXYGEN_TAR}"
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020010
Milo Yip4a2f2722017-09-13 17:03:23 +080011: ${GITHUB_REPO:="Tencent/rapidjson"}
Philipp A. Hartmann03834b52014-07-13 11:48:37 +020012GITHUB_HOST="github.com"
13GITHUB_CLONE="git://${GITHUB_HOST}/${GITHUB_REPO}"
14GITHUB_URL="https://${GITHUB_HOST}/${GITHUB_PUSH-${GITHUB_REPO}}"
Philipp A. Hartmann4dafa2a2014-07-12 20:47:55 +020015
16# if not set, ignore password
Philipp A. Hartmann03834b52014-07-13 11:48:37 +020017#GIT_ASKPASS="${TRAVIS_BUILD_DIR}/gh_ignore_askpass.sh"
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020018
19skip() {
20 echo "$@" 1>&2
21 echo "Exiting..." 1>&2
22 exit 0
23}
24
25abort() {
26 echo "Error: $@" 1>&2
27 echo "Exiting..." 1>&2
28 exit 1
29}
30
31# TRAVIS_BUILD_DIR not set, exiting
32[ -d "${TRAVIS_BUILD_DIR-/nonexistent}" ] || \
33 abort '${TRAVIS_BUILD_DIR} not set or nonexistent.'
34
35# check for pull-requests
36[ "${TRAVIS_PULL_REQUEST}" = "false" ] || \
37 skip "Not running Doxygen for pull-requests."
38
39# check for branch name
40[ "${TRAVIS_BRANCH}" = "master" ] || \
41 skip "Running Doxygen only for updates on 'master' branch (current: ${TRAVIS_BRANCH})."
42
43# check for job number
Milo Yip6d9ab582016-07-29 15:27:32 +080044# [ "${TRAVIS_JOB_NUMBER}" = "${TRAVIS_BUILD_NUMBER}.1" ] || \
45# skip "Running Doxygen only on first job of build ${TRAVIS_BUILD_NUMBER} (current: ${TRAVIS_JOB_NUMBER})."
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020046
47# install doxygen binary distribution
48doxygen_install()
49{
50 wget -O - "${DOXYGEN_URL}" | \
51 tar xz -C ${TMPDIR-/tmp} ${DOXYGEN_VER}/bin/doxygen
Andriy Senkovychd2b235e2014-11-19 02:45:09 +020052 export PATH="${TMPDIR-/tmp}/${DOXYGEN_VER}/bin:$PATH"
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020053}
54
55doxygen_run()
56{
Andriy Senkovychd2b235e2014-11-19 02:45:09 +020057 cd "${TRAVIS_BUILD_DIR}";
58 doxygen ${TRAVIS_BUILD_DIR}/build/doc/Doxyfile;
miloyipd1a345a2015-04-02 15:48:13 +080059 doxygen ${TRAVIS_BUILD_DIR}/build/doc/Doxyfile.zh-cn;
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020060}
61
62gh_pages_prepare()
63{
Andriy Senkovych40c03112014-11-12 01:57:25 +020064 cd "${TRAVIS_BUILD_DIR}/build/doc";
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020065 [ ! -d "html" ] || \
66 abort "Doxygen target directory already exists."
Philipp A. Hartmann4dafa2a2014-07-12 20:47:55 +020067 git --version
Philipp A. Hartmann71618942017-07-10 21:32:16 +020068 git clone --single-branch -b gh-pages "${GITHUB_CLONE}" html
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020069 cd html
Philipp A. Hartmannb3665602014-07-09 08:01:25 +020070 # setup git config (with defaults)
Philipp A. Hartmann2875b572014-07-12 19:02:56 +020071 git config user.name "${GIT_NAME-travis}"
72 git config user.email "${GIT_EMAIL-"travis@localhost"}"
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020073 # clean working dir
74 rm -f .git/index
75 git clean -df
76}
77
78gh_pages_commit() {
Andriy Senkovych40c03112014-11-12 01:57:25 +020079 cd "${TRAVIS_BUILD_DIR}/build/doc/html";
miloyip19687062015-06-06 21:29:52 +080080 echo "rapidjson.org" > CNAME
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020081 git add --all;
Philipp A. Hartmannb3665602014-07-09 08:01:25 +020082 git diff-index --quiet HEAD || git commit -m "Automatic doxygen build";
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020083}
84
Philipp A. Hartmann4dafa2a2014-07-12 20:47:55 +020085gh_setup_askpass() {
86 cat > ${GIT_ASKPASS} <<EOF
87#!/bin/bash
88echo
89exit 0
90EOF
91 chmod a+x "$GIT_ASKPASS"
92}
93
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020094gh_pages_push() {
95 # check for secure variables
96 [ "${TRAVIS_SECURE_ENV_VARS}" = "true" ] || \
97 skip "Secure variables not available, not updating GitHub pages."
Philipp A. Hartmann5050f182014-07-11 13:19:45 +020098 # check for GitHub access token
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020099 [ "${GH_TOKEN+set}" = set ] || \
100 skip "GitHub access token not available, not updating GitHub pages."
Philipp A. Hartmann5050f182014-07-11 13:19:45 +0200101 [ "${#GH_TOKEN}" -eq 40 ] || \
102 abort "GitHub token invalid: found ${#GH_TOKEN} characters, expected 40."
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +0200103
Andriy Senkovych40c03112014-11-12 01:57:25 +0200104 cd "${TRAVIS_BUILD_DIR}/build/doc/html";
Philipp A. Hartmann72d0d422014-07-09 18:24:13 +0200105 # setup credentials (hide in "set -x" mode)
Philipp A. Hartmann4dafa2a2014-07-12 20:47:55 +0200106 git remote set-url --push origin "${GITHUB_URL}"
Philipp A. Hartmann4dafa2a2014-07-12 20:47:55 +0200107 git config credential.helper 'store'
Philipp A. Hartmann03834b52014-07-13 11:48:37 +0200108 # ( set +x ; git config credential.username "${GH_TOKEN}" )
Philipp A. Hartmannd08eb762014-07-13 12:10:42 +0200109 ( set +x ; [ -f ${HOME}/.git-credentials ] || \
110 ( echo "https://${GH_TOKEN}:@${GITHUB_HOST}" > ${HOME}/.git-credentials ; \
111 chmod go-rw ${HOME}/.git-credentials ) )
Philipp A. Hartmann72d0d422014-07-09 18:24:13 +0200112 # push to GitHub
Philipp A. Hartmann8d8ce9e2014-07-13 11:54:24 +0200113 git push origin gh-pages
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +0200114}
115
116doxygen_install
117gh_pages_prepare
118doxygen_run
119gh_pages_commit
120gh_pages_push
121