Skip to content

Commit 59981a7

Browse files
Merge pull request #393 from gravesti/pkgdown_check
simple pkgdown check
2 parents 428e0f9 + 345e95f commit 59981a7

19 files changed

+345
-104
lines changed

.github/workflows/end-to-end.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
env:
1212
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1313
steps:
14+
- uses: r-lib/actions/setup-pandoc@v2
15+
1416
- uses: r-lib/actions/setup-r@v2
1517

1618
- uses: actions/checkout@v2
@@ -69,6 +71,15 @@ jobs:
6971
pre-commit run --files DESCRIPTION
7072
git add README*
7173
pre-commit run --files README.Rmd
74+
cp tests/testthat/in/_pkgdown-index-articles.yml _pkgdown.yml
75+
rm -rf vignettes
76+
mkdir vignettes
77+
cp tests/testthat/in/pkgdown.Rmd vignettes/
78+
rm -rf man/
79+
mkdir -p man
80+
cp tests/testthat/in/autoupdate.Rd man/
81+
pre-commit run --files _pkgdown.yml
82+
pre-commit run --files man/autoupdate.Rd
7283
git reset HEAD --hard # restore initial state
7384
env:
7485
SKIP: consistent-release-tag

.github/workflows/hook-dependencies-update.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ jobs:
5353
deps <- desc$get_deps()
5454
dont <- c(
5555
"yaml", "usethis", "withr", "rstudioapi", "precommit",
56-
"httr" # lintr -> httr -> curl -> libcurl, but seems to give no erorr on
57-
# loading lintr, plus https://github.com/jimhester/lintr/issues/861
56+
"pkgdown", "mockery",
57+
"httr"
5858
)
59-
out <- c(out, "roxygen2", "spelling", "styler", "pkgload", "lintr", "knitr", "git2r", "desc")
59+
out <- c(out, "roxygen2", "spelling", "styler", "pkgload", "lintr", "knitr", "git2r", "desc", "mockery")
6060
out <- setdiff(c(unique(c(out, deps[deps$type == "Imports", ]$package))), dont)
6161
out <- names(renv:::renv_package_dependencies(out))
62-
return(out)
62+
return(sort(out))
6363
}
6464
options(repos = c(CRAN = "https://packagemanager.rstudio.com/all/latest"))
6565
options(renv.snapshot.filter = hook_deps)

.github/workflows/hook-tests.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
2525

