blob: 4d1d57b093483c0c28d055fa421516214fc7cb62 [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
7SUDO=sudo
8DOXYGEN_VER=doxygen-1.8.7
9DOXYGEN_TAR=${DOXYGEN_VER}.linux.bin.tar.gz
10DOXYGEN_URL="http://ftp.stack.nl/pub/users/dimitri/${DOXYGEN_TAR}"
11DOXYGEN_BIN="/usr/local/bin/doxygen"
12
13GHPAGES_REPO="miloyip/rapidjson"
14GHPAGES_BASE="https://github.com/${GHPAGES_REPO}"
15# NOTE: not expanded here to hide GH_TOKEN
16GHPAGES_PUSH='https://${GH_TOKEN}@github.com/${GHPAGES_REPO}'
17
18skip() {
19 echo "$@" 1>&2
20 echo "Exiting..." 1>&2
21 exit 0
22}
23
24abort() {
25 echo "Error: $@" 1>&2
26 echo "Exiting..." 1>&2
27 exit 1
28}
29
30# TRAVIS_BUILD_DIR not set, exiting
31[ -d "${TRAVIS_BUILD_DIR-/nonexistent}" ] || \
32 abort '${TRAVIS_BUILD_DIR} not set or nonexistent.'
33
34# check for pull-requests
35[ "${TRAVIS_PULL_REQUEST}" = "false" ] || \
36 skip "Not running Doxygen for pull-requests."
37
38# check for branch name
39[ "${TRAVIS_BRANCH}" = "master" ] || \
40 skip "Running Doxygen only for updates on 'master' branch (current: ${TRAVIS_BRANCH})."
41
42# check for job number
43[ "${TRAVIS_JOB_NUMBER}" = "${TRAVIS_BUILD_NUMBER}.1" ] || \
44 skip "Running Doxygen only on first job of build ${TRAVIS_BUILD_NUMBER} (current: ${TRAVIS_JOB_NUMBER})."
45
46# install doxygen binary distribution
47doxygen_install()
48{
49 wget -O - "${DOXYGEN_URL}" | \
50 tar xz -C ${TMPDIR-/tmp} ${DOXYGEN_VER}/bin/doxygen
51 $SUDO install -m 755 ${TMPDIR-/tmp}/${DOXYGEN_VER}/bin/doxygen \
52 ${DOXYGEN_BIN};
53}
54
55doxygen_run()
56{
57 cd "${TRAVIS_BUILD_DIR}";
58 doxygen build/Doxyfile;
59}
60
61gh_pages_prepare()
62{
63 cd "${TRAVIS_BUILD_DIR}/doc";
64 [ ! -d "html" ] || \
65 abort "Doxygen target directory already exists."
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020066 git clone --single-branch -b gh-pages ${GHPAGES_BASE} html
67 cd html
Philipp A. Hartmannb3665602014-07-09 08:01:25 +020068 # setup git config (with defaults)
69 git config user.name "${GIT_NAME-travis}"
70 git config user.email "${GIT_EMAIL-"travis@localhost"}"
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020071 # clean working dir
72 rm -f .git/index
73 git clean -df
74}
75
76gh_pages_commit() {
77 cd "${TRAVIS_BUILD_DIR}/doc/html";
78 git add --all;
Philipp A. Hartmannb3665602014-07-09 08:01:25 +020079 git diff-index --quiet HEAD || git commit -m "Automatic doxygen build";
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020080}
81
82gh_pages_push() {
83 # check for secure variables
84 [ "${TRAVIS_SECURE_ENV_VARS}" = "true" ] || \
85 skip "Secure variables not available, not updating GitHub pages."
86 [ "${GH_TOKEN+set}" = set ] || \
87 skip "GitHub access token not available, not updating GitHub pages."
88
89 cd "${TRAVIS_BUILD_DIR}/doc/html";
90 # push to GitHub without printing GH_TOKEN even in "set -x" mode
91 ( echo "git push ${GHPAGES_PUSH} gh-pages" ; set +x; \
92 eval "git push ${GHPAGES_PUSH} gh-pages" )
93}
94
95doxygen_install
96gh_pages_prepare
97doxygen_run
98gh_pages_commit
99gh_pages_push
100