travis-doxygen.sh 3.2 KB

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