|
| 1 | +#!/bin/sh |
| 2 | +################################################################################ |
| 3 | +# Title : generate_gh_pages.sh |
| 4 | +# Date created : 2016/02/22 |
| 5 | +# Notes : |
| 6 | +__AUTHOR__="openpose" |
| 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 | +################################################################################ |
| 37 | +##### Setup this script and get the current gh-pages branch. ##### |
| 38 | +echo 'Setting up the script...' |
| 39 | +# Exit with nonzero exit code if anything fails |
| 40 | +set -e |
| 41 | + |
| 42 | +# Create a clean working directory for this script. |
| 43 | +mkdir code_docs |
| 44 | +cd code_docs |
| 45 | + |
| 46 | +# Get the current gh-pages branch |
| 47 | +git clone -b gh-pages https://git@$GH_REPO_REF |
| 48 | +cd $GH_REPO_NAME |
| 49 | + |
| 50 | +##### Configure git. |
| 51 | +# Set the push default to simple i.e. push only the current branch. |
| 52 | +git config --global push.default simple |
| 53 | +# Pretend to be an user called Travis CI. |
| 54 | +git config user.name "Travis CI" |
| 55 | +git config user.email "[email protected]" |
| 56 | + |
| 57 | +# Remove everything currently in the gh-pages branch. |
| 58 | +# GitHub is smart enough to know which files have changed and which files have |
| 59 | +# stayed the same and will only update the changed files. So the gh-pages branch |
| 60 | +# can be safely cleaned, and it is sure that everything pushed later is the new |
| 61 | +# documentation. |
| 62 | +rm -rf * |
| 63 | + |
| 64 | +# Need to create a .nojekyll file to allow filenames starting with an underscore |
| 65 | +# to be seen on the gh-pages site. Therefore creating an empty .nojekyll file. |
| 66 | +# Presumably this is only needed when the SHORT_NAMES option in Doxygen is set |
| 67 | +# to NO, which it is by default. So creating the file just in case. |
| 68 | +echo "" > .nojekyll |
| 69 | + |
| 70 | +################################################################################ |
| 71 | +##### Generate the Doxygen code documentation and log the output. ##### |
| 72 | +echo 'Generating Doxygen code documentation...' |
| 73 | +# Redirect both stderr and stdout to the log file AND the console. |
| 74 | +echo "INPUT = ${TRAVIS_BUILD_DIR}/README.md ${TRAVIS_BUILD_DIR}/include/openpose/" >> $DOXYFILE |
| 75 | +echo "USE_MDFILE_AS_MAINPAGE = ${TRAVIS_BUILD_DIR}/README.md" >> $DOXYFILE |
| 76 | +echo "OUTPUT_DIRECTORY = " >> $DOXYFILE |
| 77 | +doxygen $DOXYFILE 2>&1 | tee doxygen.log |
| 78 | + |
| 79 | +################################################################################ |
| 80 | +##### Upload the documentation to the gh-pages branch of the repository. ##### |
| 81 | +# Only upload if Doxygen successfully created the documentation. |
| 82 | +# Check this by verifying that the html directory and the file html/index.html |
| 83 | +# both exist. This is a good indication that Doxygen did it's work. |
| 84 | +if [ -d "html" ] && [ -f "html/index.html" ]; then |
| 85 | + |
| 86 | + echo 'Uploading documentation to the gh-pages branch...' |
| 87 | + # Add everything in this directory (the Doxygen code documentation) to the |
| 88 | + # gh-pages branch. |
| 89 | + # GitHub is smart enough to know which files have changed and which files have |
| 90 | + # stayed the same and will only update the changed files. |
| 91 | + git add --all |
| 92 | + |
| 93 | + # Commit the added files with a title and description containing the Travis CI |
| 94 | + # build number and the GitHub commit reference that issued this build. |
| 95 | + git commit -m "Deploy code docs to GitHub Pages Travis build: ${TRAVIS_BUILD_NUMBER}" -m "Commit: ${TRAVIS_COMMIT}" |
| 96 | + |
| 97 | + # Force push to the remote gh-pages branch. |
| 98 | + # The ouput is redirected to /dev/null to hide any sensitive credential data |
| 99 | + # that might otherwise be exposed. |
| 100 | + git push --force "https://${GH_REPO_TOKEN}@${GH_REPO_REF}" > /dev/null 2>&1 |
| 101 | +else |
| 102 | + echo '' >&2 |
| 103 | + echo 'Warning: No documentation (html) files have been found!' >&2 |
| 104 | + echo 'Warning: Not going to push the documentation to GitHub!' >&2 |
| 105 | + exit 1 |
| 106 | +fi |
0 commit comments