Updated: 2023-05-24
A simple guide to use CI/CD and Code coverage. For CI tasks will be done using
GitHub Actions. Some examples of yaml files for CI tasks can be found here eg.
check-standard.yaml
file.
CI/CD
This is a simple process to implement CI/CD using GitHub Actions with usethis package. Basically the steps here is a summary from Dean Attali with slight changes:
- If you already use
Travis
and want to change to Github Actions, you have to delete all Travis related files and references. Easier to search with projectSPC s p
if you use Doom Emacs. Among those will be:- .travis.yml
- link in README.md file
- in .Rbuildignore file
- I have multiple git accounts as explained here and
usethis
will not able to find the correct repo URL. I have to change theorigin
to Git repo url fromgit@work:helseprofil/myrepo.git
using either terminal orusethis::use_git_remote()
functions. You can check your remote origin withgit remote -v
in the terminal just to check where the repos origin is.
# with R usethis package
usethis::use_git_remote("origin", url = "https://github.com/username/reponame.git", overwrite = TRUE)
# from terminal
git remote add origin https://github.com/username/reponame
- Get the CI url with:
usethis::use_github_action_check_standard()
- Paste the URL to your README file. The URL is allready copy to your clipboard when running step 3.
- You can edit
R-CMD-check.yml
file in folder.github/workflow
to suit your need.
Covr
For Code coverage we will use both covr
and usethis
packages. So don’t
forget to install them first! You can also read general guide from this blog.
This short guide below is especially relevant if you are using Github Action:
- When your package are loaded with
devtools::load_all()
, then runusethis::use_coverage()
to add the batch to yourREADME.Rmd
file. - Run
usethis::use_github_action("test-coverage")
to add filetest-coverage.yaml
in folder./github/workflow
. - If you use a private repos, you need to add your token to codecov.io by
running this code:
covr::codecov(token = "${{secret.CODECOV_TOKEN}}")
- To check, run
covr::report()
. If you get error then you should run in a new session without loading your package. Basically this error happens only to Windows OS as discussed here by Jim Hester.# Run R in your package folder without running devtools::load_all() pkg <- covr::package_coverage(path = getwd()) covr::report(pkg)