Skip to content

Commit

Permalink
Add macro do_drat() (#221)
Browse files Browse the repository at this point in the history
* add macro `do_drat()`

* add vignette "troubleshooting"

* add {desc} to suggests
  • Loading branch information
pat-s authored Jan 18, 2020
1 parent dfd3250 commit 2d16e0c
Show file tree
Hide file tree
Showing 18 changed files with 352 additions and 23 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Suggests:
callr,
circle,
covr,
desc,
devtools,
drat,
fansi,
Expand Down Expand Up @@ -105,6 +106,7 @@ Collate:
'macro-package-checks.R'
'macro-pkgdown.R'
'macro-bookdown.R'
'macro-drat.R'
'mock.R'
'print.R'
'repo.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export(ci_on_circle)
export(ci_on_travis)
export(deploy)
export(do_bookdown)
export(do_drat)
export(do_package_checks)
export(do_pkgdown)
export(dsl_get)
Expand Down
89 changes: 89 additions & 0 deletions R/macro-drat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#' do_drat
#'
#' The [do_drat()] macro adds the necessary steps for building
#' and deploying a drat repository to host R package sources.
#'
#' @include macro.R
#' @include macro-package-checks.R
#' @name macro
NULL

#' Build and deploy drat repository
#'
#' @description
#' `do_drat()` builds and deploys R packages to a drat repository and adds
#' default steps to the `"install"`, `"before_deploy"` and `"deploy"` stages:
#'
#' @inheritParams step_add_to_drat
#' @inheritParams step_setup_ssh
#' @inheritParams step_setup_push_deploy
#' @inheritParams step_do_push_deploy
#' @param path,branch By default, this macro deploys the `"master"` branch
#' of the drat repository. An alternative option is `"gh-pages"`.
#' @param ssh_key_name `string`\cr
#' The name of the private SSH key which should be used for deployment to the
#' drat repo.
#'
#' @section Deployment: Deployment can only happen to the `master` or
#' `gh-pages` branch because the Github Pages functionality from Github is
#' used to access the drat repository later on. You need to enable this
#' functionality when creating the drat repository on Github via `Settings ->
#' Github pages` and set it to the chosen setting here.
#'
#' To build and deploy Windows binaries, builds on Travis CI with deployment
#' permissions need to be triggered. To build and deploy macOS binaries,
#' builds on Travis CI with deployment permissions need to be triggered. Have
#' a look at \url{https://docs.ropensci.org/tic/articles/deployment.html} for
#' more information and instructions.
#' @family macros
#' @export
#' @examples
#' dsl_init()
#'
#' do_drat()
#'
#' dsl_get()
do_drat <- function(repo_slug = NULL,
orphan = FALSE,
checkout = TRUE,
path = "~/git/drat",
branch = "master",
remote_url = NULL,
commit_message = NULL,
commit_paths = ".",
ssh_key_name = "id_rsa",
deploy_dev = FALSE) {

#' @description
#' 1. [step_setup_ssh()] in the `"before_deploy"` to setup
#' the upcoming deployment
get_stage("before_deploy") %>%
add_step(step_setup_ssh(name = ssh_key_name))

#' 1. [step_setup_push_deploy()] in the `"before_deploy"` stage
#' (if `deploy` is set),
get_stage("before_deploy") %>%
add_step(step_setup_push_deploy(
path = !!enquo(path),
branch = !!enquo(branch),
remote_url = paste0("git@github.com:", repo_slug, ".git"),
orphan = !!enquo(orphan),
checkout = !!enquo(checkout)
))

#' 1. [step_add_to_drat()] in the `"deploy"`
get_stage("deploy") %>%
add_step(step_add_to_drat(
repo_slug = repo_slug, deploy_dev = deploy_dev
))

#' 1. [step_do_push_deploy()] in the `"deploy"` stage.
get_stage("deploy") %>%
add_step(step_do_push_deploy(
path = !!enquo(path),
commit_message = !!enquo(commit_message),
commit_paths = !!enquo(commit_paths)
))

dsl_get()
}
52 changes: 39 additions & 13 deletions R/steps-drat.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,53 @@ AddToDrat <- R6Class(
inherit = TicStep,

public = list(
initialize = function(repo_slug = NULL, deploy_dev = FALSE) {
private$repo_slug <- repo_slug
private$deploy_dev <- deploy_dev
},

prepare = function() {
verify_install(c("drat", "remotes", "knitr", "withr", "pkgbuild"))
verify_install(c(
"drat", "remotes", "rmarkdown", "withr", "pkgbuild",
"desc", "usethis"
))
},

run = function() {
path <- pkgbuild::build(binary = (getOption("pkgType") != "source"))
drat::insertPackage(path)
withr::with_dir(
"~/git/drat",
if (file.exists("index.Rmd")) {
knitr::knit("index.Rmd", "index.md")
}
)
if (is.null(private$repo_slug)) {
stopc("A repository to deploy to is required.")
}

ver <- desc::desc_get_version()
if (length(unlist(ver)) > 3 && private$deploy_dev == FALSE) {
cli_alert_info("Detected dev version of current package. Not building
package binaries because {.code deploy_dev = FALSE} is
set.", wrap = FALSE)
return(invisible())
}
else {
path <- pkgbuild::build(binary = (getOption("pkgType") != "source"))
drat::insertPackage(path)
}
}
),

private = list(
repo_slug = NULL,
deploy_dev = NULL
)
)

#' Step: Add built package to a drat
#'
#' Builds a package (binary on OS X or Windows) and inserts it into an existing
#' \pkg{drat} repository via [drat::insertPackage()].
#' Also knits the `index.Rmd` file of the drat if it exists.
#'
#' @param repo_slug `[string]`\cr
#' The name of the drat repository to deploy to in the form `:owner/:repo`.
#' @param deploy_dev `[logical]`\cr
#' Should development versions of packages also be deployed to the drat repo?
#' By default only "major", "minor" and "patch" releases are build and
#' deployed.
#' @family steps
#' @export
#' @examples
Expand All @@ -35,6 +59,8 @@ AddToDrat <- R6Class(
#' add_step(step_add_to_drat())
#'
#' dsl_get()
step_add_to_drat <- function() {
AddToDrat$new()
step_add_to_drat <- function(repo_slug = NULL, deploy_dev = FALSE) {
AddToDrat$new(
repo_slug = repo_slug, deploy_dev = deploy_dev
)
}
8 changes: 6 additions & 2 deletions R/steps-ssh.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ InstallSSHKeys <- R6Class(
public = list(
initialize = function(name = "TRAVIS_DEPLOY_KEY") {
# for backward comp, if "id_rsa" exists we take this key
private$name <- compat_ssh_key(name)
private$name <- compat_ssh_key(name = name)
},

run = function() {
Expand Down Expand Up @@ -106,11 +106,12 @@ InstallSSHKeys <- R6Class(
},

check = function() {

# only if non-interactive and TRAVIS_DEPLOY_KEY env var is available
if (!ci_is_interactive()) {
if (!ci_can_push(private$name)) {
cli_alert_danger("Deployment was requested but the build is not able to
deploy. We checked for env var {.var {name}} but could
deploy. We checked for env var {.var {private$name}} but could
not find it as an env var in the current build.
Double-check if it exists. Calling
{.fun travis::use_travis_deploy} may help resolving
Expand Down Expand Up @@ -249,12 +250,15 @@ SetupSSH <- R6Class(

check = function() {
if (!private$install_ssh_keys$check()) {
cli_alert_info("{.fun SetupSSH$check}: {.fun install_ssh_keys} failed.")
return(FALSE)
}
if (!private$add_to_known_hosts$check()) {
cli_alert_info("{.fun SetupSSH$check}: {.fun add_to_known_hosts} failed.") # nolint
return(FALSE)
}
if (!private$test_ssh$check()) {
cli_alert_info("{.fun SetupSSH$check}: {.fun test_ssh} failed.")
return(FALSE)
}
TRUE
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The most important improvements over existing solutions are:

{tic} can be installed from GitHub with:

``` r
```r
remotes::install_github("ropensci/tic")
```

Expand Down
24 changes: 22 additions & 2 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@
},
"sameAs": "https://CRAN.R-project.org/package=covr"
},
{
"@type": "SoftwareApplication",
"identifier": "desc",
"name": "desc",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"sameAs": "https://CRAN.R-project.org/package=desc"
},
{
"@type": "SoftwareApplication",
"identifier": "devtools",
Expand Down Expand Up @@ -402,7 +414,7 @@
],
"releaseNotes": "https://github.com/krlmlr/tic/blob/master/NEWS.md",
"readme": "https://github.com/krlmlr/tic/blob/master/README.md",
"fileSize": "346.89KB",
"fileSize": "349.538KB",
"contIntegration": [
"https://travis-ci.com/ropensci/tic",
"https://ci.appveyor.com/project/ropensci/tic",
Expand All @@ -426,5 +438,13 @@
"https://ci.appveyor.com/project/ropensci/tic-website"
],
"developmentStatus": "https://www.tidyverse.org/lifecycle/#maturing",
"keywords": ["r", "travis-ci", "appveyor", "continuous-integration", "deployment", "r-package", "rstats"]
"keywords": [
"r",
"travis-ci",
"appveyor",
"continuous-integration",
"deployment",
"r-package",
"rstats"
]
}
1 change: 1 addition & 0 deletions man/do_bookdown.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 97 additions & 0 deletions man/do_drat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/do_package_checks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2d16e0c

Please sign in to comment.