From eb6aa82af9c02d1dbef6d4138a0c1e0705e8d9af Mon Sep 17 00:00:00 2001 From: pat-s Date: Sun, 29 Mar 2020 19:53:27 +0200 Subject: [PATCH 1/3] add macro blogdown --- DESCRIPTION | 2 + NAMESPACE | 2 + R/macro-blogdown.R | 116 +++++++++++++++++++++++++++++++++++++ R/steps-blogdown.R | 42 ++++++++++++++ man/do_blogdown.Rd | 114 ++++++++++++++++++++++++++++++++++++ man/do_bookdown.Rd | 1 + man/do_drat.Rd | 1 + man/do_package_checks.Rd | 1 + man/do_pkgdown.Rd | 1 + man/do_readme_rmd.Rd | 1 + man/list_macros.Rd | 1 + man/macro.Rd | 6 +- man/step_build_blogdown.Rd | 32 ++++++++++ 13 files changed, 319 insertions(+), 1 deletion(-) create mode 100644 R/macro-blogdown.R create mode 100644 R/steps-blogdown.R create mode 100644 man/do_blogdown.Rd create mode 100644 man/step_build_blogdown.Rd diff --git a/DESCRIPTION b/DESCRIPTION index f4e746b2..627cdd78 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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' @@ -124,6 +125,7 @@ Collate: 'run.R' 'stage.R' 'steps-base.R' + 'steps-blogdown.R' 'steps-bookdown.R' 'steps-code.R' 'steps-drat.R' diff --git a/NAMESPACE b/NAMESPACE index 7bfefe50..538a39ea 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) @@ -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) diff --git a/R/macro-blogdown.R b/R/macro-blogdown.R new file mode 100644 index 00000000..f2dbf5f9 --- /dev/null +++ b/R/macro-blogdown.R @@ -0,0 +1,116 @@ +#' 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. + get_stage("install") %>% + add_step(step_install_deps(repos = !!enquo(repos))) + + 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() +} diff --git a/R/steps-blogdown.R b/R/steps-blogdown.R new file mode 100644 index 00000000..3c9f4af2 --- /dev/null +++ b/R/steps-blogdown.R @@ -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(...) +} diff --git a/man/do_blogdown.Rd b/man/do_blogdown.Rd new file mode 100644 index 00000000..0226fd07 --- /dev/null +++ b/man/do_blogdown.Rd @@ -0,0 +1,114 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/macro-blogdown.R +\name{do_blogdown} +\alias{do_blogdown} +\title{Build a blogdown site} +\usage{ +do_blogdown( + ..., + 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" +) +} +\arguments{ +\item{...}{Passed on to \code{\link[=step_build_blogdown]{step_build_blogdown()}}} + +\item{deploy}{\verb{[flag]}\cr +If \code{TRUE}, deployment setup is performed +before building the blogdown site, +and the site is deployed after building it. +Set to \code{FALSE} to skip deployment. +By default (if \code{deploy} is \code{NULL}), deployment happens +if the following conditions are met: +\enumerate{ +\item The repo can be pushed to (see \code{\link[=ci_can_push]{ci_can_push()}}). +\item The \code{branch} argument is \code{NULL} +(i.e., if the deployment happens to the active branch), +or the current branch is \code{master} (see \code{\link[=ci_get_branch]{ci_get_branch()}}). +}} + +\item{orphan}{\verb{[flag]}\cr +Create and force-push an orphan branch consisting of only one commit? +This can be useful e.g. for \verb{path = "docs", branch = "gh-pages"}, +but cannot be applied for pushing to the current branch.} + +\item{checkout}{\verb{[flag]}\cr +Check out the current contents of the repository? Defaults to \code{TRUE}, +set to \code{FALSE} if the build process relies on existing contents or +if you deploy to a different branch.} + +\item{repos}{CRAN-like repositories to install from, defaults to +\code{\link[=repo_default]{repo_default()}}.} + +\item{path}{\verb{[string]}\cr +Path to the repository, default \code{"."} which means setting up the current +repository.} + +\item{branch}{\verb{[string]}\cr +Target branch, default: current branch.} + +\item{remote_url}{\verb{[string]}\cr +The URL of the remote Git repository to push to, defaults to the +current GitHub repository.} + +\item{commit_message}{\verb{[string]}\cr +Commit message to use, defaults to a useful message linking to the CI build +and avoiding recursive CI runs.} + +\item{commit_paths}{\verb{[character]}\cr +Restrict the set of directories and/or files added to Git before deploying. +Default: deploy all files.} + +\item{private_key_name}{\code{string}\cr +Only needed when deploying from builds on Travis CI or GitHub Actions. +If you have set a custom name for the private key during creation of the +SSH key pair via \code{\link[travis:use_travis_deploy]{travis::use_travis_deploy()}}, +\code{\link[tic:use_ghactions_deploy]{tic::use_ghactions_deploy()}} or \code{\link[=use_tic]{use_tic()}}, pass this name here.} +} +\description{ +\code{do_blogdown()} adds default steps related to package checks +to the \code{"install"}, \code{"before_deploy"}, \code{"script"} and \code{"deploy"} stages. + +\enumerate{ +\item \code{\link[=step_install_deps]{step_install_deps()}} in the \code{"install"} stage, using the +\code{repos} argument. +\item \code{\link[=step_setup_ssh]{step_setup_ssh()}} in the \code{"before_deploy"} +to setup the upcoming deployment (if \code{deploy} is set), +\item \code{\link[=step_setup_push_deploy]{step_setup_push_deploy()}} in the \code{"before_deploy"} stage +(if \code{deploy} is set), +\item \code{\link[=step_build_blogdown]{step_build_blogdown()}} in the \code{"deploy"} stage, +forwarding all \code{...} arguments. +\item \code{\link[=step_do_push_deploy]{step_do_push_deploy()}} in the \code{"deploy"} stage. +} + +By default, the \verb{public/} directory is deployed to the \code{gh-pages} branch, +keeping the history. If the output directory of your blog/theme is not +\code{"public"} you need to change the \code{"path"} argument. +} +\examples{ +\dontrun{ +dsl_init() + +do_blogdown() + +dsl_get() +} +} +\seealso{ +Other macros: +\code{\link{do_bookdown}()}, +\code{\link{do_drat}()}, +\code{\link{do_package_checks}()}, +\code{\link{do_pkgdown}()}, +\code{\link{do_readme_rmd}()}, +\code{\link{list_macros}()} +} +\concept{macros} diff --git a/man/do_bookdown.Rd b/man/do_bookdown.Rd index 10156ab9..366f3453 100644 --- a/man/do_bookdown.Rd +++ b/man/do_bookdown.Rd @@ -103,6 +103,7 @@ dsl_get() } \seealso{ Other macros: +\code{\link{do_blogdown}()}, \code{\link{do_drat}()}, \code{\link{do_package_checks}()}, \code{\link{do_pkgdown}()}, diff --git a/man/do_drat.Rd b/man/do_drat.Rd index 9f747742..6cab9fb9 100644 --- a/man/do_drat.Rd +++ b/man/do_drat.Rd @@ -92,6 +92,7 @@ dsl_get() } \seealso{ Other macros: +\code{\link{do_blogdown}()}, \code{\link{do_bookdown}()}, \code{\link{do_package_checks}()}, \code{\link{do_pkgdown}()}, diff --git a/man/do_package_checks.Rd b/man/do_package_checks.Rd index 3ad40752..ddbc0d89 100644 --- a/man/do_package_checks.Rd +++ b/man/do_package_checks.Rd @@ -95,6 +95,7 @@ dsl_get() } \seealso{ Other macros: +\code{\link{do_blogdown}()}, \code{\link{do_bookdown}()}, \code{\link{do_drat}()}, \code{\link{do_pkgdown}()}, diff --git a/man/do_pkgdown.Rd b/man/do_pkgdown.Rd index eb203774..e1629d2f 100644 --- a/man/do_pkgdown.Rd +++ b/man/do_pkgdown.Rd @@ -99,6 +99,7 @@ dsl_get() } \seealso{ Other macros: +\code{\link{do_blogdown}()}, \code{\link{do_bookdown}()}, \code{\link{do_drat}()}, \code{\link{do_package_checks}()}, diff --git a/man/do_readme_rmd.Rd b/man/do_readme_rmd.Rd index b15dac1c..75e03959 100644 --- a/man/do_readme_rmd.Rd +++ b/man/do_readme_rmd.Rd @@ -57,6 +57,7 @@ dsl_get() } \seealso{ Other macros: +\code{\link{do_blogdown}()}, \code{\link{do_bookdown}()}, \code{\link{do_drat}()}, \code{\link{do_package_checks}()}, diff --git a/man/list_macros.Rd b/man/list_macros.Rd index 99657b54..997681cf 100644 --- a/man/list_macros.Rd +++ b/man/list_macros.Rd @@ -14,6 +14,7 @@ Lists available macro functions of the \code{tic} package. } \seealso{ Other macros: +\code{\link{do_blogdown}()}, \code{\link{do_bookdown}()}, \code{\link{do_drat}()}, \code{\link{do_package_checks}()}, diff --git a/man/macro.Rd b/man/macro.Rd index ec480a2f..19978054 100644 --- a/man/macro.Rd +++ b/man/macro.Rd @@ -1,6 +1,7 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/macro.R, R/macro-package-checks.R, -% R/macro-pkgdown.R, R/macro-bookdown.R, R/macro-drat.R, R/macro-readme-rmd.R +% R/macro-pkgdown.R, R/macro-blogdown.R, R/macro-bookdown.R, R/macro-drat.R, +% R/macro-readme-rmd.R \name{macro} \alias{macro} \title{Macros} @@ -18,6 +19,9 @@ analysis. The \code{\link[=do_pkgdown]{do_pkgdown()}} macro adds the necessary steps for building and deploying \pkg{pkgdown} documentation for a package. +The \code{\link[=do_blogdown]{do_blogdown()}} macro adds the necessary steps for building +and deploying a \pkg{blogdown} blog. + The \code{\link[=do_bookdown]{do_bookdown()}} macro adds the necessary steps for building and deploying a \pkg{bookdown} book. diff --git a/man/step_build_blogdown.Rd b/man/step_build_blogdown.Rd new file mode 100644 index 00000000..9fc6c146 --- /dev/null +++ b/man/step_build_blogdown.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/steps-blogdown.R +\name{step_build_blogdown} +\alias{step_build_blogdown} +\title{Step: Build a Blogdown Site} +\usage{ +step_build_blogdown(...) +} +\arguments{ +\item{...}{ + Arguments passed on to \code{\link[blogdown:build_site]{blogdown::build_site}} + \describe{ + \item{\code{local}}{Whether to build the website locally to be served via +\code{\link[blogdown]{serve_site}()}.} + \item{\code{method}}{Different methods to build a website (each with pros and cons). +See Details. The value of this argument will be obtained from the global +option \code{getOption('blogdown.method')} when it is set.} + \item{\code{run_hugo}}{Whether to run \code{hugo_build()} after R Markdown files are +compiled.} + }} +} +\description{ +Build a Blogdown site using \code{\link[blogdown:render_book]{blogdown::render_book()}}. +} +\examples{ +dsl_init() + +get_stage("script") \%>\% + add_step(step_build_blogdown(".")) + +dsl_get() +} From faf4e4a5fc2fa2778824ea9883e5f00aaa1cd23a Mon Sep 17 00:00:00 2001 From: pat-s Date: Sun, 29 Mar 2020 19:55:54 +0200 Subject: [PATCH 2/3] install hugo --- R/macro-blogdown.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/macro-blogdown.R b/R/macro-blogdown.R index f2dbf5f9..f1073456 100644 --- a/R/macro-blogdown.R +++ b/R/macro-blogdown.R @@ -71,8 +71,11 @@ do_blogdown <- function(..., #' @description #' 1. [step_install_deps()] in the `"install"` stage, using the #' `repos` argument. + #' Here `blogdown::install_hugo()` is called to install the latest version of + #' HUGO. get_stage("install") %>% - add_step(step_install_deps(repos = !!enquo(repos))) + 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"` From 5ac84c05bb28f7ace69e7b698838c56f03688edf Mon Sep 17 00:00:00 2001 From: pat-s Date: Sun, 29 Mar 2020 20:08:19 +0200 Subject: [PATCH 3/3] fix macro --- R/macro-blogdown.R | 4 ++-- R/steps-blogdown.R | 2 +- man/do_blogdown.Rd | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/R/macro-blogdown.R b/R/macro-blogdown.R index f1073456..6d82ee52 100644 --- a/R/macro-blogdown.R +++ b/R/macro-blogdown.R @@ -71,8 +71,8 @@ do_blogdown <- function(..., #' @description #' 1. [step_install_deps()] in the `"install"` stage, using the #' `repos` argument. - #' Here `blogdown::install_hugo()` is called to install the latest version of - #' HUGO. + #' 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()) diff --git a/R/steps-blogdown.R b/R/steps-blogdown.R index 3c9f4af2..8fa8e936 100644 --- a/R/steps-blogdown.R +++ b/R/steps-blogdown.R @@ -19,7 +19,7 @@ BuildBlogdown <- R6Class( ), private = list( - Blogdown_args = NULL + blogdown_args = NULL ) ) diff --git a/man/do_blogdown.Rd b/man/do_blogdown.Rd index 0226fd07..4b9d446e 100644 --- a/man/do_blogdown.Rd +++ b/man/do_blogdown.Rd @@ -80,6 +80,8 @@ to the \code{"install"}, \code{"before_deploy"}, \code{"script"} and \code{"depl \enumerate{ \item \code{\link[=step_install_deps]{step_install_deps()}} in the \code{"install"} stage, using the \code{repos} argument. +\item \code{blogdown::install_hugo()} in the \code{"install"} stage to install the +latest version of HUGO. \item \code{\link[=step_setup_ssh]{step_setup_ssh()}} in the \code{"before_deploy"} to setup the upcoming deployment (if \code{deploy} is set), \item \code{\link[=step_setup_push_deploy]{step_setup_push_deploy()}} in the \code{"before_deploy"} stage