Kyle Harris
Kyle Harris

Reputation: 43

How to Make azure-pipeline.yml for CI for a R package?

I have been trying to get an Azure pipeline working for my companies internal R packages. I would like the pipeline to:

  1. Check() the package
  2. Run the tests in /testthat
  3. Check code coverage with covr

We use Azure DevOps and use the Azure Repos within that. The few examples I find mainly focus on GitHub solutions. I have tried working with https://github.com/r-lib/r-azure-pipelines, however, with not a lot of knowledge on how to set up pipelines in the first place I find it very difficult to learn and move forward. I have also posted on RStudio Community here, however my current method does not run check(). I want to try to use all the test functionality that Azure DevOps supplies.

Upvotes: 4

Views: 2851

Answers (2)

louish
louish

Reputation: 99

I needed to do something similar and found your RStudio Community post really useful in getting me started with this - thanks for posting. I have now managed to set up a pipeline which:

  1. Checks the package using rcmdcheck (this also runs the testthat tests)
  2. Runs code coverage with covr
  3. Publishes the test results, code coverage report and the check.log file

First, you first need to make sure your testthat.R script runs test_check with the reporter argument specified like so:

test_check("mypackage", reporter = JunitReporter$new(file = "test-result.xml"))


Then the following .yml file should do the trick:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

container:
  image: 'rocker/tidyverse:latest'

variables:
  _R_CHECK_FORCE_SUGGESTS_: false
  MAKEFLAGS: "-j 2"

steps:
- bash: R -q -e 'writeLines(".libPaths(\"~/R-private\")", ".Rprofile"); dir.create("~/R-private", recursive = TRUE); print(Sys.getenv());'
  displayName: "Preliminaries"

- bash: R -q -e 'install.packages(c("covr", "roxygen2", "testthat", "remotes", "rcmdcheck")); remotes::install_deps(dependencies = TRUE);'
  displayName: 'Install Dependencies'

- bash: R -q -e "rcmdcheck::rcmdcheck(args = '--no-manual', error_on = 'warning', check_dir = 'check')"
  displayName: 'Check Package'

- bash: R -q -e 'cov <- covr::package_coverage(); covr::to_cobertura(cov, "coverage.xml")'
  displayName: 'Run Code Coverage'
  condition: succeededOrFailed()

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk'
  inputs:
    packageType: sdk
    version: 2.2.203
    installationPath: $(Agent.ToolsDirectory)/dotnet
  condition: succeededOrFailed()

- task: PublishCodeCoverageResults@1
  displayName: 'Publish Code Coverage'
  inputs:
    codeCoverageTool: 'Cobertura'
    summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml'
  condition: succeededOrFailed()

- task: PublishTestResults@2
  displayName: 'Publish Test Results'
  inputs:
    testResultsFormat: 'JUnit'
    testResultsFiles: '**/test-*.xml'
  condition: succeededOrFailed()

- task: PublishBuildArtifacts@1
  displayName: 'Publish Check log'
  inputs:
    pathToPublish: 'check/mypackage.Rcheck/00check.log' 
    artifactName: check 
  condition: succeededOrFailed()

Upvotes: 3

J. Gaida
J. Gaida

Reputation: 56

Having faced exactly the same challenges with getting Azure pipelines to work with R packages, in two separate organisations, thought I should take the time to share what I've learned along the way.

Please see brief write up and code at https://github.com/jamiegaida/AzurePipelineR

This builds on the great answer above by louish along with other sources. It also runs the lintr package via MegaLinter.

Upvotes: 4

Related Questions