#!/bin/bash
#
# Deploy documentation to Github Pages
#
# Run from project root
#
# @author Natesh Narain
#

export BRANCH=$1
export API_TOKEN=$2

# only deploy on master branch commit
if [[ "$BRANCH" != "develop" ]]; then
	exit 0
fi

# clone into what is going to be the docs output directory
git clone --branch=gh-pages https://github.com/nnarain/gameboycore.git docs/html

# remove all content of the repo
cd docs/html
git rm -rf .
cd ../..

# build the docs in the cloned directory
cd build
make docs
cd ..

cd docs/html

# checkin the output
git config user.name "Natesh Narain"
git config user.email nnaraindev@gmail.com
git add . --all
git commit -am "Documentation"

# push
git push -f -q https://nnarain:$API_TOKEN@github.com/nnarain/gameboycore.git gh-pages

cd ../..

#---
echo "Have a nice day"
#---
