Skip to content

Commit

Permalink
Add code coverage check to CI (#78)
Browse files Browse the repository at this point in the history
* Combine GitHub actions test runs into a single ci file

Setting the groundwork to add a coverage report to Cladetime. We'll want to
run integration tests and unit tests at the same time to get a full report
of test coverage, so do that (but not on every push).

* Add test coverage check and report

The coverage job will fail if if code coverage is >= 80%

* Add status badge for the CI workflow

This doesn't give us an actual coverage percentage, but a successful
workflow run does mean that coverage is at or above the stated minimum
(in this case 80%, to match Hubverse standards).

* Rename run-code-checks to ci

This is a common pattern I've seen when looking at other python projects
(and also, the workflow does more than run tests now)

* Also run CI workflow on merge to main branch

* Fix typo
  • Loading branch information
bsweger authored Jan 6, 2025
1 parent b2c18ca commit 0833d7b
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 61 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: CI

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

env:
FORCE_COLOR: "1"
PIP_DISABLE_PIP_VERSION_CHECK: "1"
PIP_NO_PYTHON_VERSION_WARNING: "1"

jobs:
run-checks:
name: Run linter and tests
runs-on: ubuntu-latest

steps:
- name: Checkout 🛎️
uses: actions/checkout@v4

- name: Set up Python 🐍
uses: actions/setup-python@v5
with:
cache: pip

- name: Install dependencies 📦️
run: |
pip install --upgrade pip
pip install -r requirements/requirements-dev.txt
pip install -e .
- name: Lint 🧹
run: ruff check

- name: Run tests 🧪
run: |
pip install --upgrade pip
pip install -r requirements/requirements-dev.txt
pip install -e .
coverage run -m pytest
- name: Upload coverage data 📤
uses: actions/upload-artifact@v4
with:
name: coverage
path: .coverage
include-hidden-files: true
if-no-files-found: ignore

coverage:
# https://hynek.me/articles/ditch-codecov-python/
name: Generate coverage report
runs-on: ubuntu-latest
needs: run-checks
if: always()

steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up Python 🐍
uses: actions/setup-python@v5
with:
cache: pip

- name: Install uv 🌟
uses: astral-sh/setup-uv@v5
with:
version: ">=0.0.1"

- name: Download coverage data 📥
uses: actions/download-artifact@v4
with:
name: coverage
merge-multiple: true

- name: Generate coverage report 📊
run: |
uv tool install coverage
coverage html --skip-covered --skip-empty
coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
# Generate report again, this time with a fail-under threshold
coverage report --fail-under=80
- name: Upload HTML report if coverage check fails
uses: actions/upload-artifact@v4
with:
name: html-cov-report
path: htmlcov
if: ${{ failure() }}


31 changes: 0 additions & 31 deletions .github/workflows/run-code-checks.yaml

This file was deleted.

30 changes: 0 additions & 30 deletions .github/workflows/run-integration-tests.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![cladetime CI status](https://github.com/reichlab/cladetime/actions/workflows/ci.yaml/badge.svg)

# User Guide

Cladetime is a wrapper around Nextstrain's GenBank-based SARS-CoV-2 genome
Expand Down

0 comments on commit 0833d7b

Please sign in to comment.