#!/bin/sh

# This script builds and publishes pages

set -e

echo CHECKING REPO

set +e
git remote | grep gh-pages

if [ "$?" != 0 ]
then
	echo 'Remote `gh-pages` not found!'
	echo 'Create a `gh-pages` remote in this repo'
	echo 'with ssh url that has write access to `gh-pages` branch. '
fi
set -e


echo ACTIVATING VENV
. /venv3.13/bin/activate

echo BUILDING DOCS
./scripts/GenerateDocs.py 

echo SAVING ARTIFACT
cp -r --reflink=auto ./docs "$MINICYCLE_ARTIFACTS/pages"

echo ADDING PAGES TO GIT
git reset --hard
git branch gh-pages || true
git checkout gh-pages
rm -rf *
cp -r --reflink=auto "$MINICYCLE_ARTIFACTS/pages" ./docs
git add --all
git commit --allow-empty -m "autocommit from Mitakihara on $(date)" 
git push --set-upstream gh-pages gh-pages


