Skip to content

test: make coverage suite CI-safe #36

test: make coverage suite CI-safe

test: make coverage suite CI-safe #36

Workflow file for this run

name: CI
# Tag pushes must be listed explicitly; branch-only `push` does not run on new tags,
# so "Publish to PyPI" would always be skipped without `tags:` here.
on:
push:
branches: [main, dev]
tags:
- "v*"
pull_request:
branches: [main]
workflow_dispatch:
inputs:
publish_to_pypi:
description: "Publish to PyPI after tests (only if this version is not already on PyPI)"
required: false
default: false
type: boolean
permissions:
contents: read
jobs:
test:
name: Test (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install ctxeng + dev deps
run: |
pip install -e ".[dev]"
- name: Lint with ruff
run: ruff check ctxeng/
- name: Type check with mypy
run: mypy ctxeng/ --ignore-missing-imports
continue-on-error: true
- name: Run tests with coverage
run: |
pytest tests/ --cov=ctxeng --cov-report=xml --cov-report=term-missing --cov-fail-under=80
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
fail_ci_if_error: false
publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: test
# Runs after a version tag push (e.g. v0.1.3), or manual run with publish enabled.
if: |
needs.test.result == 'success' &&
(
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.publish_to_pypi == 'true')
)
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Build package
run: |
pip install hatchling
python -m hatchling build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
# If PYPI_API_TOKEN is set, token-based upload is used.
# If it's missing, the action falls back to trusted publishing (OIDC),
# which requires `id-token: write` permissions.
password: ${{ secrets.PYPI_API_TOKEN }}