This tests an R package each time you commit, and uploads the test coverage results to Codecov

cr_deploy_packagetests(
  steps = NULL,
  cloudbuild_file = "cloudbuild-tests.yml",
  env = c("NOT_CRAN=true"),
  test_script = NULL,
  codecov_script = NULL,
  codecov_token = "$_CODECOV_TOKEN",
  build_image = "gcr.io/gcer-public/packagetools:latest",
  create_trigger = c("file", "inline", "no"),
  trigger_repo = NULL,
  ...,
  footer = TRUE
)

Arguments

steps

extra steps to run before the cr_buildstep_packagetests steps run (such as decryption of auth files)

cloudbuild_file

The cloudbuild yaml file to write to. See create_trigger

env

Environment arguments to be set during the test script runs

test_script

The script that will call rcmdcheck to perform tests. If NULL a default script is used in system.file("r_buildsteps", "devtools_tests.R", package="googlecloudRunner")

codecov_script

The script that will call codecov to perform coverage. If NULL a default script is used in system.file("r_buildsteps", "codecov_tests.R", package="googleCloudRunner")

codecov_token

If using codecov, supply your codecov token here.

build_image

The docker image that will be used to run the R code for the test scripts

create_trigger

If creating a trigger, whether to create it from the cloudbuild_file or inline

trigger_repo

If not NULL, a cr_buildtrigger_repo where a buildtrigger will be created via cr_buildtrigger

...

Arguments passed on to cr_build_make

yaml

A Yaml object created from cr_build_yaml or a file location of a .yaml/.yml cloud build file

artifacts

Artifacts that may be built via cr_build_yaml_artifact

options

Options to pass to a Cloud Build

availableSecrets

Secret Manager objects built by cr_build_yaml_secrets

logsBucket

The gs:// location of a bucket to put logs in

source

A Source object specifying the location of the source files to build, usually created by cr_build_source

timeout

Amount of time that this build should be allowed to run, to second

images

A list of images to be pushed upon the successful completion of all build

substitutions

Substitutions data for `Build` resource

serviceAccount

service account email to be used for the build

footer

flag passed to cr_build_write, indicating if a footer in the YAML should be added with the creation date/time.

Details

The trigger repository needs to hold an R package configured to do tests upon.

For GitHub, the repository will need to be linked to the project you are building within, via https://console.cloud.google.com/cloud-build/triggers/connect

If your tests need authentication details, add these via cr_buildstep_secret to the steps argument, which will prepend decrypting the authentication file before running the tests.

If you want codecov to ignore some files then also deploy a .covrignore file to your repository - see covr website at https://covr.r-lib.org/ for details.

See also

Create your own custom deployment using cr_buildstep_packagetests which this function uses with some defaults

cr_buildstep_packagetests

Other Deployment functions: cr_deploy_docker_trigger(), cr_deploy_docker(), cr_deploy_pkgdown(), cr_deploy_run_website(), cr_deploy_run(), cr_deploy_r()

Examples


# create a local cloudbuild.yml file for packagetests
pd <- cr_deploy_packagetests(create_trigger = "no")
#>  2022-03-26 19:55:58 > Writing to cloudbuild-tests.yml
#> 
#>  Complete deployment of tests Cloud Build yaml:
#>  Go to https://console.cloud.google.com/cloud-build/triggers and
#>   make a build trigger pointing at this file in your repo:
#>   cloudbuild-tests.yml 
#>  Build Trigger substitution variable settings:
#>   _CODECOV_TOKEN = your-codecov-token
#>   Ignored files filter (glob): docs/** and vignettes/**
pd
#> ==cloudRunnerYaml==
#> steps:
#> - name: gcr.io/gcer-public/packagetools:latest
#>   args:
#>   - Rscript
#>   - -e
#>   - |-
#>     message("cran mirror: ", getOption("repos"))
#>     remotes::install_deps(dependencies = TRUE)
#>     rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "warning")
#>   env:
#>   - NOT_CRAN=true
#> - name: gcr.io/gcer-public/packagetools:latest
#>   args:
#>   - Rscript
#>   - -e
#>   - |-
#>     remotes::install_deps(dependencies = TRUE)
#>     remotes::install_local()
#>     cv <- covr::package_coverage()
#>     up <- covr::codecov(coverage = cv,
#>                   commit = "$COMMIT_SHA", branch = "$BRANCH_NAME",
#>                   quiet = FALSE)
#>     up
#>     if (!up$uploaded) stop("Error uploading codecov reports")
#>   env:
#>   - NOT_CRAN=true
#>   - CODECOV_TOKEN=$_CODECOV_TOKEN
#>   - CI=true
#>   - GCB_PROJECT_ID=$PROJECT_ID
#>   - GCB_BUILD_ID=$BUILD_ID
#>   - GCB_COMMIT_SHA=$COMMIT_SHA
#>   - GCB_REPO_NAME=$REPO_NAME
#>   - GCB_BRANCH_NAME=$BRANCH_NAME
#>   - GCB_TAG_NAME=$TAG_NAME
#>   - GCB_HEAD_BRANCH=$_HEAD_BRANCH
#>   - GCB_BASE_BRANCH=$_BASE_BRANCH
#>   - GCB_HEAD_REPO_URL=$_HEAD_REPO_URL
#>   - GCB_PR_NUMBER=$_PR_NUMBER

