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 | |
Philipp A. Hartmann | c1afdc8 | 2014-07-12 19:56:30 +0200 | [diff] [blame] | 13 | : ${GITHUB_REPO:="miloyip/rapidjson"} |
Philipp A. Hartmann | 03834b5 | 2014-07-13 11:48:37 +0200 | [diff] [blame^] | 14 | GITHUB_HOST="github.com" |
| 15 | GITHUB_CLONE="git://${GITHUB_HOST}/${GITHUB_REPO}" |
| 16 | GITHUB_URL="https://${GITHUB_HOST}/${GITHUB_PUSH-${GITHUB_REPO}}" |
Philipp A. Hartmann | 4dafa2a | 2014-07-12 20:47:55 +0200 | [diff] [blame] | 17 | |
| 18 | # if not set, ignore password |
Philipp A. Hartmann | 03834b5 | 2014-07-13 11:48:37 +0200 | [diff] [blame^] | 19 | #GIT_ASKPASS="${TRAVIS_BUILD_DIR}/gh_ignore_askpass.sh" |
Philipp A. Hartmann | 7c7eb1c | 2014-07-08 18:55:55 +0200 | [diff] [blame] | 20 | |
| 21 | skip() { |
| 22 | echo "$@" 1>&2 |
| 23 | echo "Exiting..." 1>&2 |
| 24 | exit 0 |
| 25 | } |
| 26 | |
| 27 | abort() { |
| 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 |
| 50 | doxygen_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 | |
| 58 | doxygen_run() |
| 59 | { |
| 60 | cd "${TRAVIS_BUILD_DIR}"; |
| 61 | doxygen build/Doxyfile; |
| 62 | } |
| 63 | |
| 64 | gh_pages_prepare() |
| 65 | { |
| 66 | cd "${TRAVIS_BUILD_DIR}/doc"; |
| 67 | [ ! -d "html" ] || \ |
| 68 | abort "Doxygen target directory already exists." |
Philipp A. Hartmann | 4dafa2a | 2014-07-12 20:47:55 +0200 | [diff] [blame] | 69 | git --version |
Philipp A. Hartmann | 03834b5 | 2014-07-13 11:48:37 +0200 | [diff] [blame^] | 70 | git clone --single-branch -b gh-pages "${GITHUB_CLONE}" html |
Philipp A. Hartmann | 7c7eb1c | 2014-07-08 18:55:55 +0200 | [diff] [blame] | 71 | cd html |
Philipp A. Hartmann | b366560 | 2014-07-09 08:01:25 +0200 | [diff] [blame] | 72 | # setup git config (with defaults) |
Philipp A. Hartmann | 2875b57 | 2014-07-12 19:02:56 +0200 | [diff] [blame] | 73 | git config user.name "${GIT_NAME-travis}" |
| 74 | git config user.email "${GIT_EMAIL-"travis@localhost"}" |
Philipp A. Hartmann | 7c7eb1c | 2014-07-08 18:55:55 +0200 | [diff] [blame] | 75 | # clean working dir |
| 76 | rm -f .git/index |
| 77 | git clean -df |
| 78 | } |
| 79 | |
| 80 | gh_pages_commit() { |
| 81 | cd "${TRAVIS_BUILD_DIR}/doc/html"; |
| 82 | git add --all; |
Philipp A. Hartmann | b366560 | 2014-07-09 08:01:25 +0200 | [diff] [blame] | 83 | git diff-index --quiet HEAD || git commit -m "Automatic doxygen build"; |
Philipp A. Hartmann | 7c7eb1c | 2014-07-08 18:55:55 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Philipp A. Hartmann | 4dafa2a | 2014-07-12 20:47:55 +0200 | [diff] [blame] | 86 | gh_setup_askpass() { |
| 87 | cat > ${GIT_ASKPASS} <<EOF |
| 88 | #!/bin/bash |
| 89 | echo |
| 90 | exit 0 |
| 91 | EOF |
| 92 | chmod a+x "$GIT_ASKPASS" |
| 93 | } |
| 94 | |
Philipp A. Hartmann | 7c7eb1c | 2014-07-08 18:55:55 +0200 | [diff] [blame] | 95 | gh_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. Hartmann | 5050f18 | 2014-07-11 13:19:45 +0200 | [diff] [blame] | 99 | # check for GitHub access token |
Philipp A. Hartmann | 7c7eb1c | 2014-07-08 18:55:55 +0200 | [diff] [blame] | 100 | [ "${GH_TOKEN+set}" = set ] || \ |
| 101 | skip "GitHub access token not available, not updating GitHub pages." |
Philipp A. Hartmann | 5050f18 | 2014-07-11 13:19:45 +0200 | [diff] [blame] | 102 | [ "${#GH_TOKEN}" -eq 40 ] || \ |
| 103 | abort "GitHub token invalid: found ${#GH_TOKEN} characters, expected 40." |
Philipp A. Hartmann | 7c7eb1c | 2014-07-08 18:55:55 +0200 | [diff] [blame] | 104 | |
| 105 | cd "${TRAVIS_BUILD_DIR}/doc/html"; |
Philipp A. Hartmann | 72d0d42 | 2014-07-09 18:24:13 +0200 | [diff] [blame] | 106 | # setup credentials (hide in "set -x" mode) |
Philipp A. Hartmann | 4dafa2a | 2014-07-12 20:47:55 +0200 | [diff] [blame] | 107 | git remote set-url --push origin "${GITHUB_URL}" |
Philipp A. Hartmann | 4dafa2a | 2014-07-12 20:47:55 +0200 | [diff] [blame] | 108 | git config credential.helper 'store' |
Philipp A. Hartmann | 03834b5 | 2014-07-13 11:48:37 +0200 | [diff] [blame^] | 109 | # ( set +x ; git config credential.username "${GH_TOKEN}" ) |
| 110 | ( set +x ; \ |
| 111 | echo "https://${GH_TOKEN}:@${GITHUB_HOST}" > ${HOME}/.git-credentials ; \ |
| 112 | chmod go-rw ${HOME}/.git-credentials ) |
Philipp A. Hartmann | 72d0d42 | 2014-07-09 18:24:13 +0200 | [diff] [blame] | 113 | # push to GitHub |
Philipp A. Hartmann | 33da661 | 2014-07-11 13:29:50 +0200 | [diff] [blame] | 114 | git push origin gh-pages || \ |
| 115 | skip "GitHub pages update failed, temporarily ignored." |
Philipp A. Hartmann | 7c7eb1c | 2014-07-08 18:55:55 +0200 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | doxygen_install |
| 119 | gh_pages_prepare |
| 120 | doxygen_run |
| 121 | gh_pages_commit |
| 122 | gh_pages_push |
| 123 | |