Add comprehensive test suite and coverage utilities #1
This file contains hidden or 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 and Coverage | |
on: | |
push: | |
branches: [ main, develop ] | |
pull_request: | |
branches: [ main, develop ] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: [3.11, 3.12] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Cache pip packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -e ".[test]" | |
- name: Run tests with coverage | |
run: | | |
python -m pytest tests/ \ | |
--cov=cellmap_flow \ | |
--cov-report=xml \ | |
--cov-report=term-missing \ | |
--cov-branch \ | |
-v | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
file: ./coverage.xml | |
flags: unittests | |
name: codecov-umbrella | |
fail_ci_if_error: false | |
coverage-report: | |
runs-on: ubuntu-latest | |
needs: test | |
if: github.event_name == 'pull_request' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.11 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -e ".[test]" | |
pip install coverage-badge | |
- name: Run coverage | |
run: | | |
python -m pytest tests/ \ | |
--cov=cellmap_flow \ | |
--cov-report=json \ | |
--cov-report=html \ | |
--cov-branch | |
- name: Generate coverage badge | |
run: | | |
coverage-badge -o coverage.svg | |
- name: Upload coverage reports as artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: coverage-reports | |
path: | | |
htmlcov/ | |
coverage.svg | |
coverage.json | |
retention-days: 30 | |
coverage-comment: | |
runs-on: ubuntu-latest | |
needs: test | |
if: github.event_name == 'pull_request' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.11 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -e ".[test]" | |
- name: Run coverage | |
run: | | |
python -m pytest tests/ \ | |
--cov=cellmap_flow \ | |
--cov-report=json | |
- name: Coverage comment | |
uses: py-cov-action/python-coverage-comment-action@v3 | |
with: | |
GITHUB_TOKEN: ${{ github.token }} |