# add a decryption step for an auth file
cr_deploy_packagetests(
  steps = cr_buildstep_secret("my_secret", "auth.json"),
  env = c("NOT_CRAN=true", "MY_AUTH_FILE=auth.json"),
  timeout = 1200,
  create_trigger = "no"
)
#>  2022-03-26 19:55:58 > Writing to cloudbuild-tests.yml
#> 
#>  Complete deployment of tests Cloud Build yaml:
#>  Go to https://console.cloud.google.com/cloud-build/triggers and
#>   make a build trigger pointing at this file in your repo:
#>   cloudbuild-tests.yml 
#>  Build Trigger substitution variable settings:
#>   _CODECOV_TOKEN = your-codecov-token
#>   Ignored files filter (glob): docs/** and vignettes/**
#> ==cloudRunnerYaml==
#> steps:
#> - name: gcr.io/cloud-builders/gcloud
#>   entrypoint: bash
#>   args:
#>   - -c
#>   - gcloud secrets versions access latest --secret=my_secret  > auth.json
#> - name: gcr.io/gcer-public/packagetools:latest
#>   args:
#>   - Rscript
#>   - -e
#>   - |-
#>     message("cran mirror: ", getOption("repos"))
#>     remotes::install_deps(dependencies = TRUE)
#>     rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "warning")
#>   env:
#>   - NOT_CRAN=true
#>   - MY_AUTH_FILE=auth.json
#> - name: gcr.io/gcer-public/packagetools:latest
#>   args:
#>   - Rscript
#>   - -e
#>   - |-
#>     remotes::install_deps(dependencies = TRUE)
#>     remotes::install_local()
#>     cv <- covr::package_coverage()
#>     up <- covr::codecov(coverage = cv,
#>                   commit = "$COMMIT_SHA", branch = "$BRANCH_NAME",
#>                   quiet = FALSE)
#>     up
#>     if (!up$uploaded) stop("Error uploading codecov reports")
#>   env:
#>   - NOT_CRAN=true
#>   - MY_AUTH_FILE=auth.json
#>   - CODECOV_TOKEN=$_CODECOV_TOKEN
#>   - CI=true
#>   - GCB_PROJECT_ID=$PROJECT_ID
#>   - GCB_BUILD_ID=$BUILD_ID
#>   - GCB_COMMIT_SHA=$COMMIT_SHA
#>   - GCB_REPO_NAME=$REPO_NAME
#>   - GCB_BRANCH_NAME=$BRANCH_NAME
#>   - GCB_TAG_NAME=$TAG_NAME
#>   - GCB_HEAD_BRANCH=$_HEAD_BRANCH
#>   - GCB_BASE_BRANCH=$_BASE_BRANCH
#>   - GCB_HEAD_REPO_URL=$_HEAD_REPO_URL
#>   - GCB_PR_NUMBER=$_PR_NUMBER
#> timeout: 1200s


# creating a buildtrigger repo for trigger_repo
repo <- cr_buildtrigger_repo("MarkEdmondson1234/googleCloudRunner",
  branch = "master"
)
if (FALSE) {

# will create the file in the repo, and point a buildtrigger at it
cr_deploy_packagetests(create_trigger = "file", trigger_repo = repo)


# will make an inline build within a buildtrigger
cr_deploy_packagetests(create_trigger = "inline", trigger_repo = repo)
}

unlink("cloudbuild-tests.yml")