2626
steps:
27+
- uses: r-lib/actions/setup-pandoc@v2
2728
- uses: actions/checkout@v2
2829
- uses: r-lib/actions/setup-r@v2
2930
with:
@@ -67,6 +68,9 @@ jobs:
6768
run: |
6869
source('renv/activate.R')
6970
renv::restore()
71+
options(install.packages.compile.from.source = "never", pkgType = "binary")
72+
# install hook-specific additional_dependencies from .pre-commit-config.yaml
73+
renv::install(c('pkgdown', 'mockery'))
7074
renv::install(getwd(), dependencies = FALSE)
7175
# needed to make sure renv is activated in run_test()
7276
activate <- c(

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ repos:
8282
(?x)^(
8383
tests/testthat/in/.*|
8484
inst/renv-update\.R|
85+
inst/hooks/exported/pkgdown.R|
8586
renv/activate.R|
8687
vignettes/FAQ\.Rmd|
8788
)$
89+
# - id: pkgdown
8890
- repo: https://github.com/pre-commit/pre-commit-hooks
8991
rev: v4.3.0
9092
hooks:

.pre-commit-hooks.yaml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
- id: roxygenize
22
name: roxygenize
3-
description: run roxygen2::roxygenize()
3+
description: run `roxygen2::roxygenize()`
44
entry: Rscript inst/hooks/exported/roxygenize.R
55
language: r
66
files: '^(R|man)/'
77
require_serial: true
88
minimum_pre_commit_version: "2.13.0"
99
- id: use-tidy-description
1010
name: use-tidy-description
11-
description: run usethis::use_tidy_description()
11+
description: run `usethis::use_tidy_description()`
1212
entry: Rscript inst/hooks/exported/use-tidy-description.R
1313
language: r
1414
files: '^DESCRIPTION$'
1515
minimum_pre_commit_version: "2.13.0"
1616
- id: style-files
1717
name: style-files
18-
description: style files with styler
18+
description: style files with {styler}
1919
entry: Rscript inst/hooks/exported/style-files.R
2020
language: r
2121
files: '(\.[rR]profile|\.[rR]|\.[rR]md|\.[rR]nw|\.[qQ]md)$'
@@ -44,21 +44,21 @@
4444
minimum_pre_commit_version: "2.13.0"
4545
- id: readme-rmd-rendered
4646
name: readme-rmd-rendered
47-
description: make sure README.Rmd hasn't been edited more recently than README.md
47+
description: make sure README.Rmd hasn't been edited more recently than `README.md`
4848
entry: Rscript inst/hooks/exported/readme-rmd-rendered.R
4949
language: r
5050
files: 'README\.[Rr]?md$'
5151
minimum_pre_commit_version: "2.13.0"
5252
- id: codemeta-description-updated
5353
name: codemeta-description-updated
54-
description: make sure codemeta.json is in sync with DESCRIPTION. It should be run after use-tidy-description.
54+
description: make sure `codemeta.json` is in sync with `DESCRIPTION`. It should be run after use-tidy-description
5555
entry: Rscript inst/hooks/exported/codemeta-description-updated.R
5656
language: r
5757
files: '^DESCRIPTION$'
5858
minimum_pre_commit_version: "2.13.0"
5959
- id: spell-check
6060
name: spell-check
61-
description: perform a spell check with spelling::spell_check_files()
61+
description: perform a spell check with `spelling::spell_check_files()`
6262
entry: Rscript inst/hooks/exported/spell-check.R
6363
language: r
6464
exclude: >
@@ -92,17 +92,24 @@
9292
minimum_pre_commit_version: "2.13.0"
9393
- id: deps-in-desc
9494
name: deps-in-desc
95-
description: Check if dependencies that can be parsed from code are in DESCRIPTION.
95+
description: Check if dependencies that can be parsed from code are in `DESCRIPTION`
9696
entry: Rscript inst/hooks/exported/deps-in-desc.R
9797
language: r
9898
files: '(\.[rR]profile|\.R|\.Rmd|\.Rnw|\.r|\.rmd|\.rnw)$'
9999
exclude: 'renv/activate\.R'
100100
minimum_pre_commit_version: "2.13.0"
101101
- id: lintr
102102
name: lintr
103-
description: check if a .R file is lint free (using lintr)
103+
description: check if a `.R` file is lint free (using {lintr})
104104
entry: Rscript inst/hooks/exported/lintr.R
105105
language: r
106106
files: '(\.[rR]profile|\.R|\.Rmd|\.Rnw|\.r|\.rmd|\.rnw)$'
107107
exclude: 'renv/activate\.R'
108108
minimum_pre_commit_version: "2.13.0"
109+
- id: pkgdown
110+
name: pkgdown
111+
description: check if your {pkgdown} config file has the correct entries for references and articles
112+
entry: inst/hooks/exported/pkgdown.R
113+
language: script
114+
minimum_pre_commit_version: "2.13.0"
115+
files: '^man/|_pkgdown\.yml'

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: precommit
22
Title: Pre-Commit Hooks
3-
Version: 0.3.2.9003
3+
Version: 0.3.2.9004
44
Author: Lorenz Walthert
55
Maintainer: Lorenz Walthert <[email protected]>
66
Description: Useful git hooks for R building on top of the multi-language
@@ -33,6 +33,7 @@ Suggests:
3333
lintr,
3434
mockery,
3535
pkgload,
36+
pkgdown,
3637
reticulate (>= 1.16),
3738
rmarkdown,
3839
roxygen2,

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ editor_options:
44
wrap: 72
55
---
66

7-
# precommit v0.3.2.9001 (Development version)
7+
# precommit v0.3.2.9003 (Development version)
88

9+
- new hook `pkgdown` to emulate a {pkgdown} build for reference and
10+
articles (#393).
911
- `codemeta-description-updated`, `roxygenize`, and
1012
`use-tidy-description` now all support a `root` argument that
1113
specifies the directory in the git repo that contains the R package.

inst/hooks/exported/pkgdown.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env Rscript
2+
3+
if (is.null(pkgdown:::pkgdown_config_path("."))) {
4+
rlang::inform(paste0(
5+
"{pkgdown} seems not configured, the remainder of the check is skipped. ",
6+
"For this hook to not even be invoked, remove `id: pkgdown` from ",
7+
"`.pre-commit-config.yaml`."
8+
))
9+
quit()
10+
}
11+
12+
if (!require(pkgdown, quietly = TRUE)) {
13+
stop("{pkgdown} could not be loaded, please install it.")
14+
}
15+
if (packageVersion("pkgdown") < package_version("2.0.4")) {
16+
rlang::abort("You need at least version 2.0.4 of {pkgdown} to run this hook.")
17+
}
18+
check_pkgdown()

inst/pre-commit-hooks.yaml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
- id: roxygenize
22
name: roxygenize
3-
description: run roxygen2::roxygenize()
3+
description: run `roxygen2::roxygenize()`
44
entry: Rscript inst/hooks/exported/roxygenize.R
55
language: r
66
files: '^(R|man)/'
77
require_serial: true
88
minimum_pre_commit_version: "2.13.0"
99
- id: use-tidy-description
1010
name: use-tidy-description
11-
description: run usethis::use_tidy_description()
11+
description: run `usethis::use_tidy_description()`
1212
entry: Rscript inst/hooks/exported/use-tidy-description.R
1313
language: r
1414
files: '^DESCRIPTION$'
1515
minimum_pre_commit_version: "2.13.0"
1616
- id: style-files
1717
name: style-files
18-
description: style files with styler
18+
description: style files with {styler}
1919
entry: Rscript inst/hooks/exported/style-files.R
2020
language: r
2121
files: '(\.[rR]profile|\.[rR]|\.[rR]md|\.[rR]nw|\.[qQ]md)$'
@@ -44,21 +44,21 @@
4444
minimum_pre_commit_version: "2.13.0"
4545
- id: readme-rmd-rendered
4646
name: readme-rmd-rendered
47-
description: make sure README.Rmd hasn't been edited more recently than README.md
47+
description: make sure README.Rmd hasn't been edited more recently than `README.md`
4848
entry: Rscript inst/hooks/exported/readme-rmd-rendered.R
4949
language: r
5050
files: 'README\.[Rr]?md$'
5151
minimum_pre_commit_version: "2.13.0"
5252
- id: codemeta-description-updated
5353
name: codemeta-description-updated
54-
description: make sure codemeta.json is in sync with DESCRIPTION. It should be run after use-tidy-description.
54+
description: make sure `codemeta.json` is in sync with `DESCRIPTION`. It should be run after use-tidy-description
5555
entry: Rscript inst/hooks/exported/codemeta-description-updated.R
5656
language: r
5757
files: '^DESCRIPTION$'
5858
minimum_pre_commit_version: "2.13.0"
5959
- id: spell-check
6060
name: spell-check
61-
description: perform a spell check with spelling::spell_check_files()
61+
description: perform a spell check with `spelling::spell_check_files()`
6262
entry: Rscript inst/hooks/exported/spell-check.R
6363
language: r
6464
exclude: >
@@ -92,17 +92,24 @@
9292
minimum_pre_commit_version: "2.13.0"
9393
- id: deps-in-desc
9494
name: deps-in-desc
95-
description: Check if dependencies that can be parsed from code are in DESCRIPTION.
95+
description: Check if dependencies that can be parsed from code are in `DESCRIPTION`
9696
entry: Rscript inst/hooks/exported/deps-in-desc.R
9797
language: r
9898
files: '(\.[rR]profile|\.R|\.Rmd|\.Rnw|\.r|\.rmd|\.rnw)$'
9999
exclude: 'renv/activate\.R'
100100
minimum_pre_commit_version: "2.13.0"
101101
- id: lintr
102102
name: lintr
103-
description: check if a .R file is lint free (using lintr)
103+
description: check if a `.R` file is lint free (using {lintr})
104104
entry: Rscript inst/hooks/exported/lintr.R
105105
language: r
106106
files: '(\.[rR]profile|\.R|\.Rmd|\.Rnw|\.r|\.rmd|\.rnw)$'
107107
exclude: 'renv/activate\.R'
108108
minimum_pre_commit_version: "2.13.0"
109+
- id: pkgdown
110+
name: pkgdown
111+
description: check if your {pkgdown} config file has the correct entries for references and articles
112+
entry: inst/hooks/exported/pkgdown.R
113+
language: script
114+
minimum_pre_commit_version: "2.13.0"
115+
files: '^man/|_pkgdown\.yml'

0 commit comments

Comments
 (0)