Skip to content

Commit ab61ce3

Browse files
committed
add code coverage
1 parent de969dd commit ab61ce3

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

.github/workflows/R-CMD-check.yaml

+26-1
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ jobs:
5151
run: |
5252
brew install --cask xquartz
5353
54+
- name: Whether to use codecov
55+
run: |
56+
echo "USE_R_CODECOV=${{ (runner.os == 'Linux' && matrix.config.r == 'release') && true || false }}" >> $GITHUB_ENV
57+
5458
- uses: r-lib/actions/setup-r-dependencies@HEAD
5559
if: matrix.config.r >= '4.0'
5660
with:
5761
# install the package itself as we register vignette engine
58-
extra-packages: any::rcmdcheck, local::.
62+
extra-packages: any::rcmdcheck, local::. ${{ env.USE_R_CODECOV == 'true' && ', any::covr, any::xml2' || '' }}
5963
needs: check
6064

6165
- uses: r-lib/actions/check-r-package@HEAD
@@ -72,6 +76,27 @@ jobs:
7276
R CMD build litedown
7377
R CMD check --as-cran --no-manual litedown_*.tar.gz
7478
79+
- name: Test coverage
80+
if: success() && env.USE_R_CODECOV == 'true'
81+
run: |
82+
cov = covr::package_coverage(
83+
quiet = FALSE,
84+
clean = FALSE,
85+
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
86+
)
87+
covr::to_cobertura(cov)
88+
shell: Rscript {0}
89+
90+
- uses: codecov/codecov-action@v5
91+
if: env.USE_R_CODECOV == 'true'
92+
with:
93+
# Fail if error if not on PR, or if on PR and token is given
94+
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
95+
files: ./cobertura.xml
96+
plugins: noop
97+
disable_search: true
98+
token: ${{ secrets.CODECOV_TOKEN }}
99+
75100
- uses: actions/checkout@HEAD
76101
if: runner.os == 'macOS'
77102
with:

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
release](https://www.r-pkg.org/badges/version/litedown)](https://cran.r-project.org/package=litedown)
1616
[![litedown on
1717
r-universe](https://yihui.r-universe.dev/badges/litedown)](https://yihui.r-universe.dev/litedown)
18+
[![Codecov test
19+
coverage](https://codecov.io/gh/yihui/litedown/branch/main/graph/badge.svg)](https://app.codecov.io/gh/yihui/litedown?branch=main)
1820

1921
<!-- badges: end -->
2022

0 commit comments

Comments
 (0)