From b462d8859f727e60790d2190b00b0f9cab705c3d Mon Sep 17 00:00:00 2001 From: IlyaZar Date: Wed, 9 Aug 2023 12:06:39 +0200 Subject: [PATCH 1/2] feature: use test coverage for current git-branch - to clearly show what the testing coverage is on each branch via the badge - `README.Rmd` is altered to programatically retrieve the current git branch which automatically uses the correct coverage results from https://about.codecov.io/ Refs: #1086 --- README.Rmd | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.Rmd b/README.Rmd index 65253ad5..314ae7b2 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,7 +17,23 @@ knitr::opts_chunk$set( -[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html) [![R-CMD-check](https://github.com/ThinkR-open/golem/workflows/R-CMD-check/badge.svg)](https://github.com/ThinkR-open/golem/actions) [![Coverage status](https://codecov.io/gh/ThinkR-open/golem/branch/master/graph/badge.svg)](https://codecov.io/github/ThinkR-open/golem?branch=master) [![CRAN status](https://www.r-pkg.org/badges/version/golem)](https://cran.r-project.org/package=golem) +```{r echo = FALSE} +name_branch <- system("git symbolic-ref --short HEAD", intern = TRUE) +link_to_branch_svg <- paste0( + "https://codecov.io/gh/ThinkR-open/golem/branch/", + name_branch, + "/graph/badge.svg") +link_to_branch_html <- paste0( + "https://app.codecov.io/github/ThinkR-open/golem/tree/", + name_branch) +``` + +```{r, echo = FALSE, results = "asis"} +cat('[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html)') +cat('[![R-CMD-check](https://github.com/ThinkR-open/golem/workflows/R-CMD-check/badge.svg)](https://github.com/ThinkR-open/golem/actions)') +cat(paste0("\n[![Coverage status](", link_to_branch_svg, ")](", link_to_branch_html, ")")) +cat('[![CRAN status](https://www.r-pkg.org/badges/version/golem)](https://cran.r-project.org/package=golem)') +``` From 51113f0c6abd4432a7409563cf7ee0195fb40243 Mon Sep 17 00:00:00 2001 From: IlyaZar Date: Wed, 9 Aug 2023 18:56:26 +0200 Subject: [PATCH 2/2] feat: add workflow to rebuild README.Rmd automatically - when CI rebuilds README.Rmd it should also use the badge of the git-branch so the codecov gets an update --- .github/workflows/render-rmarkdown.yaml | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/render-rmarkdown.yaml diff --git a/.github/workflows/render-rmarkdown.yaml b/.github/workflows/render-rmarkdown.yaml new file mode 100644 index 00000000..67efe207 --- /dev/null +++ b/.github/workflows/render-rmarkdown.yaml @@ -0,0 +1,38 @@ +# 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 + +# Controls when the action will run: for now dev and master +on: + push: + branches: [master, dev] + +name: render-rmarkdown + +jobs: + render-rmarkdown: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + # Checks-out golem repo so the job can access it + - name: Checkout repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: r-lib/actions/setup-pandoc@v2 + - uses: r-lib/actions/setup-r@v2 + - uses: r-lib/actions/setup-renv@v2 + + # install CRAN packages used inside README.Rmd + - name: install required packages + run: Rscript -e 'install.packages(c("rmarkdown", "covr"))' + # Render READEME.md using rmarkdown + - name: render README + run: Rscript -e 'rmarkdown::render("README.Rmd", output_format = "md_document")' + - name: Render Rmarkdown files and Commit Results + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git add README.md + git commit -m "Re-build README.md" || echo "No changes to commit" + git push origin || echo "No changes to commit"