blob: a85d7baea346cb7275168bbef4712c092bf2839e [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."
66 git clone --single-branch -b gh-pages ${GHPAGES_BASE} html
67 cd html
68 # clean working dir
69 rm -f .git/index
70 git clean -df
71}
72
73gh_pages_commit() {
74 cd "${TRAVIS_BUILD_DIR}/doc/html";
75 git add --all;
76 git commit -m "Automatic doxygen build";
77}
78
79gh_pages_push() {
80 # check for secure variables
81 [ "${TRAVIS_SECURE_ENV_VARS}" = "true" ] || \
82 skip "Secure variables not available, not updating GitHub pages."
83 [ "${GH_TOKEN+set}" = set ] || \
84 skip "GitHub access token not available, not updating GitHub pages."
85
86 cd "${TRAVIS_BUILD_DIR}/doc/html";
87 # push to GitHub without printing GH_TOKEN even in "set -x" mode
88 ( echo "git push ${GHPAGES_PUSH} gh-pages" ; set +x; \
89 eval "git push ${GHPAGES_PUSH} gh-pages" )
90}
91
92doxygen_install
93gh_pages_prepare
94doxygen_run
95gh_pages_commit
96gh_pages_push
97