Feat: migration #3
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# Workflow adjusted from usethis::use_github_action("test-coverage") to just report coverage internally and not to publish to codecov | |
on: | |
push: | |
branches: | |
- main | |
- master | |
pull_request: | |
branches: | |
- main | |
- master | |
permissions: | |
contents: read | |
pull-requests: write | |
name: test-coverage-internal | |
jobs: | |
test-coverage-internal: | |
runs-on: ubuntu-latest | |
env: | |
POSTGRES_PW: ${{secrets.TEST_POSTGRES_DB_PW}} | |
GITHUB_PAT: ${{ secrets.ACTION_PAT || secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: r-lib/actions/setup-r@v2 | |
with: | |
use-public-rspm: true | |
- uses: r-lib/actions/setup-r-dependencies@v2 | |
with: | |
extra-packages: | | |
any::covr | |
any::xml2 | |
any::dplyr | |
any::knitr | |
needs: coverage | |
- name: Start local postgres server with Docker | |
run: | | |
docker pull postgres | |
docker run --name my-postgres --env POSTGRES_PASSWORD=${{env.POSTGRES_PW}} --publish 5432:5432 --detach postgres | |
- 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: Stop and remove postgres server | |
run: | | |
docker stop my-postgres | |
docker remove my-postgres | |
- 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 |