简体   繁体   English

GitLab CI与r testthat包

[英]GitLab CI with r testthat package

Can anyone run testthat tests for a minimal R package using GitLab.com continuous integration tools? 任何人都可以使用GitLab.com持续集成工具运行testthat测试最小R包吗? My attempt: 我的尝试:
https://gitlab.com/djchapman/CI_example https://gitlab.com/djchapman/CI_example
This is the .gitlab-CI.yml text I am using, 这是我正在使用的.gitlab-CI.yml文本,

image: rocker/rstudio
test:
   script:
    - R -e 'install.packages(c("devtools", "testthat"))'
    - R CMD build . --no-build-vignettes --no-manual
    - PKG_FILE_NAME=$(ls -1t *.tar.gz | head -n 1)
    - R CMD check "${PKG_FILE_NAME}" --no-build-vignettes --no-manual
    - R -e 'devtools::test()'

It is adapted from this website. 它改编自这个网站。 I realize that devtools has dependencies which may need to be included as packages are installed, and I tried that, but the libraries for git2r didn't seem to install correctly, and now I wonder if I'm going about it wrong. 我意识到devtools有依赖关系,可能需要在安装包时包含,我尝试了,但是git2r的库似乎没有正确安装,现在我想知道我是不是错了。 Thanks. 谢谢。

You do not need to run the tests via devtools since R CMD check does that already. 您不需要通过devtools运行测试,因为R CMD check已经完成了。 The following should work: 以下应该有效:

image: rocker/rstudio
test:
   script:
    - R -e 'install.packages(c("testthat"))'
    - R CMD build . --no-build-vignettes --no-manual
    - PKG_FILE_NAME=$(ls -1t *.tar.gz | head -n 1)
    - R CMD check "${PKG_FILE_NAME}" --no-build-vignettes --no-manual

Alternatively you could use an image that allows for binary installs: 或者,您可以使用允许二进制安装的映像:

image: rocker/r-base
test:
   script:
    - apt-get update
    - apt-get install --yes --no-install-recommends r-cran-testthat r-cran-devtools
    - R -e "devtools::install_deps()"
    - R CMD build . --no-build-vignettes --no-manual
    - PKG_FILE_NAME=$(ls -1t *.tar.gz | head -n 1)
    - R CMD check "${PKG_FILE_NAME}" --no-build-vignettes --no-manual

This is useful if you have dependencies that have not been packaged for Debian, or if you don't want to update your CI script when you add a new dependency. 如果您具有尚未为Debian打包的依赖项,或者在添加新依赖项时不想更新CI脚本,则此选项非常有用。

For me this didn't work as expected. 对我来说,这没有按预期工作。 I found out that the problem was I had vignettes. 我发现问题是我有小插曲。 Using the following content of my .gitlab-ci.yml , I worked around that problem: 使用我的.gitlab-ci.yml的以下内容,我解决了这个问题:

image: rocker/r-base
gitlab:
   script:
    - apt-get update
    # install dependencies for package
    - apt-get install --yes --no-install-recommends r-cran-xml2 r-cran-testthat r-cran-devtools
    - R -e 'devtools::install_deps(dependencies = c("Depends", "Imports", "Suggests"))'
    # remove vignettes folder and get VignetteBuilder field out of DESCRIPTION file
    - rm -rf vignettes
    - R -e 'd <- read.dcf("DESCRIPTION"); d[, colnames(d) == "VignetteBuilder"] <- NA; write.dcf(d, "DESCRIPTION")'
    - R CMD build . --no-build-vignettes --no-manual
    - PKG_FILE_NAME=$(ls -1t *.tar.gz | head -n 1)
    - R CMD check "${PKG_FILE_NAME}" --no-build-vignettes --no-manual --as-cran
    # update code coverage
    - apt-get install --yes git
    - R -e "covr::codecov(token = 'mytoken')"

It removes the vignettes folder and removes the VignetteBuilder field from the DESCRIPTION file before it starts building. 它会删除vignettes文件夹,并在开始构建之前从DESCRIPTION文件中删除VignetteBuilder字段。 Quite convenient, although I now cannot test the contents of it. 相当方便,虽然我现在无法测试它的内容。

After a while I found out that covr::codecov() works really well if you give the token as input (from https://codecov.io/gl/yourname/yourproject/settings ) and install git on beforehand. 过了一会儿,我发现如果你把令牌作为输入(来自https://codecov.io/gl/yourname/yourproject/settings )并且预先安装git ,那么covr::codecov()效果非常好。

Hope this helps others too. 希望这也有助于其他人。 GitLab is a great replacement for GitHub. GitLab是GitHub的绝佳替代品。
It's 2018 and some things have changed . 这是2018年, 有些事情发生了变化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM