Site icon R-bloggers

Add a test coverage badge to your R packages using GitHub Actions

[This article was first published on pacha.dev/blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

If this post is useful to you I kindly ask a minimal donation on Buy Me a Coffee. It shall be used to continue my Open Source efforts.

You can send me questions for the blog using this form and subscribe to receive an email when there is a new post.

I added a new package to my GitHub profile, armadillo4r, and no matter the different paths I took, it was impossible to get Codecov to detect the new repository.

After over thirty minutes of trying different things, I gave up and decided to create a GitHub Actions workflow that would generate a test coverage badge for my R packages without needing to set up a separate service like Codecov or Coveralls.

The result is the new package ghacoveragebadge, which you can use to add a test coverage badge to your R packages using GitHub Actions. Here is the badge for the kendallknight package that I updated today:

Test coverage

You can install the development version of ghacoveragebadge like so:

pak::pkg_install("pachadotdev/ghacoveragebadge")

To add a badge like the previous one to your own R package, go to the package’s main directory and run:

library(ghacoveragebadge)
use_github_actions_coverage()

Using this function will create a GitHub Actions workflow file in .github/workflows/coverage.yaml that will run the test coverage analysis and generate the badge every time you push to the main branch or merge a pull request into main.

I hope it’s useful!

To leave a comment for the author, please follow the link and comment on their blog: pacha.dev/blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Exit mobile version