Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macro do_drat() #221

Merged
merged 38 commits into from
Jan 18, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
fb16d42
first do_drat() try
pat-s Jan 16, 2020
43952e8
require full repo slug
pat-s Jan 16, 2020
ff245db
fix ci_can_push()
pat-s Jan 16, 2020
6a2583e
fix repo argument
pat-s Jan 16, 2020
d599bcd
use git/drat as the path arg default
pat-s Jan 16, 2020
03c8917
always deploy
pat-s Jan 16, 2020
3006dc5
clean add_to_drat()
pat-s Jan 16, 2020
c1aad3e
merge origin/master
pat-s Jan 16, 2020
7ce717a
do not deploy dev versions
pat-s Jan 16, 2020
ef853b4
import desc pkg
pat-s Jan 16, 2020
a98eca2
try without usethis::proj_get()
pat-s Jan 16, 2020
5f9cf13
no wrap
pat-s Jan 16, 2020
2eb44ab
add deployment instruction for appveyor
pat-s Jan 16, 2020
a28680f
merge master
pat-s Jan 16, 2020
81439e4
update vignette
pat-s Jan 16, 2020
832bf47
remove ...
pat-s Jan 16, 2020
7fb670e
give hint how to name env var
pat-s Jan 16, 2020
a5d1c1c
move macro checks and args to step_add_to_drat
pat-s Jan 17, 2020
f6613f5
clean NAMESPACE
pat-s Jan 17, 2020
c8ca8d7
donttest example
pat-s Jan 17, 2020
567bb76
fix deploy_dev
pat-s Jan 17, 2020
1714e5e
move deployment checks to `step_add_to_drat()`
pat-s Jan 17, 2020
d3e7e00
ups
pat-s Jan 17, 2020
0d4f695
merge origin/master
pat-s Jan 17, 2020
67864df
debug
pat-s Jan 17, 2020
983732e
debug
pat-s Jan 17, 2020
6068a1c
document
pat-s Jan 17, 2020
b685f85
be more verbose
pat-s Jan 17, 2020
8430f15
try reverting step_install_ssh_key()() change
pat-s Jan 17, 2020
80bcb57
clean
pat-s Jan 17, 2020
826ba29
try
pat-s Jan 17, 2020
4e422ad
Merge branch 'master' into do-drat
pat-s Jan 17, 2020
dbe32f2
add troubleshooting vignette
pat-s Jan 17, 2020
f1434ca
debug
pat-s Jan 17, 2020
1f68799
debug
pat-s Jan 17, 2020
190aa97
debug
pat-s Jan 17, 2020
63771ac
debug
pat-s Jan 17, 2020
50f5df4
solved it!
pat-s Jan 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Imports:
backports,
cli (>= 2.0.0),
crayon,
desc,
magrittr,
memoise,
methods,
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
2 changes: 2 additions & 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 Expand Up @@ -76,6 +77,7 @@ import(cli)
import(rlang)
importFrom(R6,R6Class)
importFrom(crayon,has_color)
importFrom(desc,desc_get_version)
importFrom(magrittr,"%>%")
importFrom(memoise,memoise)
importFrom(methods,setOldClass)
Expand Down
114 changes: 114 additions & 0 deletions R/macro-drat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#' do_drat
#'
#' The [do_drat()] macro adds the necessary steps for building
#' and deploying a drat repository to host R package sources.
#'
#' @importFrom desc desc_get_version
#'
#' @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 repo_slug `[string]`\cr
#' The name of the drat repository to deploy to in the form `:owner/:repo`.
#' @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 will be used for deployment.
#' Must be available in the build as a secure environment variable.
#' @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.
#'
#' @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
#' \dontrun{
#' 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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still the correct default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case yes. We have to manually insert the private secured key in appveyor.yml and I think inserting it with "TRAVIS_DEPLOY_KEY" would be misleading.

Since "id_rsa" is supported universally, I choose to go with it here.
Keys on Appveyor needs to be manually created anyway until now. We could change the name once we have an Appveyor client pkg.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mind reverting to "id_rsa", this would save lots of downstream pain.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I know. One reason of the whole effort was to ensure that differently named private SSH key works throughout all functions, especially when installing the key. This came from the motivation to decouple travis::use_travis_deploy() from {tic}. I know that this does not mean that the default needs to change necessarily - but having a different one is an indirect way to save the tests whether a custom name would also work 😅

Also I still think that some non-tech users will have an easier life understanding what that env var is about.

However, I see that we complicate things (a bit) since id_rsa is the canonical default picked up everywhere.

Argh, I don't know what's best 🤔

deploy_dev = FALSE) {

if (is.null(repo_slug)) {
stopc("A repository to deploy to is required.")
}
if (!ci_can_push(name = ssh_key_name)) {
stopc("Deployment not possible. Please the SSH deployment permissions of the build.")
}

if (!deploy_dev) {
ver <- desc::desc_get_version()
if (length(unlist(ver)) > 3) {
cli_alert_info("Detected dev version of current package. Not building
package binaries because {.code deploy_dev = FALSE} is
set.", wrap = FALSE)
return(invisible())
}
}

#' @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 = 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())

#' 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()
}
11 changes: 2 additions & 9 deletions R/steps-drat.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@ AddToDrat <- R6Class(

public = list(
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")
}
)
}
)
)
Expand All @@ -24,8 +19,6 @@ AddToDrat <- R6Class(
#'
#' 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.
#'
#' @family steps
#' @export
#' @examples
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 @@ -321,6 +321,18 @@
},
"sameAs": "https://CRAN.R-project.org/package=crayon"
},
{
"@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": "magrittr",
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.193KB",
"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.

99 changes: 99 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.

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

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

5 changes: 4 additions & 1 deletion man/macro.Rd

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

1 change: 0 additions & 1 deletion man/step_add_to_drat.Rd

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

3 changes: 3 additions & 0 deletions man/tic-package.Rd

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

Loading