| 1 |
name: Tests |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
branches: [ master ] |
| 6 |
tags: [ '[0-9]+.[0-9]+.[0-9]+*' ] |
| 7 |
pull_request: |
| 8 |
branches: [ master ] |
| 9 |
|
| 10 |
jobs: |
| 11 |
|
| 12 |
linters: |
| 13 |
runs-on: ubuntu-latest |
| 14 |
|
| 15 |
steps: |
| 16 |
- uses: actions/checkout@v4 |
| 17 |
- uses: actions/setup-python@v5 |
| 18 |
with: |
| 19 |
python-version: '3.9' |
| 20 |
|
| 21 |
- name: Install pre-commit |
| 22 |
run: | |
| 23 |
pip install pre-commit |
| 24 |
|
| 25 |
- name: run linters |
| 26 |
# pre-commit also runs in pre-commit.ci, but let's have it here too |
| 27 |
# to block `pypi-publish` job from triggering if pre-commit fails |
| 28 |
run: | |
| 29 |
pre-commit run -a |
| 30 |
|
| 31 |
tests: |
| 32 |
runs-on: ${{ matrix.os }} |
| 33 |
strategy: |
| 34 |
matrix: |
| 35 |
python-version: ['pypy-3.9', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14-dev'] |
| 36 |
os: [ubuntu-latest, macos-latest, windows-latest] |
| 37 |
continue-on-error: ${{ matrix.python-version == '3.14-dev' }} |
| 38 |
|
| 39 |
steps: |
| 40 |
- uses: actions/checkout@v4 |
| 41 |
|
| 42 |
- name: Set up Python ${{ matrix.python-version }} |
| 43 |
uses: actions/setup-python@v5 |
| 44 |
with: |
| 45 |
python-version: ${{ matrix.python-version }} |
| 46 |
|
| 47 |
- name: Installation (deps and package) |
| 48 |
run: | |
| 49 |
pip install . -r tests/requirements.txt |
| 50 |
|
| 51 |
- name: Test with pytest |
| 52 |
run: | |
| 53 |
pytest --cov --cov-fail-under=100 |
| 54 |
|
| 55 |
- name: Report coverage |
| 56 |
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' |
| 57 |
uses: codecov/codecov-action@v4 |
| 58 |
with: |
| 59 |
token: ${{ secrets.CODECOV_TOKEN }} |
| 60 |
|
| 61 |
allgood: |
| 62 |
runs-on: ubuntu-latest |
| 63 |
needs: |
| 64 |
- tests |
| 65 |
- linters |
| 66 |
steps: |
| 67 |
- run: echo "Great success!" |
| 68 |
|
| 69 |
pypi-publish: |
| 70 |
# Only publish if all other jobs succeed |
| 71 |
needs: [ allgood ] |
| 72 |
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') |
| 73 |
runs-on: ubuntu-latest |
| 74 |
steps: |
| 75 |
- uses: actions/checkout@v4 |
| 76 |
- uses: actions/setup-python@v5 |
| 77 |
with: |
| 78 |
python-version: '3.x' |
| 79 |
- name: Install build and publish tools |
| 80 |
run: | |
| 81 |
pip install build twine |
| 82 |
- name: Build and check |
| 83 |
run: | |
| 84 |
rm -rf dist/ && python -m build |
| 85 |
twine check --strict dist/* |
| 86 |
- name: Publish |
| 87 |
run: | |
| 88 |
twine upload dist/* |
| 89 |
env: |
| 90 |
TWINE_USERNAME: __token__ |
| 91 |
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} |