Make CI more resilient #8
Workflow file for this run
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: "🔬 Test" | |
on: | |
pull_request: | |
push: | |
branches: | |
- "develop" | |
- "master" | |
- "main" | |
- "releases" | |
jobs: | |
test: | |
strategy: | |
fail-fast: false | |
matrix: | |
# macOS and Windows tests target only the upper and lower CPython versions. | |
os: | |
- name: "macOS" | |
runner: "macos-latest" | |
- name: "Windows" | |
runner: "windows-latest" | |
cpythons: | |
# The goal is to ensure that each individual runner | |
# is paired with all Python versions simultaneously. | |
# This nested-list syntax accomplishes that goal. | |
- - "3.8" | |
- "3.12" | |
# These last two keys are placeholders to ensure consistency in matrix values. | |
cpython-betas: | |
- [] | |
pypys: | |
- [] | |
# The Linux runner tests every CPython and PyPy version. | |
include: | |
- os: | |
name: "Linux" | |
runner: "ubuntu-latest" | |
cpythons: | |
- "3.8" | |
- "3.9" | |
- "3.10" | |
- "3.11" | |
- "3.12" | |
cpython-betas: | |
- "3.13" | |
pypys: | |
- "3.8" | |
- "3.9" | |
- "3.10" | |
name: "${{ matrix.os.name }}" | |
runs-on: "${{ matrix.os.runner }}" | |
steps: | |
- name: "Checkout the repo" | |
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" # v4.1.1 | |
- name: "Setup Python" | |
id: "setup-python" | |
uses: "actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236" # v4.7.1 | |
with: | |
python-version: "${{ matrix.os.name == 'Linux' && format('pypy-{0}\n{1}\n', join(matrix.pypys, '\npypy-'), join(matrix.cpython-betas, '\n')) || '' }}${{ join(matrix.cpythons, '\n') }}" | |
allow-prereleases: true | |
- name: "Detect Pythons" | |
uses: "kurtmckee/detect-pythons@cd2193638306e04e41ac36f0f9290f18680138ac" # v1.0.0 | |
- name: "Restore cache" | |
id: "restore-cache" | |
uses: "actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84" # v3.3.2 | |
with: | |
# The cache key includes the following to ensure it busts correctly: | |
# | |
# * All Python versions (detected by kurtmckee/detect-pythons, above) | |
# This ensures that .venv/ symlinks to Python interpreters work. | |
# * The tox configuration (tox.ini) | |
# * The mypy/pytest/Sphinx configurations (pyproject.toml, docs/conf.py) | |
# * Exact dependency versions (requirements/*.txt) | |
# | |
key: "test-os=${{ runner.os }}-hash=${{ hashFiles('.python-identifiers', 'pyproject.toml', 'docs/conf.py', 'tox.ini', 'requirements/*.txt') }}" | |
path: | | |
.mypy_cache/ | |
.tox/ | |
.venv/ | |
- name: "Determine venv path" | |
shell: "bash" | |
run: "echo 'venv-path=.venv/${{ runner.os == 'Windows' && 'Scripts' || 'bin' }}' >> $GITHUB_ENV" | |
- name: "Create virtual environment" | |
if: "steps.restore-cache.outputs.cache-hit == false" | |
run: | | |
python -m venv .venv | |
${{ env.venv-path }}/python -m pip install --upgrade pip setuptools wheel | |
${{ env.venv-path }}/python -m pip install tox | |
- name: "Run tests (Linux)" | |
if: "matrix.os.name == 'Linux'" | |
# Interpreters are tested in the following order: | |
# Stable CPython versions first, then PyPy versions, then CPython betas. | |
run: "${{ env.venv-path }}/tox run -e py${{ join(matrix.cpythons, '-chardet,py') }}-chardet,pypy${{ join(matrix.pypys, '-chardet,pypy') }}-chardet,py${{ join(matrix.cpython-betas, '-chardet,py') }}-chardet" | |
- name: "Run tests (macOS/Windows)" | |
if: "matrix.os.name != 'Linux'" | |
run: "${{ env.venv-path }}/tox run -e py${{ join(matrix.cpythons, '-chardet,py') }}-chardet" | |
lint: | |
name: "Lint" | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: "Checkout the repo" | |
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" # v4.1.1 | |
- name: "Setup Python" | |
id: "setup-python" | |
uses: "actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236" # v4.7.1 | |
with: | |
python-version: "3.12" | |
- name: "Determine month number" | |
shell: "bash" | |
run: "date +'%m' > month-number.txt" | |
- name: "Restore cache" | |
id: "restore-cache" | |
uses: "actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84" # v3.3.2 | |
with: | |
path: | | |
.mypy_cache/ | |
.tox/ | |
.venv/ | |
key: "lint-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('month-number.txt', 'pyproject.toml', 'tox.ini') }}" | |
- name: "Create virtual environment" | |
if: "steps.restore-cache.outputs.cache-hit == false" | |
run: | | |
python -m venv .venv | |
.venv/bin/python -m pip install --upgrade pip setuptools wheel | |
.venv/bin/python -m pip install tox | |
- name: "Build the documentation" | |
run: ".venv/bin/tox run -e docs" | |
- name: "Check type annotations" | |
run: ".venv/bin/tox run -e mypy" |