blob: c63d7830ae5028bed42413cf31f260203f5c6b2b [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)
67 git config user.name "${GIT_NAME-travis}"
68 git config 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."
84 [ "${GH_TOKEN+set}" = set ] || \
85 skip "GitHub access token not available, not updating GitHub pages."
86
87 cd "${TRAVIS_BUILD_DIR}/doc/html";
Philipp A. Hartmann72d0d422014-07-09 18:24:13 +020088 # setup credentials (hide in "set -x" mode)
89 git config core.askpass /bin/true
90 ( set +x ; git config credential.${GHPAGES_URL}.username "${GH_TOKEN}" )
91 # push to GitHub
92 git push origin gh-pages
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020093}
94
95doxygen_install
96gh_pages_prepare
97doxygen_run
98gh_pages_commit
99gh_pages_push
100