|
16 | 16 |
|
17 | 17 | set -ev
|
18 | 18 |
|
19 |
| -# Build new docset in docs/_build from master. |
20 |
| -tox -e docs |
| 19 | +# Adding GitHub pages branch. `git submodule add` checks it |
| 20 | +# out at HEAD. |
| 21 | +GH_PAGES_DIR="ghpages" |
21 | 22 | git submodule add -b gh-pages \
|
22 | 23 | "https://${GH_OAUTH_TOKEN}@github.com/${GH_OWNER}/${GH_PROJECT_NAME}" \
|
23 |
| - ghpages |
24 |
| -cp -R docs/_build/html/* ghpages/ |
25 |
| -cd ghpages |
26 |
| -# allow "git add" to fail if there aren't new files. |
27 |
| -set +e |
| 24 | + ${GH_PAGES_DIR} |
| 25 | + |
| 26 | +# Determine if we are building a new tag or are building docs |
| 27 | +# for master. Then build new docset in docs/_build from master. |
| 28 | +if [[ -z "${TRAVIS_TAG}" ]]; then |
| 29 | + SPHINX_RELEASE=$(git log -1 --pretty=%h) tox -e docs |
| 30 | +else |
| 31 | + # Sphinx will use the package version by default. |
| 32 | + tox -e docs |
| 33 | +fi |
| 34 | + |
| 35 | +# Get the current version. Assumes the PWD is the root of the git repo. |
| 36 | +# We run this after `tox -e docs` to make sure the `docs` env is |
| 37 | +# set up. |
| 38 | +CURRENT_VERSION=$(.tox/docs/bin/python scripts/get_version.py) |
| 39 | + |
| 40 | +# Update gh-pages with the created docs. |
| 41 | +cd ${GH_PAGES_DIR} |
| 42 | +if [[ -z "${TRAVIS_TAG}" ]]; then |
| 43 | + git rm -fr master/ |
| 44 | + cp -R ../docs/_build/html/ master/ |
| 45 | +else |
| 46 | + if [[ -d ${CURRENT_VERSION} ]]; then |
| 47 | + echo "The directory ${CURRENT_VERSION} already exists." |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | + git rm -fr latest/ |
| 51 | + # Put the new release in latest and with the actual version. |
| 52 | + cp -R ../docs/_build/html/ latest/ |
| 53 | + cp -R ../docs/_build/html/ "${CURRENT_VERSION}/" |
| 54 | +fi |
| 55 | + |
| 56 | +# Update the files push to gh-pages. |
28 | 57 | git add .
|
29 |
| -set -e |
30 | 58 | git status
|
| 59 | + |
31 | 60 | # H/T: https://github.com/dhermes
|
32 |
| -if [[ -n "$(git status --porcelain)" ]]; then |
33 |
| - # Commit to gh-pages branch to apply changes. |
34 |
| - git config --global user.email "travis@travis-ci.org" |
35 |
| - git config --global user.name "travis-ci" |
36 |
| - git commit -m "Update docs after merge to master." |
37 |
| - git push \ |
38 |
| - "https://${GH_OAUTH_TOKEN}@github.com/${GH_OWNER}/${GH_PROJECT_NAME}" \ |
39 |
| - HEAD:gh-pages |
40 |
| -else |
| 61 | +if [[ -z "$(git status --porcelain)" ]]; then |
41 | 62 | echo "Nothing to commit. Exiting without pushing changes."
|
| 63 | + exit |
42 | 64 | fi
|
| 65 | + |
| 66 | +# Commit to gh-pages branch to apply changes. |
| 67 | +git config --global user.email "travis@travis-ci.org" |
| 68 | +git config --global user.name "travis-ci" |
| 69 | +git commit -m "Update docs after merge to master." |
| 70 | +# NOTE: This may fail if two docs updates (on merges to master) |
| 71 | +# happen in close proximity. |
| 72 | +git push \ |
| 73 | + "https://${GH_OAUTH_TOKEN}@github.com/${GH_OWNER}/${GH_PROJECT_NAME}" \ |
| 74 | + HEAD:gh-pages |
0 commit comments