travis-doxygen.sh 3.2 KB

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