hadley / r-pkgs

Building R packages
https://r-pkgs.org
Other
883 stars 627 forks source link

Port "Secrets and tests" PR from style.tidyverse.org to here #567

Closed jennybc closed 2 years ago

jennybc commented 5 years ago

https://github.com/tidyverse/style/pull/110

jennybc commented 5 years ago

Continuous integration

Continuous integration (CI) services, such as Travis CI, can be used to automate important development tasks, like testing and building artefacts. Typically, this goes hand in hand with the practice of hosting development on a site like GitHub.com. Each time the developer pushes new work to GitHub, it triggers a Travis job to run R CMD check or build and deploy a website.

The usethis::use_tidy_ci() function does some basic setup that's relevant to almost any tidyverse or r-lib package. But there's a long tail of more specialized tasks that we implement in a more artisanal way. Here we record some of the common principles and mechanics, since they cannot be (yet?) be automated.

Secrets

Many CI tasks require a piece of secret info that gives, say, Travis the permission to do something on behalf of the developer. Examples: make requests to a Google API, make commits back to the project repo, deploy to a hosting service. Managing these secrets requires care, but it's often worth it to test software more thoroughly or to keep a rendered book or website up-to-date.

What follows in a brain dump

Use the simplest, smallest secret possible.

Store the secret outside the project, i.e. in an env var or in a specific, semi-hidden place at the user-level. For example, store a secret file in some well-named folder below ~/.R/ or define an env var in ~/.Renviron.

Plan for graceful and partial failure when the secret is not available.

Other possible topics

Automatic rendering of

jennybc commented 2 years ago

Hmmm, this cuts across documentation (both examples and vignettes), testing, and CI.

hadley commented 2 years ago

I now touch on @examplesIf in the man/ chapter which I think is all that's needed there.