blob: ad50b3ff127039bd306b2701bbc211d53dec6e76 [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"
Philipp A. Hartmann72d0d422014-07-09 18:24:13 +020014GHPAGES_URL="https://github.com/${GHPAGES_REPO}"
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020015
16skip() {
17 echo "$@" 1>&2
18 echo "Exiting..." 1>&2
19 exit 0
20}
21
22abort() {
23 echo "Error: $@" 1>&2
24 echo "Exiting..." 1>&2
25 exit 1
26}
27
28# TRAVIS_BUILD_DIR not set, exiting
29[ -d "${TRAVIS_BUILD_DIR-/nonexistent}" ] || \
30 abort '${TRAVIS_BUILD_DIR} not set or nonexistent.'
31
32# check for pull-requests
33[ "${TRAVIS_PULL_REQUEST}" = "false" ] || \
34 skip "Not running Doxygen for pull-requests."
35
36# check for branch name
37[ "${TRAVIS_BRANCH}" = "master" ] || \
38 skip "Running Doxygen only for updates on 'master' branch (current: ${TRAVIS_BRANCH})."
39
40# check for job number
41[ "${TRAVIS_JOB_NUMBER}" = "${TRAVIS_BUILD_NUMBER}.1" ] || \
42 skip "Running Doxygen only on first job of build ${TRAVIS_BUILD_NUMBER} (current: ${TRAVIS_JOB_NUMBER})."
43
44# install doxygen binary distribution
45doxygen_install()
46{
47 wget -O - "${DOXYGEN_URL}" | \
48 tar xz -C ${TMPDIR-/tmp} ${DOXYGEN_VER}/bin/doxygen
49 $SUDO install -m 755 ${TMPDIR-/tmp}/${DOXYGEN_VER}/bin/doxygen \
50 ${DOXYGEN_BIN};
51}
52
53doxygen_run()
54{
55 cd "${TRAVIS_BUILD_DIR}";
56 doxygen build/Doxyfile;
57}
58
59gh_pages_prepare()
60{
61 cd "${TRAVIS_BUILD_DIR}/doc";
62 [ ! -d "html" ] || \
63 abort "Doxygen target directory already exists."
Philipp A. Hartmann72d0d422014-07-09 18:24:13 +020064 git clone --single-branch -b gh-pages ${GHPAGES_URL} html
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020065 cd html
Philipp A. Hartmannb3665602014-07-09 08:01:25 +020066 # setup git config (with defaults)
Milo Yip62250922014-07-12 18:42:26 +080067 git config --global user.name "${GIT_NAME-travis}"
68 git config --global user.email "${GIT_EMAIL-"travis@localhost"}"
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020069 # clean working dir
70 rm -f .git/index
71 git clean -df
72}
73
74gh_pages_commit() {
75 cd "${TRAVIS_BUILD_DIR}/doc/html";
76 git add --all;
Philipp A. Hartmannb3665602014-07-09 08:01:25 +020077 git diff-index --quiet HEAD || git commit -m "Automatic doxygen build";
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020078}
79
80gh_pages_push() {
81 # check for secure variables
82 [ "${TRAVIS_SECURE_ENV_VARS}" = "true" ] || \
83 skip "Secure variables not available, not updating GitHub pages."
Philipp A. Hartmann5050f182014-07-11 13:19:45 +020084 # check for GitHub access token
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020085 [ "${GH_TOKEN+set}" = set ] || \
86 skip "GitHub access token not available, not updating GitHub pages."
Philipp A. Hartmann5050f182014-07-11 13:19:45 +020087 [ "${#GH_TOKEN}" -eq 40 ] || \
88 abort "GitHub token invalid: found ${#GH_TOKEN} characters, expected 40."
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020089
90 cd "${TRAVIS_BUILD_DIR}/doc/html";
Philipp A. Hartmann72d0d422014-07-09 18:24:13 +020091 # setup credentials (hide in "set -x" mode)
92 git config core.askpass /bin/true
93 ( set +x ; git config credential.${GHPAGES_URL}.username "${GH_TOKEN}" )
94 # push to GitHub
Philipp A. Hartmann33da6612014-07-11 13:29:50 +020095 git push origin gh-pages || \
96 skip "GitHub pages update failed, temporarily ignored."
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020097}
98
99doxygen_install
100gh_pages_prepare
101doxygen_run
102gh_pages_commit
103gh_pages_push
104