#!/bin/bash
# this script is used on hack.p6c.org as the 'doc.perl6.org' user to update
# the website.
source /home/rakudobrew/.rakudobrew-bash
# workaround for bug in rakudobrew
PATH="$PATH:/home/rakudobrew/rakudobrew/moar-2016.06/install/share/perl6/site/bin"
set -e
set -x
cd ~/doc
git fetch
before=$(git rev-parse HEAD)
git checkout origin/master
after=$(git rev-parse HEAD)
if [ "$before" = "$after" ]
then
    echo "nothing to do"
else
    LOGDIR=$HOME/doc/html/build-log
    mkdir -p "$LOGDIR"
    DATE=$(date --iso-8601=minutes)
    LOGFILE="$LOGDIR/build-$DATE.log";
    echo "Writing logs to $LOGFILE";
    exec >$LOGFILE 2>&1

    echo "Building docs for $after with " `perl6 --version`
    echo 'Cleaning out old HTML files'
    # don't clean out html/ entirely, because there are some files
    # under version control there, and because  of html/build-log/
    find html/ -name '*.html' -delete

    # if the htmlify fails, sync the build log.
    # since sync-build-log returns false, not the whole thing is synced
    time make html || ./util/sync-build-log
    ./util/sync
fi

# vim: expandtab shiftwidth=4
