Skip to content

Instantly share code, notes, and snippets.

@fwilhe
Created November 3, 2015 13:24
Show Gist options
  • Save fwilhe/d0cb0a954d902c892856 to your computer and use it in GitHub Desktop.
Save fwilhe/d0cb0a954d902c892856 to your computer and use it in GitHub Desktop.
#!/bin/sh
# based on https://raw.githubusercontent.com/fkling/esprima_ast_explorer/master/scripts/push-site.sh
# precondition: `gh-pages` branch does exist
TARGETPATH="../$(basename $(pwd))_gh_pages"
REMOTE=$(git remote -v | grep origin | grep "(push)" | cut -f 2 | cut -d ' ' -f 1)
if ! git diff --quiet && git diff --cached --quiet; then
echo >&2 "Cannot build, your index contains uncommitted changes."
exit 1
fi
if [ ! -d "$TARGETPATH" ]; then
echo "Cloning into '$TARGETPATH'..."
git clone ./ "$TARGETPATH"
cd "$TARGETPATH"
git checkout gh-pages
git remote set-url --push origin $REMOTE
cd - > /dev/null
fi
echo "Building..."
./gradlew asciidoctor
echo "Copying artifacts..."
cp -R build/asciidoc/html5/* "$TARGETPATH/"
# Commit changes
cd $TARGETPATH
if git diff --quiet && git diff --cached --quite; then
echo "No changes, nothing to commit..."
exit 0
fi
echo "Committing..."
git add .
git commit -m "Automatic commit by push-site.sh: Update site"
echo "Pushing..."
git push origin
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment