ci: enable github test workflow #10
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: Tests | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
concurrency: | |
group: tests-${{ github.head_ref || github.ref }} | |
cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
jobs: | |
tests: | |
name: ${{ matrix.os }} / ${{ matrix.python-version }} | |
runs-on: ${{ matrix.image }} | |
strategy: | |
matrix: | |
os: [Ubuntu, macOS, Windows] | |
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] | |
include: | |
- os: Ubuntu | |
image: ubuntu-22.04 | |
- os: Windows | |
image: windows-2022 | |
- os: macOS | |
image: macos-12 | |
fail-fast: false | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
id: setup-python | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install and configure Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
version: 1.5.1 | |
virtualenvs-in-project: true | |
- name: Set up cache | |
uses: actions/cache@v4 | |
id: cache | |
with: | |
path: .venv | |
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
- name: Ensure cache is healthy | |
if: steps.cache.outputs.cache-hit == 'true' | |
run: | | |
# `timeout` is not available on macOS, so we define a custom function. | |
[ "$(command -v timeout)" ] || function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; } | |
# Using `timeout` is a safeguard against the Poetry command hanging for some reason. | |
timeout 10s poetry run pip --version || rm -rf .venv | |
- name: Install dependencies | |
run: poetry install | |
- name: Run pytest | |
run: | | |
poetry run pytest --cov -v --cov-report=xml | |
mv coverage.xml coverage.${{ runner.os }}-py${{ matrix.python-version }}.xml | |
- name: Upload coverage reports to Codecov | |
uses: codecov/codecov-action@v3 | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
- name: Check for clean working tree | |
run: | | |
git diff --exit-code --stat HEAD |