Blame doc/ghdeploydoxy.sh

Packit 38d9dc
#!/bin/bash
Packit 38d9dc
################################################################################
Packit 38d9dc
# Notes         :
Packit 38d9dc
# Preconditions:
Packit 38d9dc
# - Packages doxygen doxygen-doc doxygen-latex doxygen-gui graphviz
Packit 38d9dc
#   must be installed.
Packit 38d9dc
# - Doxygen configuration file must have the destination directory empty and
Packit 38d9dc
#   source code directory.
Packit 38d9dc
# - A gh-pages branch should already exist.
Packit 38d9dc
#
Packit 38d9dc
# Required global variables:
Packit 38d9dc
# - DOXYFILE            : The Doxygen configuration file.
Packit 38d9dc
# - GH_REPO_NAME        : The name of the repository.
Packit 38d9dc
# - GH_REPO_REF         : The GitHub reference to the repository.
Packit 38d9dc
# - GH_REPO_TOKEN       : The GitHub application token.
Packit 38d9dc
#
Packit 38d9dc
# This script will generate Doxygen documentation and push the documentation to
Packit 38d9dc
# the gh-pages branch of a repository specified by GH_REPO_REF.
Packit 38d9dc
# Before this script is used there should already be a gh-pages branch in the
Packit 38d9dc
# repository.
Packit 38d9dc
#
Packit 38d9dc
################################################################################
Packit 38d9dc
Packit 38d9dc
################################################################################
Packit 38d9dc
##### Setup this script and get the current gh-pages branch.               #####
Packit 38d9dc
echo 'Setting up the script...'
Packit 38d9dc
# Exit with nonzero exit code if anything fails
Packit 38d9dc
set -e
Packit 38d9dc
Packit 38d9dc
GH_REPO_NAME=
Packit 38d9dc
GH_REPO_REF=
Packit 38d9dc
GH_REPO_TOKEN=
Packit 38d9dc
Packit 38d9dc
usage() { echo "Usage: `basename $0` options (-n value) (-r value) (-t value)" 1>&2; exit 1; }
Packit 38d9dc
Packit 38d9dc
if ( ! getopts ":n:r:t:" opt); then
Packit 38d9dc
      usage
Packit 38d9dc
fi
Packit 38d9dc
Packit 38d9dc
while getopts :n:r:t: opt; do
Packit 38d9dc
  case $opt in
Packit 38d9dc
  n)
Packit 38d9dc
      GH_REPO_NAME=$OPTARG
Packit 38d9dc
      ;;
Packit 38d9dc
  r)
Packit 38d9dc
      GH_REPO_REF=$OPTARG
Packit 38d9dc
      ;;
Packit 38d9dc
  t)
Packit 38d9dc
      GH_REPO_TOKEN=$OPTARG
Packit 38d9dc
      ;;
Packit 38d9dc
  *)
Packit 38d9dc
      usage
Packit 38d9dc
      ;;
Packit 38d9dc
  esac
Packit 38d9dc
done
Packit 38d9dc
Packit 38d9dc
shift $((OPTIND - 1))
Packit 38d9dc
Packit 38d9dc
[ -n "$GH_REPO_NAME" ] || {
Packit 38d9dc
    echo "ERROR: -n GH_REPO_NAME is not defined" >/dev/stderr
Packit 38d9dc
    exit 1
Packit 38d9dc
}
Packit 38d9dc
Packit 38d9dc
[ -n "$GH_REPO_REF" ] || {
Packit 38d9dc
    echo "ERROR: -r GH_REPO_REF is not defined" >/dev/stderr
Packit 38d9dc
    exit 1
Packit 38d9dc
}
Packit 38d9dc
Packit 38d9dc
[ -n "$GH_REPO_TOKEN" ] || {
Packit 38d9dc
    echo "ERROR: -t GH_REPO_TOKEN is not defined" >/dev/stderr
Packit 38d9dc
    exit 1
Packit 38d9dc
}
Packit 38d9dc
Packit 38d9dc
################################################################################
Packit 38d9dc
##### Upload the documentation to the gh-pages branch of the repository.   #####
Packit 38d9dc
# Only upload if Doxygen successfully created the documentation.
Packit 38d9dc
# Check this by verifying that the html directory and the file html/index.html
Packit 38d9dc
# both exist. This is a good indication that Doxygen did it's work.
Packit 38d9dc
if [ -d "html-out" ] && [ -f "html-out/index.html" ]; then
Packit 38d9dc
Packit 38d9dc
    # Create a clean working directory for this script.
