blob: 399df05617928ef9bb0334a80077960bce6c341d [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. Hartmann7c7eb1c2014-07-08 18:55:55 +02007DOXYGEN_VER=doxygen-1.8.7
8DOXYGEN_TAR=${DOXYGEN_VER}.linux.bin.tar.gz
9DOXYGEN_URL="http://ftp.stack.nl/pub/users/dimitri/${DOXYGEN_TAR}"
10DOXYGEN_BIN="/usr/local/bin/doxygen"
11
Philipp A. Hartmannc1afdc82014-07-12 19:56:30 +020012: ${GITHUB_REPO:="miloyip/rapidjson"}
Philipp A. Hartmann03834b52014-07-13 11:48:37 +020013GITHUB_HOST="github.com"
14GITHUB_CLONE="git://${GITHUB_HOST}/${GITHUB_REPO}"
15GITHUB_URL="https://${GITHUB_HOST}/${GITHUB_PUSH-${GITHUB_REPO}}"
Philipp A. Hartmann4dafa2a2014-07-12 20:47:55 +020016
17# if not set, ignore password
Philipp A. Hartmann03834b52014-07-13 11:48:37 +020018#GIT_ASKPASS="${TRAVIS_BUILD_DIR}/gh_ignore_askpass.sh"
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020019
20skip() {
21 echo "$@" 1>&2
22 echo "Exiting..." 1>&2
23 exit 0
24}
25
26abort() {
27 echo "Error: $@" 1>&2
28 echo "Exiting..." 1>&2
29 exit 1
30}
31
32# TRAVIS_BUILD_DIR not set, exiting
33[ -d "${TRAVIS_BUILD_DIR-/nonexistent}" ] || \
34 abort '${TRAVIS_BUILD_DIR} not set or nonexistent.'
35
36# check for pull-requests
37[ "${TRAVIS_PULL_REQUEST}" = "false" ] || \
38 skip "Not running Doxygen for pull-requests."
39
40# check for branch name
41[ "${TRAVIS_BRANCH}" = "master" ] || \
42 skip "Running Doxygen only for updates on 'master' branch (current: ${TRAVIS_BRANCH})."
43
44# check for job number
45[ "${TRAVIS_JOB_NUMBER}" = "${TRAVIS_BUILD_NUMBER}.1" ] || \
46 skip "Running Doxygen only on first job of build ${TRAVIS_BUILD_NUMBER} (current: ${TRAVIS_JOB_NUMBER})."
47
48# install doxygen binary distribution
49doxygen_install()
50{
51 wget -O - "${DOXYGEN_URL}" | \
52 tar xz -C ${TMPDIR-/tmp} ${DOXYGEN_VER}/bin/doxygen
Andriy Senkovychd2b235e2014-11-19 02:45:09 +020053 export PATH="${TMPDIR-/tmp}/${DOXYGEN_VER}/bin:$PATH"
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020054}
55
56doxygen_run()
57{
Andriy Senkovychd2b235e2014-11-19 02:45:09 +020058 cd "${TRAVIS_BUILD_DIR}";
59 doxygen ${TRAVIS_BUILD_DIR}/build/doc/Doxyfile;
miloyipd1a345a2015-04-02 15:48:13 +080060 doxygen ${TRAVIS_BUILD_DIR}/build/doc/Doxyfile.zh-cn;
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020061}
62
63gh_pages_prepare()
64{
Andriy Senkovych40c03112014-11-12 01:57:25 +020065 cd "${TRAVIS_BUILD_DIR}/build/doc";
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020066 [ ! -d "html" ] || \
67 abort "Doxygen target directory already exists."
Philipp A. Hartmann4dafa2a2014-07-12 20:47:55 +020068 git --version
Philipp A. Hartmann03834b52014-07-13 11:48:37 +020069 git clone --single-branch -b gh-pages "${GITHUB_CLONE}" html
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020070 cd html
Philipp A. Hartmannb3665602014-07-09 08:01:25 +020071 # setup git config (with defaults)
Philipp A. Hartmann2875b572014-07-12 19:02:56 +020072 git config user.name "${GIT_NAME-travis}"
73 git config user.email "${GIT_EMAIL-"travis@localhost"}"
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020074 # clean working dir
75 rm -f .git/index
76 git clean -df
77}
78
79gh_pages_commit() {
Andriy Senkovych40c03112014-11-12 01:57:25 +020080 cd "${TRAVIS_BUILD_DIR}/build/doc/html";
miloyip93bf4ce2015-06-05 14:08:15 +080081 echo "www.rapidjson.org" > CNAME
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020082 git add --all;
Philipp A. Hartmannb3665602014-07-09 08:01:25 +020083 git diff-index --quiet HEAD || git commit -m "Automatic doxygen build";
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020084}
85
Philipp A. Hartmann4dafa2a2014-07-12 20:47:55 +020086gh_setup_askpass() {
87 cat > ${GIT_ASKPASS} <<EOF
88#!/bin/bash
89echo
90exit 0
91EOF
92 chmod a+x "$GIT_ASKPASS"
93}
94
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020095gh_pages_push() {
96 # check for secure variables
97 [ "${TRAVIS_SECURE_ENV_VARS}" = "true" ] || \
98 skip "Secure variables not available, not updating GitHub pages."
Philipp A. Hartmann5050f182014-07-11 13:19:45 +020099 # check for GitHub access token
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +0200100 [ "${GH_TOKEN+set}" = set ] || \
101 skip "GitHub access token not available, not updating GitHub pages."
Philipp A. Hartmann5050f182014-07-11 13:19:45 +0200102 [ "${#GH_TOKEN}" -eq 40 ] || \
103 abort "GitHub token invalid: found ${#GH_TOKEN} characters, expected 40."
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +0200104
Andriy Senkovych40c03112014-11-12 01:57:25 +0200105 cd "${TRAVIS_BUILD_DIR}/build/doc/html";
Philipp A. Hartmann72d0d422014-07-09 18:24:13 +0200106 # setup credentials (hide in "set -x" mode)
Philipp A. Hartmann4dafa2a2014-07-12 20:47:55 +0200107 git remote set-url --push origin "${GITHUB_URL}"
Philipp A. Hartmann4dafa2a2014-07-12 20:47:55 +0200108 git config credential.helper 'store'
Philipp A. Hartmann03834b52014-07-13 11:48:37 +0200109 # ( set +x ; git config credential.username "${GH_TOKEN}" )
Philipp A. Hartmannd08eb762014-07-13 12:10:42 +0200110 ( set +x ; [ -f ${HOME}/.git-credentials ] || \
111 ( echo "https://${GH_TOKEN}:@${GITHUB_HOST}" > ${HOME}/.git-credentials ; \
112 chmod go-rw ${HOME}/.git-credentials ) )
Philipp A. Hartmann72d0d422014-07-09 18:24:13 +0200113 # push to GitHub
Philipp A. Hartmann8d8ce9e2014-07-13 11:54:24 +0200114 git push origin gh-pages
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +0200115}
116
117doxygen_install
118gh_pages_prepare
119doxygen_run
120gh_pages_commit
121gh_pages_push
122