Skip to content

Commit 1dac981

Browse files
committed
GitHub Pages guide. Fixed logging. Classifiers.
Only test sphinx-build in main Travis tests (script section). Save docsV for after_success. If a previous branch is broken it shouldn't break the current branch's tests. Adding GitHub Pages guide in docs. Adding classifiers. Getting ready for release. Moved log statements around. Was printing nothing significant to push and then pushed successfully. Didn't make sense. Tox docsV testenv changed from build to push. Not used in Travis yet.
1 parent 36acc86 commit 1dac981

File tree

8 files changed

+165
-5
lines changed

8 files changed

+165
-5
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ install: pip install appveyor-artifacts coveralls tox
88
before_script:
99
- git config --global user.email "[email protected]"
1010
- git config --global user.name "Travis CI"
11-
script: tox -e lint,py35,py34,py33,pypy,py27,docsV
11+
script: tox -e lint,py35,py34,py33,pypy,py27,docs
1212
after_success:
1313
- coveralls
1414

docs/github_pages.rst

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
.. _github_pages:
2+
3+
============
4+
GitHub Pages
5+
============
6+
7+
It's pretty easy to use `GitHub Pages <https://pages.github.com/>`_ to host all of your versioned documentation. Before
8+
starting be sure to go through the :ref:`tutorial` first to make sure you can build your docs locally. You'll also want
9+
to do the :ref:`push-all-versions` section.
10+
11+
.. tip::
12+
13+
You may want to enable GitHub's `protected branches <https://help.github.com/articles/about-protected-branches/>`_
14+
feature for the gh-pages branch to prevent you or anyone from accidentally deleting the branch from remote.
15+
16+
This guide assumes:
17+
18+
1. You already have documentation in your master branch and SCVersioning builds it locally. If not you'll need to use
19+
the :option:`--root-ref` argument.
20+
2. You already have your CI configured and running on your repo (this guide uses Travis CI but it should work on any
21+
other).
22+
23+
Turn Off Jekyll
24+
===============
25+
26+
Building on the steps in the :ref:`tutorial` document you'll want to disable Jekyll because it doesn't copy over files
27+
and directories `that start with underscores <https://github.com/blog/572-bypassing-jekyll-on-github-pages>`_, which
28+
Sphinx uses.
29+
30+
.. code-block:: bash
31+
32+
git checkout gh-pages
33+
git pull origin gh-pages
34+
touch .nojekyll
35+
git add .nojekyll
36+
git commit
37+
git push origin gh-pages
38+
git checkout master # Or whatever branch you were in.
39+
40+
Then navigate to https://username.github.io/repo_name/ and if you used ``.`` for your :option:`REL_DST` you should see
41+
your HTML docs there. Otherwise if you used something like ``html/docs`` you'll need to navigate to
42+
https://username.github.io/repo_name/html/docs/.
43+
44+
.. tip::
45+
46+
Old repositories may not have **Enforce HTTPS** enabled for their GitHub Pages. It's a good idea to enable this
47+
feature. More info: https://help.github.com/articles/securing-your-github-pages-site-with-https/
48+
49+
Running in CI
50+
=============
51+
52+
The goal of using GitHub Pages is to have docs automatically update on every new/changed branch/tag. In this example
53+
we'll be using Travis CI but any CI should work.
54+
55+
Travis won't be able to push any changes to the gh-pages branch without SSH keys. This guide will worry about just
56+
getting Travis to run SCVersioning. It should only fail when trying to push to origin.
57+
58+
CI Config File
59+
--------------
60+
61+
Edit your CI configuration file (e.g. `.travis.yml <https://docs.travis-ci.com/user/customizing-the-build/>`_) with:
62+
63+
.. code-block:: yaml
64+
65+
install:
66+
- pip install sphinxcontrib-versioning
67+
after_success:
68+
- git config --global user.email "[email protected]"
69+
- git config --global user.name "Travis CI"
70+
- sphinx-versioning push gh-pages . docs
71+
72+
The two git config lines are needed to make commits locally to the gh-pages branch (cloned to a temporary directory by
73+
SCVersioning). If you want SCVersioning to delete unrelated files from the gh-pages branch (e.g. deleted branches' HTML
74+
documentation, deleted tags, etc) change the sphinx-versioning command to:
75+
76+
.. code-block:: bash
77+
78+
sphinx-versioning -e .gitignore -e .nojekyll -e README.rst push gh-pages . docs
79+
80+
This tells SCVersioning to delete all files in gh-pages except those three. More information in :option:`--grm-exclude`.
81+
82+
Commit
83+
------
84+
85+
Commit your changes to the CI config file and push. You should see documentation building successfully, but it should
86+
fail when it tries to push since we haven't given your CI any permission to make changes to the git repository.
87+
88+
SSH Key
89+
=======
90+
91+
Now that we know SCVersioning works fine locally and remotely it's time to unleash it. We'll be using
92+
`Deploy Keys <https://developer.github.com/guides/managing-deploy-keys/>`_ to grant Travis write access to your
93+
repository. At the time of this writing this is the most narrow-scoped authorization method for docs deployment.
94+
95+
To avoid leaking the SSH private key (thereby granting write access to the repo) we'll be using Travis CI's
96+
`Encrypting Files <https://docs.travis-ci.com/user/encrypting-files/>`_ feature. You'll need to install the Travis CI
97+
`ruby client <https://github.com/travis-ci/travis.rb#installation>`_ for this section.
98+
99+
ssh-keygen
100+
----------
101+
102+
First we'll create the SSH key pair.
103+
104+
.. code-block:: bash
105+
106+
ssh-keygen -t rsa -b 4096 -C "Travis CI Deploy Key" -N "" -f docs/key
107+
cat docs/key.pub # We'll be adding this to GitHub's repo settings page.
108+
travis encrypt-file docs/key docs/key.enc --add after_success # Updates .travis.yml
109+
rm docs/key docs/key.pub # Don't need these anymore.
110+
111+
We need to give GitHub your SSH **public** key (the one we ran with ``cat``). Go to
112+
https://github.com/username/repo_name/settings/keys and click "Add deploy key". The title could be anything (e.g.
113+
"Travis CI Deploy Key"). The key you're pasting will be one long line and will look something like "ssh-rsa AAAAB3N...==
114+
Travis CI Deploy Key"
115+
116+
Be sure to check **Allow write access**.
117+
118+
travis.yml
119+
----------
120+
121+
The ``travis encrypt-file`` command should have updated your ``.travis.yml`` with the openssl command for you. However
122+
we still need to make one more change to the file before committing it. Update .travis.yml with these ``chmod``,
123+
``eval``, and ``git remote`` commands. The after_success section should end up looking like this:
124+
125+
.. code-block:: bash
126+
127+
after_success:
128+
- touch docs/key; chmod 600 docs/key # Secure before storing key data.
129+
- openssl aes-256-cbc ... -in docs/key.enc -out docs/key -d
130+
- eval `ssh-agent -s`; ssh-add docs/key
131+
- git config --global user.email "[email protected]"
132+
- git config --global user.name "Travis CI"
133+
- git remote set-url origin "[email protected]:$TRAVIS_REPO_SLUG"
134+
- export ${!TRAVIS*} # Optional, for commit messages.
135+
- sphinx-versioning push gh-pages . docs
136+
137+
Finally commit both **.travis.yml** and the encrypted **docs/key.enc** file. Push and watch Travis update your docs
138+
automatically for you.