Packit 38d9dc
    mkdir code_docs
Packit 38d9dc
    cd code_docs
Packit 38d9dc
Packit 38d9dc
    # Get the current gh-pages branch
Packit 38d9dc
    git clone -b gh-pages https://git@$GH_REPO_REF
Packit 38d9dc
    cd $GH_REPO_NAME
Packit 38d9dc
Packit 38d9dc
    ##### Configure git.
Packit 38d9dc
    # Set the push default to simple i.e. push only the current branch.
Packit 38d9dc
    git config --global push.default simple
Packit 38d9dc
Packit 38d9dc
    # Remove everything currently in the gh-pages branch.
Packit 38d9dc
    # GitHub is smart enough to know which files have changed and which files have
Packit 38d9dc
    # stayed the same and will only update the changed files. So the gh-pages branch
Packit 38d9dc
    # can be safely cleaned, and it is sure that everything pushed later is the new
Packit 38d9dc
    # documentation.
Packit 38d9dc
    CURRENTCOMMIT=`git rev-parse HEAD`
Packit 38d9dc
    git reset --hard `git rev-list HEAD | tail -n 1` # Reset working tree to initial commit
Packit 38d9dc
    git reset --soft $CURRENTCOMMIT # Move HEAD back to where it was
Packit 38d9dc
Packit 38d9dc
    # Move doxy files into local gh-pages branch folder
Packit 38d9dc
    mv ../../html-out/* .
Packit 38d9dc
Packit 38d9dc
    # Need to create a .nojekyll file to allow filenames starting with an underscore
Packit 38d9dc
    # to be seen on the gh-pages site. Therefore creating an empty .nojekyll file.
Packit 38d9dc
    # Presumably this is only needed when the SHORT_NAMES option in Doxygen is set
Packit 38d9dc
    # to NO, which it is by default. So creating the file just in case.
Packit 38d9dc
    echo "" > .nojekyll
Packit 38d9dc
Packit 38d9dc
    echo 'Uploading documentation to the gh-pages branch...'
Packit 38d9dc
    # Add everything in this directory (the Doxygen code documentation) to the
Packit 38d9dc
    # gh-pages branch.
Packit 38d9dc
    # GitHub is smart enough to know which files have changed and which files have
Packit 38d9dc
    # stayed the same and will only update the changed files.
Packit 38d9dc
    git add --all
Packit 38d9dc
Packit 38d9dc
    # Commit the added files with a title and description containing the Travis CI
Packit 38d9dc
    # build number and the GitHub commit reference that issued this build.
Packit 38d9dc
    git commit -m "Deploy code docs to GitHub Pages"
Packit 38d9dc
Packit 38d9dc
    # Force push to the remote gh-pages branch.
Packit 38d9dc
    # The ouput is redirected to /dev/null to hide any sensitive credential data
Packit 38d9dc
    # that might otherwise be exposed.
Packit 38d9dc
    git push --force "https://${GH_REPO_TOKEN}@${GH_REPO_REF}" > /dev/null 2>&1
Packit 38d9dc
else
Packit 38d9dc
    echo '' >&2
Packit 38d9dc
    echo 'Warning: No documentation (html) files have been found!' >&2
Packit 38d9dc
    echo 'Warning: Not going to push the documentation to GitHub!' >&2
Packit 38d9dc
    exit 1
Packit 38d9dc
fi