travis-doxygen.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. # Update Doxygen documentation after push to 'master'.
  3. # Author: @pah
  4. set -e
  5. DOXYGEN_VER=doxygen-1.8.7
  6. DOXYGEN_TAR=${DOXYGEN_VER}.linux.bin.tar.gz
  7. DOXYGEN_URL="http://ftp.stack.nl/pub/users/dimitri/${DOXYGEN_TAR}"
  8. DOXYGEN_BIN="/usr/local/bin/doxygen"
  9. : ${GITHUB_REPO:="miloyip/rapidjson"}
  10. GITHUB_HOST="github.com"
  11. GITHUB_CLONE="git://${GITHUB_HOST}/${GITHUB_REPO}"
  12. GITHUB_URL="https://${GITHUB_HOST}/${GITHUB_PUSH-${GITHUB_REPO}}"
  13. # if not set, ignore password
  14. #GIT_ASKPASS="${TRAVIS_BUILD_DIR}/gh_ignore_askpass.sh"
  15. skip() {
  16. echo "$@" 1>&2
  17. echo "Exiting..." 1>&2
  18. exit 0
  19. }
  20. abort() {
  21. echo "Error: $@" 1>&2
  22. echo "Exiting..." 1>&2
  23. exit 1
  24. }
  25. # TRAVIS_BUILD_DIR not set, exiting
  26. [ -d "${TRAVIS_BUILD_DIR-/nonexistent}" ] || \
  27. abort '${TRAVIS_BUILD_DIR} not set or nonexistent.'
  28. # check for pull-requests
  29. [ "${TRAVIS_PULL_REQUEST}" = "false" ] || \
  30. skip "Not running Doxygen for pull-requests."
  31. # check for branch name
  32. [ "${TRAVIS_BRANCH}" = "master" ] || \
  33. skip "Running Doxygen only for updates on 'master' branch (current: ${TRAVIS_BRANCH})."
  34. # check for job number
  35. # [ "${TRAVIS_JOB_NUMBER}" = "${TRAVIS_BUILD_NUMBER}.1" ] || \
  36. # skip "Running Doxygen only on first job of build ${TRAVIS_BUILD_NUMBER} (current: ${TRAVIS_JOB_NUMBER})."
  37. # install doxygen binary distribution
  38. doxygen_install()
  39. {
  40. wget -O - "${DOXYGEN_URL}" | \
  41. tar xz -C ${TMPDIR-/tmp} ${DOXYGEN_VER}/bin/doxygen
  42. export PATH="${TMPDIR-/tmp}/${DOXYGEN_VER}/bin:$PATH"
  43. }
  44. doxygen_run()
  45. {
  46. cd "${TRAVIS_BUILD_DIR}";
  47. doxygen ${TRAVIS_BUILD_DIR}/build/doc/Doxyfile;
  48. doxygen ${TRAVIS_BUILD_DIR}/build/doc/Doxyfile.zh-cn;
  49. }
  50. gh_pages_prepare()
  51. {
  52. cd "${TRAVIS_BUILD_DIR}/build/doc";
  53. [ ! -d "html" ] || \
  54. abort "Doxygen target directory already exists."
  55. git --version
  56. git clone -b gh-pages "${GITHUB_CLONE}" html
  57. cd html
  58. # setup git config (with defaults)
  59. git config user.name "${GIT_NAME-travis}"
  60. git config user.email "${GIT_EMAIL-"travis@localhost"}"
  61. # clean working dir
  62. rm -f .git/index
  63. git clean -df
  64. }
  65. gh_pages_commit() {
  66. cd "${TRAVIS_BUILD_DIR}/build/doc/html";
  67. echo "rapidjson.org" > CNAME
  68. git add --all;
  69. git diff-index --quiet HEAD || git commit -m "Automatic doxygen build";
  70. }
  71. gh_setup_askpass() {
  72. cat > ${GIT_ASKPASS} <<EOF
  73. #!/bin/bash
  74. echo
  75. exit 0
  76. EOF
  77. chmod a+x "$GIT_ASKPASS"
  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. # check for GitHub access token
  84. [ "${GH_TOKEN+set}" = set ] || \
  85. skip "GitHub access token not available, not updating GitHub pages."
  86. [ "${#GH_TOKEN}" -eq 40 ] || \
  87. abort "GitHub token invalid: found ${#GH_TOKEN} characters, expected 40."
  88. cd "${TRAVIS_BUILD_DIR}/build/doc/html";
  89. # setup credentials (hide in "set -x" mode)
  90. git remote set-url --push origin "${GITHUB_URL}"
  91. git config credential.helper 'store'
  92. # ( set +x ; git config credential.username "${GH_TOKEN}" )
  93. ( set +x ; [ -f ${HOME}/.git-credentials ] || \
  94. ( echo "https://${GH_TOKEN}:@${GITHUB_HOST}" > ${HOME}/.git-credentials ; \
  95. chmod go-rw ${HOME}/.git-credentials ) )
  96. # push to GitHub
  97. git push origin gh-pages
  98. }
  99. doxygen_install
  100. gh_pages_prepare
  101. doxygen_run
  102. gh_pages_commit
  103. gh_pages_push