docs/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Project Links
4242
settings
4343
themes
4444

45+
.. toctree::
46+
:maxdepth: 2
47+
:caption: Web Hosting
48+
49+
github_pages
50+
4551
.. toctree::
4652
:maxdepth: 1
4753
:caption: Appendix

docs/tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Tutorial
55
========
66

7-
This section will go over the basics of the project.
7+
This guide will go over the basics of the project.
88

99
Make sure that you've already :ref:`installed <install>` it.
1010

setup.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,21 @@ def readme():
3434
author='@Robpol86',
3535
author_email='[email protected]',
3636
classifiers=[
37-
'Private :: Do Not Upload',
37+
'Development Status :: 5 - Production/Stable',
38+
'Environment :: Console',
39+
'Framework :: Sphinx :: Extension',
40+
'Intended Audience :: Developers',
41+
'License :: OSI Approved :: MIT License',
42+
'Operating System :: MacOS',
43+
'Operating System :: POSIX :: Linux',
44+
'Operating System :: POSIX',
45+
'Programming Language :: Python :: 2.7',
46+
'Programming Language :: Python :: 3.3',
47+
'Programming Language :: Python :: 3.4',
48+
'Programming Language :: Python :: 3.5',
49+
'Programming Language :: Python :: Implementation :: PyPy',
50+
'Topic :: Documentation :: Sphinx',
51+
'Topic :: Software Development :: Documentation',
3852
],
3953
description='Sphinx extension that allows building versioned docs for self-hosting.',
4054
entry_points={'console_scripts': ['sphinx-versioning = sphinxcontrib.versioning.__main__:entry_point']},

sphinxcontrib/versioning/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ def main(config):
219219
for _ in range(PUSH_RETRIES):
220220
with TempDir() as temp_dir:
221221
if main_push(config, root, temp_dir):
222-
log.info('Successfully pushed to remote repository.')
223222
return
224223
log.warning('Failed to push to remote repository. Retrying in %d seconds...', PUSH_SLEEP)
225224
time.sleep(PUSH_SLEEP)
@@ -235,6 +234,7 @@ def entry_point():
235234
config = get_arguments(sys.argv, __doc__)
236235
setup_logging(verbose=config['--verbose'], colors=not config['--no-colors'])
237236
main(config)
237+
logging.info('Success.')
238238
except HandledError:
239239
logging.critical('Failure.')
240240
sys.exit(1)

sphinxcontrib/versioning/git.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,4 +404,5 @@ def commit_and_push(local_root, versions):
404404
return False
405405
raise GitError('Failed to push to remote.', exc.output)
406406

407+
log.info('Successfully pushed to remote repository.')
407408
return True

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ deps =
5151

5252
[testenv:docsV]
5353
commands =
54-
sphinx-versioning -t -S semver,chrono build docs/_build/html docs -- -W
54+
sphinx-versioning -t -S semver,chrono -e .gitignore -e .nojekyll -e README.rst push gh-pages . docs -- -W
5555
deps =
5656
{[testenv:docs]deps}
5757
passenv =
58+
HOME
5859
HOSTNAME
5960
SSH_AUTH_SOCK
6061
TRAVIS*

0 commit comments

Comments
 (0)