Skip to content

Python CI

Python CI #232

Workflow file for this run

---
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python CI
# yamllint disable-line rule:truthy
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:
schedule:
- cron: "12 12 * * MON-FRI/3"
jobs:
build-package:
permissions:
attestations: write
contents: read
id-token: write
name: Build & verify package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check built Python package
id: baipp
uses: hynek/build-and-inspect-python-package@v2
with:
upload-name-suffix: -${{ matrix.python-version }}-${{ matrix.os }}
attest-build-provenance-github: ${{ github.event_name != 'pull_request' && !github.event.pull_request.head.repo.fork }}
outputs:
# Outputs the supported Python versions as a JSON array, from the project classifiers
python-versions: ${{ steps.baipp.outputs.supported_python_classifiers_json_array }}
CI-Python:
runs-on: ubuntu-latest
needs: build-package
env:
PYTHONDEVMODE: 1
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJson(needs.build-package.outputs.python-versions) }}
# Empty is latest, head is latest from GitHub
pdm-version: [""]
os: [ubuntu-latest]
include:
- os: macOS-latest
python-version: '3.12'
pdm-version: ""
- os: windows-latest
python-version: '3.12'
pdm-version: ""
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pdm-project/setup-pdm@v4
name: Setup PDM
with:
cache: true
python-version: ${{ matrix.python-version }} # Version range or exact version of a Python version to use, the same as actions/setup-python
version: ${{ matrix.pdm-version }} # The version of PDM to install. Leave it as empty to use the latest version from PyPI, or 'head' to use the latest version from GitHub
prerelease: true # Allow prerelease versions of PDM to be installed
allow-python-prereleases: true # Allow prerelease versions of Python to be installed. For example if only 3.12-dev is available, 3.12 will fall back to 3.12-dev
- name: Set Cache Variables
id: set_variables
shell: bash
run: |
echo "PIP_CACHE=$(pip cache dir)" >> $GITHUB_OUTPUT
echo "PDM_CACHE=$(pdm config cache_dir)" >> $GITHUB_OUTPUT
- name: Cache PIP and PDM
uses: actions/cache@v4
with:
path: |
${{ steps.set_variables.outputs.PIP_CACHE }}
${{ steps.set_variables.outputs.PDM_CACHE }}
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ matrix.pdm-version }}
- name: Install dependencies
run: |
pdm install -G :all --dev
- name: Run Test with tox
run: pdm run tox
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
flags: unittests
- name: Type check with mypy
run: |
pdm run lint-mypy
- name: Lint with ruff
run: |
pdm run lint-ruff --output-format=github --exit-non-zero-on-fix
- name: Build with pdm
run: |
pdm build
# Do not upload to PyPI, here we only want to check that the build works