Skip to content

chore: Add new R version (#50) #186

chore: Add new R version (#50)

chore: Add new R version (#50) #186

Workflow file for this run

---
name: test-coverage
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
workflow_dispatch:
workflow_call:
inputs:
use_codecov:
description: Upload code coverage results to codecov.io
required: false
type: boolean
default: false
use_local_setup_action:
description: Use composite .github/actions/setup/action.yaml to setup package specific needs
required: false
type: boolean
default: false
generate_token:
description: Generate token from GitHub app
required: false
type: boolean
default: false
secrets:
TOKEN_APP_ID:
description: ID of the GitHub app used to generate a new token
required: false
TOKEN_APP_PRIVATE_KEY:
description: Private Key for the GitHub app used to generate a new token
required: false
permissions:
contents: read
pull-requests: write
jobs:
test-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Generate custom token
id: generate-token
if: ${{ inputs.generate_token }}
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.TOKEN_APP_ID }}
private-key: ${{ secrets.TOKEN_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- name: Package specific setup
if: ${{ inputs.use_local_setup_action }}
uses: ./.github/actions/setup
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
env:
GITHUB_PAT: ${{ steps.generate-token.outputs.token || secrets.GITHUB_TOKEN }}
with:
extra-packages: |
any::covr
any::xml2
any::dplyr
any::knitr
needs: coverage
- name: Test coverage
run: |
covr::package_coverage() |>
covr::to_cobertura(filename = "cobertura.xml")
xml <- xml2::read_xml("cobertura.xml")
pkg_cov <- xml |>
xml2::xml_find_first("packages/package") |>
xml2::xml_attrs() |>
dplyr::bind_rows()
fnc_cov <- xml |>
xml2::xml_find_first("packages/package") |>
xml2::xml_find_all("classes/class") |>
xml2::xml_attrs() |>
lapply(dplyr::bind_rows)
res <- list(pkg_cov, fnc_cov) |>
dplyr::bind_rows() |>
dplyr::transmute(
Name = dplyr::coalesce(filename, name),
`Coverage (%)` = round(as.numeric(`line-rate`)*100, digits = 2)
) |>
knitr::kable()
c("# Code coverage", res) |>
writeLines(con = "coverage.md")
shell: 'Rscript {0}'
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
header: coverage
path: coverage.md
- name: Upload coverage reports to Codecov
if: ${{ inputs.use_codecov }}
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
files: "./cobertura.xml"
token: ${{ secrets.CODECOV_TOKEN }}
slug: ${{ github.repository }}
verbose: true