|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2014 Google Inc. All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -ev |
| 18 | + |
| 19 | +######################################### |
| 20 | +# Only update docs if we are on Travis. # |
| 21 | +######################################### |
| 22 | +if [[ "${TRAVIS_BRANCH}" == "master" ]] && \ |
| 23 | + [[ "${TRAVIS_PULL_REQUEST}" == "false" ]]; then |
| 24 | + echo "Building new docs on a merged commit." |
| 25 | +elif [[ -n "${TRAVIS_TAG}" ]]; then |
| 26 | + echo "Building new docs on a tag." |
| 27 | +else |
| 28 | + echo "No docs to update for a new tag or merged commit on Travis." |
| 29 | + echo "Verifying docs build successfully." |
| 30 | + tox -e docs |
| 31 | + exit |
| 32 | +fi |
| 33 | + |
| 34 | +# Adding GitHub pages branch. `git submodule add` checks it |
| 35 | +# out at HEAD. |
| 36 | +GH_PAGES_DIR="ghpages" |
| 37 | +git submodule add -b gh-pages \ |
| 38 | + "https://${GH_OAUTH_TOKEN}@github.com/${GH_OWNER}/${GH_PROJECT_NAME}" \ |
| 39 | + ${GH_PAGES_DIR} |
| 40 | + |
| 41 | +# Determine if we are building a new tag or are building docs |
| 42 | +# for master. Then build new docset in docs/_build from master. |
| 43 | +if [[ -z "${TRAVIS_TAG}" ]]; then |
| 44 | + SPHINX_RELEASE=$(git log -1 --pretty=%h) tox -e docs |
| 45 | +else |
| 46 | + # Sphinx will use the package version by default. |
| 47 | + tox -e docs |
| 48 | +fi |
| 49 | + |
| 50 | +# Get the current version. Assumes the PWD is the root of the git repo. |
| 51 | +# We run this after `tox -e docs` to make sure the `docs` env is |
| 52 | +# set up. |
| 53 | +CURRENT_VERSION=$(.tox/docs/bin/python scripts/get_version.py) |
| 54 | + |
| 55 | +# Update gh-pages with the created docs. |
| 56 | +cd ${GH_PAGES_DIR} |
| 57 | +if [[ -z "${TRAVIS_TAG}" ]]; then |
| 58 | + git rm -fr latest/ |
| 59 | + cp -R ../docs/_build/html/ latest/ |
| 60 | +else |
| 61 | + if [[ -d ${CURRENT_VERSION} ]]; then |
| 62 | + echo "The directory ${CURRENT_VERSION} already exists." |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + git rm -fr stable/ |
| 66 | + # Put the new release in stable and with the actual version. |
| 67 | + cp -R ../docs/_build/html/ stable/ |
| 68 | + cp -R ../docs/_build/html/ "${CURRENT_VERSION}/" |
| 69 | + |
| 70 | + # Also update the versions file. |
| 71 | + ../.tox/docs/bin/python ../scripts/update_versions.py |
| 72 | + # Update the files which were updated in the release. |
| 73 | + git add versions.html versions.json |
| 74 | +fi |
| 75 | + |
| 76 | +# Update the files push to gh-pages. |
| 77 | +git add . |
| 78 | +git status |
| 79 | + |
| 80 | +# H/T: https://github.com/dhermes |
| 81 | +if [[ -z "$(git status --porcelain)" ]]; then |
| 82 | + echo "Nothing to commit. Exiting without pushing changes." |
| 83 | + exit |
| 84 | +fi |
| 85 | + |
| 86 | +# Commit to gh-pages branch to apply changes. |
| 87 | +git config --global user.email "travis@travis-ci.org" |
| 88 | +git config --global user.name "travis-ci" |
| 89 | +git commit -m "Update docs after merge to master." |
| 90 | +# NOTE: This may fail if two docs updates (on merges to master) |
| 91 | +# happen in close proximity. |
| 92 | +git push \ |
| 93 | + "https://${GH_OAUTH_TOKEN}@github.com/${GH_OWNER}/${GH_PROJECT_NAME}" \ |
| 94 | + HEAD:gh-pages |
0 commit comments