Skip to content

Commit d907500

Browse files
Merge pull request #558 from jrdnbradford/add-renv-hook
Add `renv.lock` validation hook
2 parents ab57413 + acdd572 commit d907500

File tree

13 files changed

+195
-21
lines changed

13 files changed

+195
-21
lines changed

.pre-commit-hooks.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,10 @@
127127
language: script
128128
minimum_pre_commit_version: "2.13.0"
129129
files: '^man/|_pkgdown\.yml'
130+
- id: renv-lockfile-validate
131+
name: renv-lockfile-validate
132+
description: Validate that your `renv.lock` file is valid json and fits the default or provided schema
133+
entry: Rscript inst/hooks/exported/renv-lockfile-validate.R
134+
language: r
135+
minimum_pre_commit_version: "2.13.0"
136+
files: '^renv\.lock$'

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# General
22

33
Before making a pull request, discuss your ideas in an issue.
4+
45
# Adding new hooks
56

67
To create a new hook, have a look at the [official

DESCRIPTION

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: precommit
22
Title: Pre-Commit Hooks
3-
Version: 0.4.3.9004
3+
Version: 0.4.3.9005
44
Author: Lorenz Walthert
55
Maintainer: Lorenz Walthert <[email protected]>
66
Description: Useful git hooks for R building on top of the multi-language
@@ -22,16 +22,18 @@ Imports:
2222
rprojroot,
2323
withr,
2424
yaml
25-
Suggests:
25+
Suggests:
2626
desc,
2727
docopt (>= 0.7.1),
2828
git2r,
2929
glue,
30+
jsonvalidate,
3031
knitr,
3132
lintr,
3233
pkgload,
3334
pkgdown,
3435
reticulate (>= 1.16),
36+
renv (>= 1.0.8),
3537
rmarkdown,
3638
roxygen2,
3739
rstudioapi,
@@ -40,7 +42,7 @@ Suggests:
4042
testthat (>= 2.1.0),
4143
tibble,
4244
usethis (>= 2.0.0)
43-
VignetteBuilder:
45+
VignetteBuilder:
4446
knitr
4547
Encoding: UTF-8
4648
Roxygen: list(markdown = TRUE, roclets = c( "rd", "namespace", "collate",

inst/WORDLIST

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ issuehunt
8282
isTRUE
8383
jpeg
8484
json
85+
jsonvalidate
8586
KernSmooth
8687
knitr
8788
Ko
@@ -97,6 +98,7 @@ Lifecycle
9798
LinkingTo
9899
lintr
99100
loadCache
101+
lockfile
100102
lorenz
101103
lorenzwalthert
102104
lt
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env Rscript
2+
3+
"Validate renv lockfiles
4+
See `?renv::lockfile_validate()`.
5+
Usage:
6+
lockfile_validate [--schema=<schema>] [--greedy --error --verbose --strict] <files>...
7+
Options:
8+
--schema Path. Path to a custom schema.
9+
--greedy Continue after first error?
10+
--error Throw an error on parse failure?
11+
--verbose If `TRUE`, then an attribute `errors` will list validation failures as a `data.frame`.
12+
--strict Set whether the schema should be parsed strictly or not.
13+
" -> doc
14+
15+
if (!require(renv, quietly = TRUE)) {
16+
stop("{renv} could not be loaded, please install it.")
17+
}
18+
if (packageVersion("renv") < package_version("1.0.8")) {
19+
rlang::abort("You need at least version 1.0.8 of {renv} to run this hook.")
20+
}
21+
if (!require(jsonvalidate, quietly = TRUE)) {
22+
stop("{jsonvalidate} could not be loaded, please install it.")
23+
}
24+
25+
arguments <- precommit::precommit_docopt(doc)
26+
arguments$files <- normalizePath(arguments$files)
27+
if (!is.null(arguments$schema)) {
28+
arguments$schema <- normalizePath(arguments$schema)
29+
}
30+
31+
renv::lockfile_validate(
32+
lockfile = arguments$files,
33+
schema = arguments$schema,
34+
greedy = arguments$greedy,
35+
error = arguments$error,
36+
verbose = arguments$verbose,
37+
strict = arguments$strict
38+
)

inst/pre-commit-hooks.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,10 @@
127127
language: script
128128
minimum_pre_commit_version: "2.13.0"
129129
files: '^man/|_pkgdown\.yml'
130+
- id: renv-lockfile-validate
131+
name: renv-lockfile-validate
132+
description: Validate that your `renv.lock` file is valid json and fits the default or provided schema
133+
entry: Rscript inst/hooks/exported/renv-lockfile-validate.R
134+
language: r
135+
minimum_pre_commit_version: "2.13.0"
136+
files: '^renv\.lock$'

inst/update-dependency-graph-existing-packages.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ hook_deps <- function(root) {
77
"pkgdown",
88
"httr"
99
)
10-
out <- c(out, "docopt", "roxygen2", "spelling", "styler", "pkgload", "lintr", "knitr", "desc")
10+
out <- c(out, "docopt", "roxygen2", "spelling", "styler", "pkgload", "lintr", "knitr", "desc", "jsonvalidate")
1111
out <- setdiff(c(unique(c(out, deps[deps$type == "Imports", ]$package))), dont)
1212
out <- names(renv:::renv_package_dependencies(out))
1313
return(sort(out))

renv.lock

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@
8484
],
8585
"Hash": "6b868847b365672d6c1677b1608da9ed"
8686
},
87+
"V8": {
88+
"Package": "V8",
89+
"Version": "6.0.0",
90+
"Source": "Repository",
91+
"Repository": "RSPM",
92+
"Requirements": [
93+
"Rcpp",
94+
"curl",
95+
"jsonlite",
96+
"utils"
97+
],
98+
"Hash": "6603bfcbc7883a5fed41fb13042a3899"
99+
},
87100
"backports": {
88101
"Package": "backports",
89102
"Version": "1.5.0",
@@ -164,6 +177,16 @@
164177
],
165178
"Hash": "859d96e65ef198fd43e82b9628d593ef"
166179
},
180+
"curl": {
181+
"Package": "curl",
182+
"Version": "5.2.3",
183+
"Source": "Repository",
184+
"Repository": "RSPM",
185+
"Requirements": [
186+
"R"
187+
],
188+
"Hash": "d91263322a58af798f6cf3b13fd56dde"
189+
},
167190
"cyclocomp": {
168191
"Package": "cyclocomp",
169192
"Version": "1.1.1",
@@ -277,6 +300,26 @@
277300
],
278301
"Hash": "e58f80d4c5b4f0bab1456956d6ca6aad"
279302
},
303+
"jsonlite": {
304+
"Package": "jsonlite",
305+
"Version": "1.8.9",
306+
"Source": "Repository",
307+
"Repository": "RSPM",
308+
"Requirements": [
309+
"methods"
310+
],
311+
"Hash": "4e993b65c2c3ffbffce7bb3e2c6f832b"
312+
},
313+
"jsonvalidate": {
314+
"Package": "jsonvalidate",
315+
"Version": "1.3.2",
316+
"Source": "Repository",
317+
"Repository": "RSPM",
318+
"Requirements": [
319+
"V8"
320+
],
321+
"Hash": "cdc2843ef7f44f157198bb99aea7552d"
322+
},
280323
"knitr": {
281324
"Package": "knitr",
282325
"Version": "1.49",

tests/testthat/in/renv-fail.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"R": {
3+
"Version": "4.2.3",
4+
"Repositories": [
5+
{
6+
"Name": "CRAN",
7+
"URL": "https://cloud.r-project.org"
8+
}
9+
]
10+
},
11+
"Packages": {
12+
"markdown": {
13+
"Package": "markdown",
14+
"Version": "1.0",
15+
"Source": "Repository",
16+
"Repository": "CRAN",
17+
"Hash": "2324"
18+
}
19+
}
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"R": {
3+
"Version": "4.2.3",
4+
"Repositories": [
5+
{
6+
"Name": "CRAN",
7+
"URL": "https://cloud.r-project.org"
8+
}
9+
]
10+
},
11+
"Packages": {
12+
"markdown": {
13+
"Package": "markdown",
14+
"Version": "1.0",
15+
"Source": "Repository",
16+
"Repository": "CRAN"
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)