Merge pull request #21 from s-hamann/docs #38
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: Code Quality | |
on: | |
push: | |
paths: | |
- '**.py' | |
branches: | |
- main | |
pull_request: | |
paths: | |
- '**.py' | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
env: | |
RUFF_OUTPUT_FORMAT: github | |
steps: | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
check-latest: true | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install package and dependencies | |
run: pip install -e .'[all]' | |
- name: Install linters | |
run: pip install mypy ruff | |
- name: Register matchers | |
run: for matcher in .github/workflows/matchers/*.json; do echo ::add-matcher::"${matcher}"; done | |
- name: Check types | |
run: mypy --install-types --non-interactive --show-column-numbers . | |
- name: Check code style | |
run: ruff check . | |
- name: Check code formatting | |
run: ruff format --check . | |
test: | |
name: Tests | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: | |
- '3.9' | |
- '3.10' | |
- '3.11' | |
- '3.12' | |
- 'pypy3.9' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install tox | |
run: pip install tox-gh | |
- name: Run tests | |
run: tox -q run | |
- name: Store code coverage data | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-${{ matrix.python-version }} | |
path: .coverage.* | |
coverage: | |
name: Coverage | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
check-latest: true | |
- name: Install tox | |
run: pip install tox | |
- name: Get code coverage data | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: coverage-* | |
merge-multiple: true | |
- name: Process code coverage data | |
run: | | |
tox -q run -e coverage -- json | |
tox -q run -e coverage -- html | |
- name: Store code coverage report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-report | |
path: htmlcov/ | |
- name: Upload coverage reports to Codecov | |
uses: codecov/codecov-action@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: Report coverage | |
run: | | |
python >> "${GITHUB_STEP_SUMMARY}" << EOC | |
import json | |
cov = json.load(open('coverage.json')) | |
def row(stats): | |
return '|'.join([str(stats[k]) for k in ('num_statements', 'missing_lines', 'num_branches', 'num_partial_branches', 'percent_covered_display')]) + '%' | |
print('Name|Stmts|Miss|Branch|BrPart|Cover') | |
print(':---|----:|---:|-----:|-----:|----:') | |
for fname, fcov in cov['files'].items(): | |
print(f'{fname}|{row(fcov["summary"])}') | |
print(f'TOTAL|{row(cov["totals"])}') | |
EOC |