Philipp A. Hartmann | 7c7eb1c | 2014-07-08 18:55:55 +0200 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # Update Doxygen documentation after push to 'master'. |
| 3 | # Author: @pah |
| 4 | |
| 5 | set -e |
| 6 | |
| 7 | SUDO=sudo |
| 8 | DOXYGEN_VER=doxygen-1.8.7 |
| 9 | DOXYGEN_TAR=${DOXYGEN_VER}.linux.bin.tar.gz |
| 10 | DOXYGEN_URL="http://ftp.stack.nl/pub/users/dimitri/${DOXYGEN_TAR}" |
| 11 | DOXYGEN_BIN="/usr/local/bin/doxygen" |
| 12 | |
| 13 | GHPAGES_REPO="miloyip/rapidjson" |
| 14 | GHPAGES_BASE="https://github.com/${GHPAGES_REPO}" |
| 15 | # NOTE: not expanded here to hide GH_TOKEN |
| 16 | GHPAGES_PUSH='https://${GH_TOKEN}@github.com/${GHPAGES_REPO}' |
| 17 | |
| 18 | skip() { |
| 19 | echo "$@" 1>&2 |
| 20 | echo "Exiting..." 1>&2 |
| 21 | exit 0 |
| 22 | } |
| 23 | |
| 24 | abort() { |
| 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 |
| 47 | doxygen_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 | |
| 55 | doxygen_run() |
| 56 | { |
| 57 | cd "${TRAVIS_BUILD_DIR}"; |
| 58 | doxygen build/Doxyfile; |
| 59 | } |
| 60 | |
| 61 | gh_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 | |
| 73 | gh_pages_commit() { |
| 74 | cd "${TRAVIS_BUILD_DIR}/doc/html"; |
| 75 | git add --all; |
| 76 | git commit -m "Automatic doxygen build"; |
| 77 | } |
| 78 | |
| 79 | gh_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 | |
| 92 | doxygen_install |
| 93 | gh_pages_prepare |
| 94 | doxygen_run |
| 95 | gh_pages_commit |
| 96 | gh_pages_push |
| 97 | |