From fbd86297bb963385dc3ca2efca6b4d3fbeb6a8f2 Mon Sep 17 00:00:00 2001 From: CJ Yetman Date: Fri, 3 May 2024 11:52:55 +0200 Subject: [PATCH 1/3] use Codecov test-coverage.yaml action and add badge to README --- .github/workflows/test-coverage.yaml | 74 +++++----------------------- 1 file changed, 13 insertions(+), 61 deletions(-) diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index f562f3e..e5f9ed2 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -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 @@ -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: @@ -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( - "
\n", - "Coverage Report\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", - "
" - ) - } - 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: 'Coverage Report' - - - 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 From 7726c6ef637a43a6533368a0d040b2cfdba0b0f1 Mon Sep 17 00:00:00 2001 From: CJ Yetman Date: Fri, 3 May 2024 11:53:24 +0200 Subject: [PATCH 2/3] add badge to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1741663..6b12e1f 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![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?token=D90NZ59L0N)](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) From 171b8b6e61532405c12955168bb19468a97316d0 Mon Sep 17 00:00:00 2001 From: CJ Yetman Date: Fri, 3 May 2024 14:05:10 +0200 Subject: [PATCH 3/3] remove token from badge URL in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b12e1f..9fc4680 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![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?token=D90NZ59L0N)](https://codecov.io/gh/RMI-PACTA/pacta.portfolio.import) +[![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)