From 387efa93c0e672acba2ca1a0fd1d181e60372c1c Mon Sep 17 00:00:00 2001 From: olivroy Date: Tue, 20 Feb 2024 08:27:47 -0500 Subject: [PATCH] `check()` now checks pkgdown --- NEWS.md | 2 ++ R/check.R | 24 ++++++++++++++++++++++++ man/check.Rd | 3 +++ 3 files changed, 29 insertions(+) diff --git a/NEWS.md b/NEWS.md index 30c1fbf1a..faff1f317 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # devtools (development version) +* `check()` now runs `pkgdown::check_pkgdown()` optionally (@olivroy, #2449) + * `test_coverage()` now works if the package has not been installed. * `test_coverage_active_file()` now reports if any tests failed and does diff --git a/R/check.R b/R/check.R index 153a1f802..31c11280c 100644 --- a/R/check.R +++ b/R/check.R @@ -42,6 +42,7 @@ #' roxygen2 version matches the version declared in the `DESCRIPTION` #' file. Use `TRUE` or `FALSE` to override the default. #' @param build_args Additional arguments passed to `R CMD build` +#' @param pkgdown Should run [pkgdown::check_pkgdown()]? #' @param ... Additional arguments passed on to [pkgbuild::build()]. #' @param vignettes If `FALSE`, do not build or check vignettes, equivalent to #' using `args = '--ignore-vignettes' and `build_args = '--no-build-vignettes'. @@ -61,6 +62,7 @@ check <- function(pkg = ".", run_dont_test = FALSE, args = "--timings", env_vars = c(NOT_CRAN = "true"), + pkgdown = NULL, quiet = FALSE, check_dir = NULL, cleanup = deprecated(), @@ -90,6 +92,17 @@ check <- function(pkg = ".", cli::cat_line() } } + pkgdown <- pkgdown %||% has_pkgdown(pkg$path) + + if (pkgdown) { + if (!quiet) { + cat_rule("Checking pkgdown", col = "cyan", line = 2) + } + pkgdown::check_pkgdown(pkg = pkg$path) + if (!quiet) { + cli::cat_line() + } + } if (!quiet) { cat_rule("Building", col = "cyan", line = 2) @@ -151,6 +164,17 @@ can_document <- function(pkg) { } } +has_pkgdown <- function(pkg) { + tryCatch( + !is.null( + rprojroot::find_root_file( + criterion = rprojroot::is_pkgdown_project, + path = ".") + ), + error = function(e) FALSE + ) +} + #' @export #' @rdname check #' @param path Path to built package. diff --git a/man/check.Rd b/man/check.Rd index 98bd6780c..27e13e2b8 100644 --- a/man/check.Rd +++ b/man/check.Rd @@ -18,6 +18,7 @@ check( run_dont_test = FALSE, args = "--timings", env_vars = c(NOT_CRAN = "true"), + pkgdown = NULL, quiet = FALSE, check_dir = NULL, cleanup = deprecated(), @@ -83,6 +84,8 @@ Windows.)} \item{env_vars}{Environment variables set during \verb{R CMD check}} +\item{pkgdown}{Should run \code{\link[pkgdown:check_pkgdown]{pkgdown::check_pkgdown()}}?} + \item{quiet}{if \code{TRUE} suppresses output from this function.} \item{check_dir}{Path to a directory where the check is performed.