zrepl/docs/publish.sh

56 lines
1.2 KiB
Bash
Raw Normal View History

2017-08-09 16:13:12 +02:00
#!/bin/bash
set -eo pipefail
GHPAGESREPO="git@github.com:zrepl/zrepl.github.io.git"
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
2017-08-09 22:05:29 +02:00
PUBLICDIR="${SCRIPTDIR}/public_git" #use different dir than default dir 'public' (hugo server -D)
checkout_repo_msg() {
echo "checkout ${GHPAGESREPO} to ${PUBLICDIR}:"
echo " git clone ${GHPAGESREPO} ${PUBLICDIR}"
}
2017-08-09 16:13:12 +02:00
exit_msg() {
echo "error, exiting..."
}
trap exit_msg EXIT
cd "$SCRIPTDIR"
if [ ! -d "$PUBLICDIR" ]; then
checkout_repo_msg
exit 1
fi
2017-08-09 16:13:12 +02:00
echo -n "PRESS ENTER to confirm you commited the docs changes to the zrepl repo"
read
pushd "$PUBLICDIR"
2017-08-09 16:13:12 +02:00
echo "verify we're in the GitHub pages repo..."
git remote get-url origin | grep -E "^${GHPAGESREPO}\$"
if [ "$?" -ne "0" ] ;then
checkout_repo_msg
exit 1
fi
echo "resetting GitHub pages repo to latest commit"
git fetch origin
git reset --hard origin/master
2017-08-09 16:13:12 +02:00
echo "cleaning GitHub pages repo"
2017-08-09 22:05:29 +02:00
git rm -rf .
popd
2017-08-09 16:13:12 +02:00
echo "building site"
2017-08-09 22:05:29 +02:00
hugo -d "$PUBLICDIR"
pushd "$PUBLICDIR"
2017-08-09 16:13:12 +02:00
echo "adding and commiting all changes in GitHub pages repo"
git add -A
2017-08-09 22:05:29 +02:00
git commit -m "hugo render from publish.sh - `date -u`" #TODO include parent commit id
2017-08-09 16:13:12 +02:00
git push origin master