vignettes/usecase-testthat-coverage.Rmd
usecase-testthat-coverage.Rmd
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.
Go to GCP console > Cloud Build > Triggers and link your git repo to Cloud Build.
Create the tests cloudbuild.yml file via
cr_deploy_packagetests()
and generate a build trigger via
its trigger_repo argument:
repo <- "MarkEdmondson1234/googleCloudRunner"
cr_deploy_packagetests(
cloudbuild_file = "testthat.yml",
trigger_repo = cr_buildtrigger_repo(repo,branch = "^master$")
)
If you want to use codecov as well:
_CODECOV_TOKEN
with your token[![codecov](https://codecov.io/gh/MarkEdmondson1234/googleCloudRunner/branch/master/graph/badge.svg)](https://codecov.io/gh/MarkEdmondson1234/googleCloudRunner)
cr_deploy_badger()
cr_buildtrigger_list()
find the build trigger ID for your
test build e.g. 8d99c387-66f1-5ae4-a202-c2cace1fd71f
https://badger-fwjogfwaqq-ew.a.run.app/
- use the
/build/status?project={your-project}&id={the_build_trigger_id}
endpoint to make a URL for a particular build e.g.![CloudBuild](https://badger-fwjogfwaqq-ew.a.run.app/build/status?project=your-project&id=8d99c387-66f1-5ae4-a202-c2cace1fd71f)
Once in your README.md you can use
cr_build_logs_badger()
in your local R session to download
the last build logs.
The below is an example for googleCloudRunner
’s
website:
The example above also adds other substitution variables to help run some of the examples.
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:
cr_deploy_packagetests(
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.