generateDocumentationAndDeploy.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/bin/sh
  2. ################################################################################
  3. # Title : generateDocumentationAndDeploy.sh
  4. # Date created : 2016/12/09
  5. # Notes :
  6. __AUTHOR__="Martin Melik-Merkumians"
  7. # Preconditions:
  8. # - Packages doxygen doxygen-doc doxygen-latex doxygen-gui graphviz
  9. # must be installed.
  10. # - Doxygen configuration file must have the destination directory empty and
  11. # source code directory with a $(TRAVIS_BUILD_DIR) prefix.
  12. # - An gh-pages branch should already exist. See below for mor info on hoe to
  13. # create a gh-pages branch.
  14. #
  15. # Required global variables:
  16. # - TRAVIS_BUILD_NUMBER : The number of the current build.
  17. # - TRAVIS_COMMIT : The commit that the current build is testing.
  18. # - DOXYFILE : The Doxygen configuration file.
  19. # - GH_REPO_NAME : The name of the repository.
  20. # - GH_REPO_REF : The GitHub reference to the repository.
  21. # - GH_REPO_TOKEN : Secure token to the github repository.
  22. #
  23. # For information on how to encrypt variables for Travis CI please go to
  24. # https://docs.travis-ci.com/user/environment-variables/#Encrypted-Variables
  25. # or https://gist.github.com/vidavidorra/7ed6166a46c537d3cbd2
  26. # For information on how to create a clean gh-pages branch from the master
  27. # branch, please go to https://gist.github.com/vidavidorra/846a2fc7dd51f4fe56a0
  28. #
  29. # This script will generate Doxygen documentation and push the documentation to
  30. # the gh-pages branch of a repository specified by GH_REPO_REF.
  31. # Before this script is used there should already be a gh-pages branch in the
  32. # repository.
  33. #
  34. ################################################################################
  35. ################################################################################
  36. ##### Setup this script and get the current gh-pages branch. #####
  37. echo 'Setting up the script...'
  38. # Exit with nonzero exit code if anything fails
  39. set -e
  40. # Create a clean working directory for this script.
  41. mkdir code_docs
  42. cd code_docs
  43. # Get the current gh-pages branch
  44. git clone -b gh-pages https://git@$GH_REPO_REF
  45. cd $GH_REPO_NAME
  46. ##### Configure git.
  47. # Set the push default to simple i.e. push only the current branch.
  48. git config --global push.default simple
  49. # Pretend to be an user called Travis CI.
  50. git config user.name "Travis CI"
  51. git config user.email "travis@eipstackgroup.org"
  52. # Remove everything currently in the gh-pages branch.
  53. # GitHub is smart enough to know which files have changed and which files have
  54. # stayed the same and will only update the changed files. So the gh-pages branch
  55. # can be safely cleaned, and it is sure that everything pushed later is the new
  56. # documentation.
  57. rm -rf *
  58. # Need to create a .nojekyll file to allow filenames starting with an underscore
  59. # to be seen on the gh-pages site. Therefore creating an empty .nojekyll file.
  60. # Presumably this is only needed when the SHORT_NAMES option in Doxygen is set
  61. # to NO, which it is by default. So creating the file just in case.
  62. echo "" > .nojekyll
  63. cd ../..
  64. ################################################################################
  65. ##### Generate the Doxygen code documentation and log the output. #####
  66. echo 'Generating Doxygen code documentation...'
  67. # Redirect both stderr and stdout to the log file AND the console.
  68. doxygen $DOXYFILE 2>&1 | tee doxygen.log
  69. cp -r doc/api_doc/html/* code_docs/$GH_REPO_NAME
  70. cd code_docs/$GH_REPO_NAME
  71. ################################################################################
  72. ##### Upload the documentation to the gh-pages branch of the repository. #####
  73. # Only upload if Doxygen successfully created the documentation.
  74. # Check this by verifying that the html directory and the file html/index.html
  75. # both exist. This is a good indication that Doxygen did it's work.
  76. if [ -f "index.html" ]; then
  77. echo 'Uploading documentation to the gh-pages branch...'
  78. # Add everything in this directory (the Doxygen code documentation) to the
  79. # gh-pages branch.
  80. # GitHub is smart enough to know which files have changed and which files have
  81. # stayed the same and will only update the changed files.
  82. git add --all .
  83. # Commit the added files with a title and description containing the Travis CI
  84. # build number and the GitHub commit reference that issued this build.
  85. git commit -m "Deploy code docs to GitHub Pages Travis build: ${TRAVIS_BUILD_NUMBER}" -m "Commit: ${TRAVIS_COMMIT}"
  86. # Force push to the remote gh-pages branch.
  87. # The ouput is redirected to /dev/null to hide any sensitive credential data
  88. # that might otherwise be exposed.
  89. git push --force "https://${GH_REPO_TOKEN}@${GH_REPO_REF}" HEAD:gh-pages > /dev/null 2>&1
  90. else
  91. echo '' >&2
  92. echo 'Warning: No documentation (html) files have been found!' >&2
  93. echo 'Warning: Not going to push the documentation to GitHub!' >&2
  94. exit 1
  95. fi