set -ex
INSTALLED=$(echo $(mdbook --version 2>/dev/null || echo "mdbook none") | cut -d' ' -f1)
PINNED=0.2.1
if [ "$PINNED" != "$INSTALLED" ]; then
URL=https://github.com/rust-lang-nursery/mdBook/releases/download/v${PINNED}/mdbook-v${PINNED}-x86_64-unknown-linux-musl.tar.gz
curl -SsL $URL | tar xvz -C $HOME/.cargo/bin
fi
mdbook build -d ../target/guide guide
cargo doc --all-features --no-deps
echo "<meta http-equiv=refresh content=0;url=pyo3/index.html>" > target/doc/index.html
git fetch --tags
LASTEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1 -l v*))
git clone -b gh-pages https://$GH_TOKEN@github.com/$TRAVIS_REPO_SLUG.git gh_pages
cd gh_pages
echo "<meta http-equiv=refresh content=0;url='${LASTEST_TAG}/'>" > index.html
echo "pyo3.rs" > CNAME
rm -rf "$TRAVIS_BRANCH"
cp -r ../target/guide "$TRAVIS_BRANCH"
cp -r ../target/doc "$TRAVIS_BRANCH"
git add --all
git commit -m "Upload documentation for $TRAVIS_BRANCH"
git push -f