Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code coverage check to CI #78

Merged
merged 6 commits into from
Jan 6, 2025
Merged

Conversation

bsweger
Copy link
Collaborator

@bsweger bsweger commented Jan 2, 2025

Resolves #43

Background

Thus far, Cladetime hasn't checked a test coverage metric as part of its CI process. This PR adds such a check, using a technique adopted from this writeup: https://hynek.me/articles/ditch-codecov-python/

Approach

The advantage of the above approach is that it doesn't require a third-party service such as codecov. At a high-level, the process looks like this:

Updates to the existing run-checks job:

  1. Use Python's coverage package to generate coverage metrics
  2. Upload the metrics file (.coverage) as a GitHub artifact

New coverage job:

  1. Download the coverage artifact
  2. Generate a coverage report and add it to the action's summary
  3. If overall coverage is < 80%, fail the job and upload an HTML version of the report as a GitHub artifact

Output

The coverage report is in the detailed output of the CI / Generate Coverage Report check below. A more human-readable output is in the action's summary: https://github.com/reichlab/cladetime/actions/runs/12588558317

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).
The coverage job will fail if if code coverage is >= 80%
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).
This is a common pattern I've seen when looking at other python projects
(and also, the workflow does more than run tests now)
uses: actions/download-artifact@v4
with:
name: coverage
merge-multiple: true
Copy link
Collaborator Author

@bsweger bsweger Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're not expecting multiple coverage files yet (as we don't do any matrix-style testing), but leaving this here as a placeholder/nudge/reminder to

matthewcornell
matthewcornell previously approved these changes Jan 6, 2025
Copy link
Member

@matthewcornell matthewcornell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool! nice work. one typo found

# Generate report again, this time with a fail-under threshold
coverage report --fail-under=80

- name: Upload HTML report if coverage check faileds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

@bsweger bsweger merged commit 0833d7b into main Jan 6, 2025
3 checks passed
@bsweger bsweger deleted the bsweger/add-coverage-report/43 branch January 6, 2025 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add test coverage report to cladetime
2 participants