For a number of years I have been concerned about the duplication of work having to maintain continuous integration environments both on Travis-CI to run the unit tests and on Readthedocs to build and host the documentation.
The solution I am proposing is to use Github actions to replace both systems. I chose Github actions instead of Travis-CI because they are easier to configure, have better log-viewing interface and surprisingly enough they are better integrated with Github!
The biggest hurdle was to find a way to reproduce the capability of readthedocs to host multiple versions of the documentation together, fortunately the sphinx-multiversion gives a very similar functionality.
Next I’ll be sharing an example configuration for Github actions that integrates:
- Installs requirements both via the package manager and
pip - Build and run unit tests for Python 3.6 and 3.7
- Just with Python 3.6, installs
sphinx-multiversion, builds the docs for all tagged releases, pushes that to the documentation repository
| # This workflow will install Python dependencies, run tests and lint with a variety of Python versions | |
| # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
| name: Python package | |
| on: | |
| push: | |
| branches: [ master ] | |
| pull_request: | |
| branches: [ master ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: [3.6, 3.7] | |
| steps: | |
| - uses: actions/checkout@v2 | |
| with: | |
| submodules: true | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v2 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install libcfitsio | |
| run: sudo apt-get install libcfitsio-dev | |
| - name: Install pip dependencies | |
| run: | | |
| python -m pip install -r requirements.txt -r test-requirements.txt | |
| - name: Build | |
| run: python setup.py build_ext -i && python setup.py install | |
| env: | |
| C_INCLUDE_PATH: /usr/include/cfitsio/ | |
| - name: Test | |
| run: | | |
| pytest | |
| - name: Build docs | |
| if: ${{ matrix.python-version==3.6 }} | |
| run: | | |
| python -m pip install -r docs/requirements.txt && sphinx-multiversion docs html | |
| - name: Install SSH Client 🔑 | |
| if: ${{ matrix.python-version==3.6 }} | |
| uses: webfactory/ssh-agent@v0.2.0 | |
| with: | |
| ssh-private-key: ${{ secrets.DEPLOY_KEY }} | |
| - name: Deploy 🚀 | |
| if: ${{ matrix.python-version==3.6 && contains(github.ref, 'master') }} | |
| uses: JamesIves/github-pages-deploy-action@3.5.7 | |
| with: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| BRANCH: master | |
| FOLDER: html | |
| REPOSITORY_NAME: MYORG/MYREPO | |
| SSH: true |
Requirements
Create a
docs/requirements.txtfile which includessphinx-multiversion, I directly usehttps://github.com/Holzhaus/sphinx-multiversion/archive/master.zipFollow the
sphinx-multiversiondocumentation to configuredocs/conf.py, for example my configuration is:```Sphinx multiversion configuration
extensions += [“sphinx_multiversion”]
templates_path = [ “_templates”, ] #html_sidebars = {’**’: [ # “versioning.html”, # ]}