#!/bin/bash -e

# thanks to http://blog.gockelhut.com/2014/09/automatic-documentation-publishing-with.html

# Settings
REPO_PATH=https://github.com/MetaluNet/Fraise-doc.git
HTML_PATH=html
COMMIT_USER="Documentation Builder"
COMMIT_EMAIL="_antoine_@metalu.net"
CHANGESET=$(git rev-parse --verify HEAD)

# Get a clean version of the HTML documentation repo.
rm -rf ${HTML_PATH}
mkdir -p ${HTML_PATH}
git clone -b gh-pages "${REPO_PATH}" ${HTML_PATH}

# rm all the files through git to prevent stale files.
cd ${HTML_PATH}
if [ `git config remote.origin.url` != ${REPO_PATH} ] ; then cd -; echo "ERROR cloning ${REPO_PATH} !" ;exit ; fi
git rm -rf .
cd -

# Generate the HTML documentation.
doxygen

# Create and commit the documentation repo.
cd ${HTML_PATH}
git add .
git config user.name "${COMMIT_USER}"
git config user.email "${COMMIT_EMAIL}"
git commit -m "Automated documentation build for changeset ${CHANGESET}."
echo Pushing to `git config remote.origin.url`
git push origin gh-pages
cd -