Skip to content

Tox

Tox #2233

Workflow file for this run

# GitHub Actions Workflow configuration
# https://docs.github.com/actions/reference/workflow-syntax-for-github-actions
# https://docs.github.com/actions/guides/building-and-testing-python
name: Tox
# Note: on key treated as boolean key by YAML
# https://github.com/adrienverge/yamllint/issues/158#issuecomment-454313233
# However, GitHub Actions documentation is consistent in using it unquoted.
on: # yamllint disable-line rule:truthy
pull_request:
branches-ignore:
- template
push:
branches-ignore:
- template
schedule:
# Run once a day (at 8:20 AM UTC) to check for exogenous breakage.
# TODO: Run when dependencies are updated. (Like Dependabot, but on
# in-range updates and without sending a PR.)
- cron: '20 8 * * *'
workflow_call: {}
workflow_dispatch: {}
permissions: {}
jobs:
test-primary:
name: Lint, Docs, Test on Python 3
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: 3.x
- name: Display Python version
run: python --version
- name: Install dependencies
run: python -m pip install --upgrade build setuptools tox
- name: Run tox
run: python -m tox -e lint,docs,py3
- name: Build sdist and wheel
run: python -m build
- name: Archive sdist
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
path: dist/*.tar.gz
archive: false
if-no-files-found: error
retention-days: 7
- name: Archive wheel
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
path: dist/*.whl
archive: false
if-no-files-found: error
retention-days: 7
test-secondary:
# Only test secondary platforms if primary test platform passed
needs:
- test-primary
name: >-
Test on Python ${{ matrix.python.version }} ${{ matrix.arch }}
on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
arch:
# Uncomment if package needs testing on different architectures
# - x86
- x64
os:
# Uncomment if package needs testing on macOS:
# - macos-latest
- ubuntu-latest
- windows-latest
python:
- version: '3.10'
exe: python
toxenv: py310
- version: 3.x
exe: python
toxenv: py3
- version: pypy-3.10
exe: pypy3
toxenv: pypy3
exclude:
# Exclude os/version already run in test-primary
- arch: x64
os: ubuntu-latest
python:
version: 3.x
exe: python
toxenv: py3
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python ${{ matrix.python.version }}
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ matrix.python.version }}
architecture: ${{ matrix.arch }}
- name: Display Python version
run: python --version
- name: Install dependencies
run: |-
${{ matrix.python.exe }} -m pip install --upgrade build setuptools tox
- name: Run tox
run: ${{ matrix.python.exe }} -m tox -e ${{ matrix.python.toxenv }}
- name: Build sdist and wheel
run: python -m build
- name: Check whether wheel artifact already exists
id: wheel_artifact
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
wheels=( dist/*.whl )
if [ "${#wheels[@]}" -ne 1 ]; then
echo "::error::Expected 1 wheel, got ${#wheels[@]}: ${wheels[*]}"
exit 1
fi
wheel=${wheels[0]}
wheel=${wheel#dist/}
if gh api \
"repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/artifacts" \
--jq '.artifacts.[].name' |
grep -Fxq "$wheel"; then
echo 'exists=true' >"$GITHUB_OUTPUT"
else
echo 'exists=false' >"$GITHUB_OUTPUT"
fi
- name: Archive wheel
# upload-artifact overwrite doesn't handle archive: false:
# https://github.com/actions/upload-artifact/issues/769
# to avoid duplicate artifacts, skip upload when it already exists
if: steps.wheel_artifact.outputs.exists == false
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
path: dist/*.whl
archive: false
if-no-files-found: error
retention-days: 7