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 do_blogdown() macro #242

Merged
merged 3 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -115,6 +115,7 @@ Collate:
'macro.R'
'macro-package-checks.R'
'macro-pkgdown.R'
'macro-blogdown.R'
'macro-bookdown.R'
'macro-drat.R'
'macro-readme-rmd.R'
Expand All @@ -124,6 +125,7 @@ Collate:
'run.R'
'stage.R'
'steps-base.R'
'steps-blogdown.R'
'steps-bookdown.R'
'steps-code.R'
'steps-drat.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_ghactions)
export(ci_on_travis)
export(deploy)
export(do_blogdown)
export(do_bookdown)
export(do_drat)
export(do_package_checks)
Expand All @@ -56,6 +57,7 @@ export(run_stage)
export(script)
export(step_add_to_drat)
export(step_add_to_known_hosts)
export(step_build_blogdown)
export(step_build_bookdown)
export(step_build_pkgdown)
export(step_do_push_deploy)
Expand Down
119 changes: 119 additions & 0 deletions R/macro-blogdown.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#' do_blogdown
#'
#' The [do_blogdown()] macro adds the necessary steps for building
#' and deploying a \pkg{blogdown} blog.
#'
#' @include macro.R
#' @include macro-pkgdown.R
#' @name macro
NULL


#' Build a blogdown site
#'
#' @description
#' `do_blogdown()` adds default steps related to package checks
#' to the `"install"`, `"before_deploy"`, `"script"` and `"deploy"` stages.
#'
#' @inheritParams step_build_blogdown
#' @inheritParams step_setup_push_deploy
#' @inheritParams step_do_push_deploy
#' @inheritParams step_install_pkg
#' @param ... Passed on to [step_build_blogdown()]
#' @template private_key_name
#' @family macros
#' @export
#' @examples
#' \dontrun{
#' dsl_init()
#'
#' do_blogdown()
#'
#' dsl_get()
#' }
do_blogdown <- function(...,
deploy = NULL,
orphan = FALSE,
checkout = TRUE,
repos = repo_default(),
path = "public",
branch = "gh-pages",
remote_url = NULL,
commit_message = NULL,
commit_paths = ".",
private_key_name = "TIC_DEPLOY_KEY") {

#' @param deploy `[flag]`\cr
#' If `TRUE`, deployment setup is performed
#' before building the blogdown site,
#' and the site is deployed after building it.
#' Set to `FALSE` to skip deployment.
if (is.null(deploy)) {
#' By default (if `deploy` is `NULL`), deployment happens
#' if the following conditions are met:
#'
#' 1. The repo can be pushed to (see [ci_can_push()]).
# account for old default "id_rsa"
private_key_name <- private_key_name

cli_text("Using {private_key_name} env var as the private key name for
SSH deployment.", wrap = TRUE)
deploy <- ci_can_push(private_key_name = private_key_name)

#' 2. The `branch` argument is `NULL`
#' (i.e., if the deployment happens to the active branch),
#' or the current branch is `master` (see [ci_get_branch()]).
if (deploy && !is.null(branch)) {
deploy <- (ci_get_branch() == "master")
}
}

#' @description
#' 1. [step_install_deps()] in the `"install"` stage, using the
#' `repos` argument.
#' 1. `blogdown::install_hugo()` in the `"install"` stage to install the
#' latest version of HUGO.
get_stage("install") %>%
add_step(step_install_deps(repos = !!enquo(repos))) %>%
add_code_step(blogdown::install_hugo())

if (isTRUE(deploy)) {
#' 1. [step_setup_ssh()] in the `"before_deploy"`
#' to setup the upcoming deployment (if `deploy` is set),
#' 1. [step_setup_push_deploy()] in the `"before_deploy"` stage
#' (if `deploy` is set),
#'
private_key_name <- private_key_name
get_stage("before_deploy") %>%
add_step(step_setup_ssh(private_key_name = !!private_key_name)) %>%
add_step(step_setup_push_deploy(
path = !!enquo(path),
branch = !!enquo(branch),
remote_url = !!enquo(remote_url),
orphan = !!enquo(orphan),
checkout = !!enquo(checkout)
))
}

#' 1. [step_build_blogdown()] in the `"deploy"` stage,
#' forwarding all `...` arguments.
get_stage("deploy") %>%
add_step(step_build_blogdown(!!!enquos(...)))

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

#' @description
#' By default, the `public/` directory is deployed to the `gh-pages` branch,
#' keeping the history. If the output directory of your blog/theme is not
#' `"public"` you need to change the `"path"` argument.

dsl_get()
}
42 changes: 42 additions & 0 deletions R/steps-blogdown.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
BuildBlogdown <- R6Class(
"BuildBlogdown",
inherit = TicStep,

public = list(
initialize = function(...) {
private$blogdown_args <- list(...)
super$initialize()
},

run = function() {
do.call(blogdown::build_site, private$blogdown_args)
},

prepare = function() {
verify_install(c("blogdown", "remotes"))
super$prepare()
}
),

private = list(
blogdown_args = NULL
)
)

#' Step: Build a Blogdown Site
#'
#' Build a Blogdown site using [blogdown::render_book()].
#'
#' @inheritDotParams blogdown::build_site
#'
#' @export
#' @examples
#' dsl_init()
#'
#' get_stage("script") %>%
#' add_step(step_build_blogdown("."))
#'
#' dsl_get()
step_build_blogdown <- function(...) {
BuildBlogdown$new(...)
}
116 changes: 116 additions & 0 deletions man/do_blogdown.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_bookdown.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_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.

1 change: 1 addition & 0 deletions man/do_readme_rmd.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/list_macros.Rd

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

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

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

Loading