Skip to content

Commit a5aabf3

Browse files
committed
Adding subdirectories for versioned docs.
Fixes #472.
1 parent 32e50eb commit a5aabf3

File tree

3 files changed

+53
-20
lines changed

3 files changed

+53
-20
lines changed

docs/conf.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@
5454
# built documents.
5555
#
5656
# The short X.Y version.
57-
version = get_distribution('gcloud').version
58-
# The full version, including alpha/beta/rc tags.
59-
release = get_distribution('gcloud').version
57+
release = os.getenv('SPHINX_RELEASE', get_distribution('gcloud').version)
6058

6159
# The language for content autogenerated by Sphinx. Refer to documentation
6260
# for a list of supported languages.

scripts/get_version.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""Simple script to get the gcloud version."""
2+
from pkg_resources import get_distribution
3+
print get_distribution('gcloud').version

scripts/update_docs.sh

+49-17
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,59 @@
1616

1717
set -ev
1818

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"
2122
git submodule add -b gh-pages \
2223
"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.
2857
git add .
29-
set -e
3058
git status
59+
3160
# 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
4162
echo "Nothing to commit. Exiting without pushing changes."
63+
exit
4264
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

Comments
 (0)