2017-11-11 23:17:17 +01:00
|
|
|
#!/bin/bash
|
2021-07-08 16:52:11 +02:00
|
|
|
set -euo pipefail
|
2020-09-12 12:28:32 +02:00
|
|
|
|
|
|
|
NON_INTERACTIVE=false
|
|
|
|
DO_CLONE=false
|
2023-09-09 12:41:06 +02:00
|
|
|
PUSH=false
|
2023-09-09 13:07:01 +02:00
|
|
|
while getopts "caP" arg; do
|
2020-09-12 12:28:32 +02:00
|
|
|
case "$arg" in
|
|
|
|
"a")
|
|
|
|
NON_INTERACTIVE=true
|
|
|
|
;;
|
|
|
|
"c")
|
|
|
|
DO_CLONE=true
|
|
|
|
;;
|
2023-09-09 12:41:06 +02:00
|
|
|
"P")
|
|
|
|
PUSH=true
|
|
|
|
;;
|
2020-09-12 12:28:32 +02:00
|
|
|
*)
|
2021-07-08 16:52:11 +02:00
|
|
|
echo "invalid option '-$arg'"
|
2020-09-12 12:28:32 +02:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2017-11-11 23:17:17 +01:00
|
|
|
GHPAGESREPO="git@github.com:zrepl/zrepl.github.io.git"
|
|
|
|
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
|
|
PUBLICDIR="${SCRIPTDIR}/public_git"
|
|
|
|
|
|
|
|
checkout_repo_msg() {
|
|
|
|
echo "clone ${GHPAGESREPO} to ${PUBLICDIR}:"
|
|
|
|
}
|
|
|
|
|
2023-09-09 12:21:25 +02:00
|
|
|
if ! type sphinx-multiversion >/dev/null; then
|
|
|
|
echo "install sphinx-multiversion and come back"
|
2017-11-18 21:16:54 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-11-11 23:17:17 +01:00
|
|
|
cd "$SCRIPTDIR"
|
|
|
|
|
|
|
|
if [ ! -d "$PUBLICDIR" ]; then
|
|
|
|
checkout_repo_msg
|
2020-09-12 12:28:32 +02:00
|
|
|
if $DO_CLONE; then
|
|
|
|
git clone "${GHPAGESREPO}" "${PUBLICDIR}"
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-11-11 23:17:17 +01:00
|
|
|
fi
|
|
|
|
|
2020-09-12 12:28:32 +02:00
|
|
|
if $NON_INTERACTIVE; then
|
|
|
|
echo "non-interactive mode"
|
|
|
|
else
|
|
|
|
echo -n "PRESS ENTER to confirm you commited and pushed docs changes and tags to the zrepl repo"
|
|
|
|
read -r
|
|
|
|
fi
|
2017-11-11 23:17:17 +01:00
|
|
|
|
2023-09-09 12:21:25 +02:00
|
|
|
pushd "$PUBLICDIR"
|
2017-11-11 23:17:17 +01:00
|
|
|
|
|
|
|
echo "verify we're in the GitHub pages repo..."
|
|
|
|
git remote get-url origin | grep -E "^${GHPAGESREPO}\$"
|
2023-09-09 12:21:25 +02:00
|
|
|
if [ "$?" -ne "0" ] ;then
|
2017-11-11 23:17:17 +01:00
|
|
|
checkout_repo_msg
|
|
|
|
echo "finished checkout, please run again"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "resetting GitHub pages repo to latest commit"
|
|
|
|
git fetch origin
|
|
|
|
git reset --hard origin/master
|
|
|
|
|
|
|
|
echo "cleaning GitHub pages repo"
|
|
|
|
git rm -rf .
|
2021-07-08 16:52:11 +02:00
|
|
|
cat > .gitignore <<EOF
|
|
|
|
**/.doctrees
|
|
|
|
EOF
|
2017-11-11 23:17:17 +01:00
|
|
|
|
|
|
|
popd
|
|
|
|
|
|
|
|
echo "building site"
|
2020-06-14 18:24:20 +02:00
|
|
|
|
2023-09-09 12:21:25 +02:00
|
|
|
python3 run-sphinx-multiversion.py . ./public_git
|
|
|
|
|
2017-11-11 23:17:17 +01:00
|
|
|
|
|
|
|
CURRENT_COMMIT=$(git rev-parse HEAD)
|
|
|
|
git status --porcelain
|
|
|
|
if [[ "$(git status --porcelain)" != "" ]]; then
|
2023-09-09 12:21:25 +02:00
|
|
|
CURRENT_COMMIT="${CURRENT_COMMIT}(dirty)"
|
2017-11-11 23:17:17 +01:00
|
|
|
fi
|
2023-09-09 12:21:25 +02:00
|
|
|
COMMIT_MSG="render from publish.sh - $(date -u) - ${CURRENT_COMMIT}"
|
2017-11-11 23:17:17 +01:00
|
|
|
|
|
|
|
pushd "$PUBLICDIR"
|
|
|
|
|
|
|
|
echo "adding and commiting all changes in GitHub pages repo"
|
2021-07-08 16:52:11 +02:00
|
|
|
git add .gitignore
|
2017-11-11 23:17:17 +01:00
|
|
|
git add -A
|
2021-07-08 16:52:11 +02:00
|
|
|
if [ "$(git status --porcelain)" != "" ]; then
|
|
|
|
git commit -m "$COMMIT_MSG"
|
|
|
|
else
|
|
|
|
echo "nothing to commit"
|
|
|
|
fi
|
2023-09-09 12:41:06 +02:00
|
|
|
|
|
|
|
if $PUSH; then
|
|
|
|
echo "pushing to GitHub pages repo"
|
|
|
|
git push origin master
|
|
|
|
else
|
|
|
|
echo "not pushing to GitHub pages repo, set -P flag to push"
|
|
|
|
fi
|
2017-11-11 23:17:17 +01:00
|
|
|
|