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

use Codecov test-coverage.yaml action and add badge to README #92

Merged
merged 3 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 13 additions & 61 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main]
branches: [main, master]

name: test-coverage

Expand All @@ -11,11 +13,10 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: r-lib/actions/setup-r@v2
with:
Expand All @@ -26,71 +27,22 @@ jobs:
extra-packages: any::covr
needs: coverage

- name: test-coverage
id: coverage
- name: Test coverage
run: |
markdown_cov_diff <- function(head, main) {
group <- "filename"
by = "line"
sig_num <- 2

tally_head <- covr::tally_coverage(head, by = by)
tally_main <- covr::tally_coverage(main, by = by)

percs_head <- tapply(tally_head$value, tally_head[[group]], FUN = function(x) sum(x > 0) / length(x) * 100)
percs_main <- tapply(tally_main$value, tally_main[[group]], FUN = function(x) sum(x > 0) / length(x) * 100)
percs_diff <- unname(percs_head - percs_main)

ttl_perc_head <- covr::percent_coverage(tally_head, by = by)
ttl_perc_main <- covr::percent_coverage(tally_main, by = by)
ttl_perc_diff <- ttl_perc_head - ttl_perc_main

percs_head <- format(percs_head, digits = sig_num)
percs_main <- format(percs_main, digits = sig_num)
percs_diff <- paste0(ifelse(percs_diff < 0, ":small_red_triangle_down: ", ""), ifelse(percs_diff > 0, ":arrow_up: ", ""), format(percs_diff, digits = sig_num))

ttl_perc_head <- format(ttl_perc_head, digits = sig_num)
ttl_perc_main <- format(ttl_perc_main, digits = sig_num)
ttl_perc_diff <- paste0(ifelse(ttl_perc_diff < 0, ":small_red_triangle_down: ", ""), ifelse(ttl_perc_diff > 0, ":arrow_up: ", ""), format(ttl_perc_diff, digits = sig_num))

paste0(
"<details>\n",
"<summary>Coverage Report</summary>\n\n",
"|file|head|main|diff|\n|",
" :-- | --: | --: | --: |\n",
paste0("|Overall|", ttl_perc_head, "%|", ttl_perc_main, "%|", ttl_perc_diff, "%|", "\n"),
paste0("|", names(percs_head), "|", percs_head, "%|", percs_main, "%|", percs_diff, "%|", collapse = "\n"),
"\n",
"</details>"
)
}
head <- covr::package_coverage()
system2("git", c("checkout", "main"))
main <- covr::package_coverage()
writeLines(markdown_cov_diff(head, main), "coverage-report.md")
token <- Sys.getenv("CODECOV_TOKEN", "")
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package"),
token = if (token != "") token
)
shell: Rscript {0}

- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '<summary>Coverage Report</summary>'

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: 'coverage-report.md'
edit-mode: replace

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- badges: start -->
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![R-CMD-check](https://github.com/RMI-PACTA/pacta.portfolio.import/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/RMI-PACTA/pacta.portfolio.import/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/gh/RMI-PACTA/pacta.portfolio.import/graph/badge.svg)](https://codecov.io/gh/RMI-PACTA/pacta.portfolio.import)
[![CRAN status](https://www.r-pkg.org/badges/version/pacta.portfolio.import)](https://CRAN.R-project.org/package=pacta.portfolio.import)
[![pacta.portfolio.import status badge](https://rmi-pacta.r-universe.dev/badges/pacta.portfolio.import)](https://rmi-pacta.r-universe.dev/ui#package:pacta.portfolio.import)
<!-- badges: end -->
Expand Down