Code Coverage Workflow
This GitHub Actions workflow is designed for testing and generating code coverage reports for an R package. It uses a matrix strategy to test different versions of R and includes options to skip code coverage badge creation. This workflow measures code coverage for unit tests and reports the code coverage as a percentage of the total number of lines covered by unit tests vs. the total number of lines in the codebase.
The [covr
][covr] R package is used to calculate the
coverage.
Report summaries and badges for coverage are generated using a series of other GitHub Actions.
For this workflow to execute successfully, you will need to create an
orphan branch called badges
in your GitHub repository. You
can do that using the following steps:
# Create orphan branch
git checkout --orphan badges
# Back up files
mv .git /tmp/.git-backup
# Remove everything else
rm -rf * .*
# Restore git files
mv /tmp/.git-backup .git
# Create a README file
echo "# Badges" > README.md
# Add, commit and push your new branch
git add . && git commit -m "Init badges" && git push origin badges
Inputs
Workflow Triggers
This workflow is triggered in two ways:
Manual Dispatch: You can manually trigger the workflow using the “workflow_dispatch” event. When triggered manually, you can specify the R version and choose to skip code coverage badge creation.
Workflow Call: The workflow can also be triggered by another workflow using the “workflow_call” event. The R version and skip-coverage-badges options are inputs for this event.
Workflow Setup
- Name: Code Coverage
- Concurrency: Code coverage jobs are organized by the pull request number or branch.
- Cancel-in-progress: Allows canceling in-progress code coverage jobs.
Job: coverage
This job verifies templates in the R package. It runs on a docker
container instance using admiralci
images
(ghcr.io/pharmaverse/admiralci-${{ inputs.r-version }}:latest
)
for the R environment.
Steps
Boilerplate Steps
- Get branch names: Retrieves branch names for further processing.
- Checkout repo (PR): Checks out the repository for pull requests.
- Checkout repository: Checks out the repository for non-pull request events.
- Normalize inputs: Normalizes input values, including determining the R version.
Staged Dependencies
- Restore cache: Restores the cache for staged dependencies.
- Setup Pandoc: Sets up Pandoc for documentation rendering.
- Run Staged dependencies: Runs the staged dependencies action.
- Install dependencies from DESCRIPTION: install dependencies from DESCRIPTION (in case of missing dependencies in parent admiralci docker image)
Run Coverage
- Run coverage: Runs code coverage tests, generates coverage reports, and outputs the coverage percentage.
Check Coverage Reports
Check whether coverage reports exist: Checks for the existence of coverage reports.
Set coverage percentage as output: Sets the coverage percentage as an output variable.
Generate Coverage Summary Report: Generates a coverage summary report, adds badges, and uploads the report for review.