Run Python Tests and Publish to PyPI #312
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run Python Tests and Publish to PyPI | |
on: | |
push: | |
branches: | |
- master | |
- develop | |
- citest | |
tags: | |
- '*' | |
pull_request: | |
branches: | |
- master | |
- develop | |
schedule: | |
# Run on Tuesdays at 5:59 | |
- cron: '59 5 * * 2' | |
workflow_dispatch: | |
jobs: | |
build-n-test: | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest] | |
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] | |
requirements-file: ["requirements.txt"] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install flake8 pytest wheel | |
pip install -r ${{ matrix.requirements-file }} | |
python setup.py install | |
- name: Lint with flake8 | |
run: | | |
# stop the build if there are Python syntax errors or undefined names | |
flake8 opusfilter --count --select=E9,F63,F7,F82 --show-source --statistics | |
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
flake8 opusfilter --count --exit-zero --statistics | |
- name: Run tests with pytest | |
run: pytest | |
build-n-publish: | |
name: Build and publish Python π distributions π¦ to PyPI and TestPyPI | |
needs: build-n-test | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Check for main release tag | |
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') | |
id: check-tag | |
run: | | |
if [[ ${{ github.event.ref }} =~ ^refs/tags/[0-9]+\.[0-9]+\.[0-9]+(rc[0-9]*)?$ ]]; then | |
echo "match=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Set up Python 3.7 | |
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.7 | |
- name: Install pypa/build | |
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') | |
run: >- | |
python -m | |
pip install | |
build | |
--user | |
- name: Build a binary wheel and a source tarball | |
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') | |
run: >- | |
python -m | |
build | |
--sdist | |
--wheel | |
--outdir dist/ | |
. | |
- name: Publish distribution π¦ to Test PyPI | |
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
repository-url: https://test.pypi.org/legacy/ | |
- name: Publish distribution π¦ to PyPI | |
if: github.event_name == 'push' && steps.check-tag.outputs.match == 'true' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.PYPI_API_TOKEN }} | |
build-and-deploy-docs: | |
runs-on: ubuntu-latest | |
needs: [build-n-test] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies to build docs | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install wheel | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
python -m pip install .[docs] | |
- name: Build docs | |
run: | | |
sphinx-build docs docs/build | |
- name: Deploy docs | |
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
branch: gh-pages | |
folder: docs/build | |
clean: true |