This workflow will run the package tests you have upon each commit to your git repo.

You can also optionally submit those test results to codecov via the excellent covr R package, helping you see which code your tests actually test. This is what creates this badge for this package:


If you do not need online authentication for your tests, then this is only a case of deploying the premade default cloudbuild.yml file via cr_deploy_packagetests().

The below assumes you have created tests for your package.

  1. Go to GCP console > Cloud Build > Triggers and link your git repo to Cloud Build.

  2. Create the tests cloudbuild.yml file via cr_deploy_packagetests() and generate a build trigger via its trigger_repo argument:

repo <- "MarkEdmondson1234/googleCloudRunner"

  cloudbuild_file = "testthat.yml",
  trigger_repo = cr_buildtrigger_repo(repo,branch = "^master$")
  1. Add and commit the cloudbuild.yml file to your git repository

Code Coverage

If you want to use codecov as well:

  1. Generate a Codecov token on its website and link it to your git repository
  2. Edit the Build Trigger for your git repository to add a substitution variable _CODECOV_TOKEN with your token
  3. Run a build and you should start to see Codecov reports after a successful test
  4. Add the Codecov badge to your README e.g.

Readme Cloud Build Badge

  1. If you haven’t already, deploy a Badger Cloud run app in your project (you can use this app for multiple buildtriggers) via cr_deploy_badger()
  2. Either in the GCP console or using cr_buildtrigger_list() find the build trigger ID for your test build e.g. 8d99c387-66f1-5ae4-a202-c2cace1fd71f
  3. The Badger app will have a URL like - use the /build/status?project={your-project}&id={the_build_trigger_id} endpoint to make a URL for a particular build e.g.
  1. Add the badge to your

Once in your you can use cr_build_logs_badger() in your local R session to download the last build logs.

Example trigger

The below is an example for googleCloudRunner’s website:

The example above also adds other substitution variables to help run some of the examples.

Authenticated tests

You can customise the deployment more by using cr_buildstep_packagetests() in your own custom build files.

For googleCloudRunner and API packages in general, an authentication key is needed to run online tests. This authentication key can be encrypted via Google Secret Manager by adding a decryption step to your tests via cr_buildstep_secret() - its usually only a case of uploading your auth file:

In that case, the decryption step needs to occur before the tests run, which you can do by supplying cr_buildstep_secret() to cr_deploy_packagetests().

You will also want to use that auth file somehow, in the below example it is placed in an environment argument that your tests use to find the authentication file:

  steps = cr_buildstep_secret("my_secret", "auth.json"),
  env = c("NOT_CRAN=true", "MY_AUTH_FILE=auth.json")

Use the resulting cloudbuild.yml file in the same manner as unauthenticated tests.