blob: a7586297fe8d6fa5b09023b604ca14d5a8919bf2 [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
Philipp A. Hartmannc1afdc82014-07-12 19:56:30 +020013: ${GITHUB_REPO:="miloyip/rapidjson"}
Philipp A. Hartmann03834b52014-07-13 11:48:37 +020014GITHUB_HOST="github.com"
15GITHUB_CLONE="git://${GITHUB_HOST}/${GITHUB_REPO}"
16GITHUB_URL="https://${GITHUB_HOST}/${GITHUB_PUSH-${GITHUB_REPO}}"
Philipp A. Hartmann4dafa2a2014-07-12 20:47:55 +020017
18# if not set, ignore password
Philipp A. Hartmann03834b52014-07-13 11:48:37 +020019#GIT_ASKPASS="${TRAVIS_BUILD_DIR}/gh_ignore_askpass.sh"
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020020
21skip() {
22 echo "$@" 1>&2
23 echo "Exiting..." 1>&2
24 exit 0
25}
26
27abort() {
28 echo "Error: $@" 1>&2
29 echo "Exiting..." 1>&2
30 exit 1
31}
32
33# TRAVIS_BUILD_DIR not set, exiting
34[ -d "${TRAVIS_BUILD_DIR-/nonexistent}" ] || \
35 abort '${TRAVIS_BUILD_DIR} not set or nonexistent.'
36
37# check for pull-requests
38[ "${TRAVIS_PULL_REQUEST}" = "false" ] || \
39 skip "Not running Doxygen for pull-requests."
40
41# check for branch name
42[ "${TRAVIS_BRANCH}" = "master" ] || \
43 skip "Running Doxygen only for updates on 'master' branch (current: ${TRAVIS_BRANCH})."
44
45# check for job number
46[ "${TRAVIS_JOB_NUMBER}" = "${TRAVIS_BUILD_NUMBER}.1" ] || \
47 skip "Running Doxygen only on first job of build ${TRAVIS_BUILD_NUMBER} (current: ${TRAVIS_JOB_NUMBER})."
48
49# install doxygen binary distribution
50doxygen_install()
51{
52 wget -O - "${DOXYGEN_URL}" | \
53 tar xz -C ${TMPDIR-/tmp} ${DOXYGEN_VER}/bin/doxygen
54 $SUDO install -m 755 ${TMPDIR-/tmp}/${DOXYGEN_VER}/bin/doxygen \
55 ${DOXYGEN_BIN};
56}
57
58doxygen_run()
59{
Andriy Senkovych40c03112014-11-12 01:57:25 +020060 cd "${TRAVIS_BUILD_DIR}/build/doc";
61 doxygen Doxyfile;
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020062}
63
64gh_pages_prepare()
65{
Andriy Senkovych40c03112014-11-12 01:57:25 +020066 cd "${TRAVIS_BUILD_DIR}/build/doc";
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020067 [ ! -d "html" ] || \
68 abort "Doxygen target directory already exists."
Philipp A. Hartmann4dafa2a2014-07-12 20:47:55 +020069 git --version
Philipp A. Hartmann03834b52014-07-13 11:48:37 +020070 git clone --single-branch -b gh-pages "${GITHUB_CLONE}" html
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020071 cd html
Philipp A. Hartmannb3665602014-07-09 08:01:25 +020072 # setup git config (with defaults)
Philipp A. Hartmann2875b572014-07-12 19:02:56 +020073 git config user.name "${GIT_NAME-travis}"
74 git config user.email "${GIT_EMAIL-"travis@localhost"}"
Philipp A. Hartmann7c7eb1c2014-07-08 18:55:55 +020075 # clean working dir
76 rm -f .git/index
77 git clean -df
78}
79
80gh_pages_commit() {
Andriy Senkovych40c03112014-11-12 01:57:25 +020081 cd "${TRAVIS_BUILD_DIR}/build/doc/html";
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