Skip to content

arrumando paths 3

arrumando paths 3 #73

Workflow file for this run

on:
push:
paths:
- r-package/**
- .github/workflows/test-coverage.yaml
branches:
- master
- dev
- teste-codecov
pull_request:
paths:
- r-package/**
- .github/workflows/test-coverage.yaml
branches:
- master
- dev
name: test-coverage
jobs:
test-coverage:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
needs: coverage
working-directory: r-package
- name: Test coverage
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
# Fix file paths so Codecov can match them against the repo root.
# covr generates paths relative to the package root (e.g. R/read_amazon.R),
# but Codecov needs paths relative to the git root (e.g. r-package/R/read_amazon.R).
# Also remove the <sources> block so Codecov uses filename directly
# instead of combining <source> + <filename>.
doc <- xml2::read_xml("cobertura.xml")
xml2::xml_remove(xml2::xml_find_all(doc, "/coverage/sources"))
for (cl in xml2::xml_find_all(doc, "//class")) {
fn <- xml2::xml_attr(cl, "filename")
xml2::xml_set_attr(cl, "filename", paste0("r-package/", fn))
}
xml2::write_xml(doc, "cobertura.xml")
shell: Rscript {0}
working-directory: r-package
- uses: codecov/codecov-action@v4
with:
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
files: ./r-package/cobertura.xml
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}
flags: r
name: codecov-r