From 4163cc6b9d417689cf168f22baeef834bef954fc Mon Sep 17 00:00:00 2001 From: Chao Sun Date: Thu, 3 May 2018 00:11:17 -0700 Subject: [PATCH] Deploy documentation to github pages --- .travis.yml | 5 ++++- ci/deploy-docs.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 ci/deploy-docs.sh diff --git a/.travis.yml b/.travis.yml index d7b93a3..f33581f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,13 +19,16 @@ rust: script: - cargo build - cargo test + - cargo doc --no-deps after_success: - if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo bench; fi - cargo coveralls --verbose --exclude-pattern '/parquet-rs/src/bin' - + - '[ "$TRAVIS_PULL_REQUEST" = false ] && + { [ "$TRAVIS_TAG" != "" ] || [ "$TRAVIS_BRANCH" = "master" ]; } && + ./ci/deploy-docs.sh' env: global: - TRAVIS_CARGO_NIGHTLY_FEATURE="" diff --git a/ci/deploy-docs.sh b/ci/deploy-docs.sh new file mode 100755 index 0000000..708211e --- /dev/null +++ b/ci/deploy-docs.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +set -e + +GITHUB_USER="doc-deploy-bot" +GITHUB_EMAIL="" + +DOC_VERSION=${TRAVIS_TAG:-$TRAVIS_BRANCH} +if [ -z "$DOC_VERSION" ]; then + echo "Failed to find documentation version, make sure TRAVIS_TAG or TRAVIS_BRANCH is set" + exit 1 +fi + +echo "Deploying documentation version $DOC_VERSION" + +# Check that GITHUB_TOKEN is set +if [ -z "$GITHUB_TOKEN" ]; then + echo "GITHUB_TOKEN is not set. + You’ll need to generate a personal access token with the 'public_repo'. + Since the token should be private, you’ll want to pass it to Travis securely + in your repository settings or via encrypted variables in .travis.yml." + exit 1 +fi + +if [ -d "target/doc" ]; then + echo "" > ./target/doc/index.html + + echo "Setting up gh-pages branch" && + git clone --branch gh-pages "https://$GITHUB_TOKEN@github.com/${TRAVIS_REPO_SLUG}.git" deploy_docs > /dev/null 2>&1 && + cd deploy_docs && + rm -rf ./$DOC_VERSION && + mkdir ./$DOC_VERSION && + mv ../target/doc/* ./$DOC_VERSION/ && + git config user.name "$GITHUB_USER" && + git config user.email "$GITHUB_EMAIL" && + git add -A . && + git commit -m "Deploy doc pages $DOC_VERSION at ${TRAVIS_COMMIT}" && + echo "Pushing documentation update" && + git push --quiet origin gh-pages > /dev/null 2>&1 && + echo "Published documentation $DOC_VERSION" || echo "Failed to publish documentation $DOC_VERSION" +else + echo "Failed to find target/doc directory, have you built the docs?" + exit 1 +fi +