Created
June 10, 2017 08:56
-
-
Save buddhike/f10f1088645d18a5135b3af3876d834b to your computer and use it in GitHub Desktop.
hugo deployment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
DIR=$(dirname "$0") | |
if [[ $(git status -s) ]] | |
then | |
echo "The working directory is dirty. Please commit any pending changes." | |
exit 1; | |
fi | |
DEFAULT_UPSTREAM="" | |
UPSTREAM=$(git remote -v | grep "upstream" | grep -v grep | cat) | |
if [ -z "$UPSTREAM" ] | |
then | |
echo "Upstream not found. Configuring the upstream." | |
git remote add upstream "$DEFAULT_UPSTREAM" && | |
git fetch --all | |
echo "Upstream configured to point to $DEFAULT_UPSTREAM." | |
fi | |
echo "Deleting old publication" | |
rm -rf public | |
mkdir public | |
git worktree prune | |
echo "Checking out gh-pages branch into public" | |
git worktree add -B gh-pages public upstream/gh-pages | |
rm -rf public/* | |
echo "Generating site" | |
hugo --baseUrl "/" | |
echo "Updating gh-pages branch" | |
pushd public && git add --all && git commit -m "Publishing to gh-pages (deploy.sh)" | |
git push -f | cat | |
popd | |
echo "published" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment