juniper/docs/book/ci-build.sh
Christian Legnitto 37a9d02850
Fix failure when no book content has changed
If there is no new book content, `git commit` will return `1` and the entire job will error. Took answer from https://stackoverflow.com/questions/8123674/how-to-git-commit-nothing-without-an-error
2019-05-03 00:39:33 -07:00

52 lines
1.3 KiB
Bash
Executable file

#! /usr/bin/env bash
# Usage: ./ci-build.sh VERSION
#
# This script builds the book to HTML with mdbook
# commits and pushes the contents to the repo in the "gh-pages" branch.
#
# It is only inteded for use on the CI!
# Enable strict error checking.
set -exo pipefail
DIR=$(dirname $(readlink -f $0))
MDBOOK="mdbook"
cd $DIR
# Verify version argument.
if [[ -z "$1" ]]; then
echo "Missing required argument 'version': cargo make build-book VERSION"
exit
fi
VERSION="$1"
# Download mdbook if not found.
if [ $MDBOOK -h ]; then
echo "mdbook found..."
else
echo "mdbook not found. Downloading..."
curl -L https://github.com/rust-lang-nursery/mdBook/releases/download/v0.2.0/mdbook-v0.2.0-x86_64-unknown-linux-gnu.tar.gz | tar xzf -
mv ./mdbook /tmp/mdbook
MDBOOK="/tmp/mdbook"
fi
$MDBOOK build
echo $VERSION > ./_rendered/VERSION
rm -rf /tmp/book-content
mv ./_rendered /tmp/book-content
cd $DIR/../..
git clean -fd
git checkout gh-pages
rm -rf $VERSION
mv /tmp/book-content ./$VERSION
git remote set-url --push origin git@github.com:graphql-rust/juniper.git
git config --local user.name "Juniper Bot"
git config --local user.email "juniper@example.com"
git add -A $VERSION
git diff-index --quiet HEAD || git commit -m "Updated book for $VERSION ***NO_CI***"
git push origin gh-pages