Skip to content

Instantly share code, notes, and snippets.

@artemklevtsov
Last active January 12, 2024 04:14
Show Gist options
  • Save artemklevtsov/785ed0472c167246e947a75216852e10 to your computer and use it in GitHub Desktop.
Save artemklevtsov/785ed0472c167246e947a75216852e10 to your computer and use it in GitHub Desktop.
Testing R package with GitLab CI (with code coverage)
variables:
CODECOV_TOKEN: "CODECOV_TOKEN_STRING"
_R_CHECK_CRAN_INCOMING_: "false"
_R_CHECK_FORCE_SUGGESTS_: "true"
APT_PKGS: "libcurl4-openssl-dev libssh2-1-dev libssl-dev libxml2-dev zlib1g-dev git"
before_script:
- apt-get update
- apt-get install -y --no-install-recommends ${APT_PKGS}
- apt-get install -y --no-install-recommends qpdf pandoc pandoc-citeproc
- export PATH="/usr/local/lib/R/site-library/littler/examples/:${PATH}"
- echo "options(Ncpus = $(nproc --all))" >> /usr/local/lib/R/etc/Rprofile.site
- install2.r devtools
- r -e 'devtools::install_dev_deps()'
r-release:
stage: test
tags:
- docker
image: rocker/r-ver:latest
script:
- r -e 'devtools::check(check_dir = ".")'
artifacts:
paths:
- "*.Rcheck"
name: logs
when: always
r-devel:
stage: test
tags:
- docker
image: rocker/r-ver:devel
script:
- r -e 'devtools::check(check_dir = ".")'
artifacts:
paths:
- "*.Rcheck"
name: logs
when: always
coverage:
stage: deploy
tags:
- docker
image: rocker/r-ver:latest
when: on_success
only:
- master
script:
- install2.r covr
- r -e 'devtools::install()'
- r -e 'covr::codecov(type = c("tests", "examples"), quiet = FALSE)'
pages:
stage: deploy
tags:
- docker
image: rocker/tidyverse:latest
script:
- install2.r pkgdown drat
- r -e 'devtools::install()'
- r -e 'pkgdown::build_site(override = list(destination = "public"))'
- mkdir -p public/drat
- r -e 'devtools::build(path = ".")'
- r -e 'drat::insertPackage(argv, "public/drat")' $(ls -1t *.tar.gz | head -n 1)
artifacts:
paths:
- public
@jonocarroll
Copy link

@barryrowlingson
Copy link

littler doesn't work well with commandArgs, so the line that inserts the package into the pages using drat fails because it doesn't pick up the tarball as an argument. For example:

$ r -e 'print(commandArgs(TRUE))' $(ls)
character(0)

you can instead use argv or R.utils::commandArgs:

$ r -e 'print(argv)' $(ls L*)
[1] "LICENSE"  "LICENSE~"
$ r -e 'print(R.utils::commandArgs(TRUE))' $(ls L*)
[1] "LICENSE"  "LICENSE~"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment