-
-
Notifications
You must be signed in to change notification settings - Fork 48
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 renv.lock
validation hook
#558
base: main
Are you sure you want to change the base?
Changes from 3 commits
bf64c5e
37ed44f
58dc4f3
8574bf8
fe7d246
c1a118c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ issuehunt | |
isTRUE | ||
jpeg | ||
json | ||
jsonvalidate | ||
KernSmooth | ||
knitr | ||
Ko | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
"Validate renv lockfiles | ||
See `?renv::lockfile_validate()`. | ||
Usage: | ||
lockfile_validate [--schema=<schema>] [--greedy --error --verbose --strict] <files>... | ||
Options: | ||
--schema Path. Path to a custom schema. | ||
--greedy Continue after first error? | ||
--error Throw an error on parse failure? | ||
--verbose If `TRUE`, then an attribute `errors` will list validation failures as a `data.frame`. | ||
--strict Set whether the schema should be parsed strictly or not. | ||
" -> doc | ||
|
||
if (!require(renv, quietly = TRUE)) { | ||
stop("{renv} could not be loaded, please install it.") | ||
} | ||
if (packageVersion("renv") < package_version("1.0.8")) { | ||
rlang::abort("You need at least version 1.0.8 of {renv} to run this hook.") | ||
} | ||
if (!require(jsonvalidate, quietly = TRUE)) { | ||
stop("{jsonvalidate} could not be loaded, please install it.") | ||
} | ||
|
||
arguments <- precommit::precommit_docopt(doc) | ||
arguments$files <- normalizePath(arguments$files) | ||
if (!is.null(arguments$schema)) { | ||
arguments$schema <- normalizePath(arguments$schema) | ||
} | ||
|
||
renv::lockfile_validate( | ||
lockfile = arguments$files, | ||
schema = arguments$schema, | ||
greedy = arguments$greedy, | ||
error = arguments$error, | ||
verbose = arguments$verbose, | ||
strict = arguments$strict | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"R": { | ||
"Version": "4.2.3", | ||
"Repositories": [ | ||
{ | ||
"Name": "CRAN", | ||
"URL": "https://cloud.r-project.org" | ||
} | ||
] | ||
}, | ||
"Packages": { | ||
"markdown": { | ||
"Package": "markdown", | ||
"Version": "1.0", | ||
"Source": "Repository", | ||
"Repository": "CRAN", | ||
"Hash": "2324" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"R": { | ||
"Version": "4.2.3", | ||
"Repositories": [ | ||
{ | ||
"Name": "CRAN", | ||
"URL": "https://cloud.r-project.org" | ||
} | ||
] | ||
}, | ||
"Packages": { | ||
"markdown": { | ||
"Package": "markdown", | ||
"Version": "1.0", | ||
"Source": "Repository", | ||
"Repository": "CRAN" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# success | ||
run_test("renv-lockfile-validate", | ||
file_name = "renv-success", | ||
suffix = ".lock", cmd_args = c("--error"), | ||
std_err = NULL | ||
) | ||
# fail | ||
run_test("renv-lockfile-validate", | ||
file_name = "renv-fail", | ||
suffix = ".lock", cmd_args = c("--error"), | ||
std_err = "error validating json" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -386,3 +386,21 @@ development dependencies of the package you want to run this hook for to be | |
installed, as well as {pkgdown} (without its dependencies). | ||
|
||
This hook does not modify files. Added in version 0.3.2.9003. | ||
|
||
|
||
## `renv-lockfile-validate` | ||
|
||
Guarantees you that you don't accidentally commit an invalid renv.lock file. | ||
The below config that uses only `--error` should suffice for most users. | ||
|
||
id: renv-lockfile-validate | ||
args: [--error] | ||
|
||
This hook does not modify files. | ||
|
||
**Arguments** | ||
|
||
<!-- --> | ||
|
||
id: renv-lockfile-validate | ||
args: [--schema=<schema>] [--greedy --error --verbose --strict] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please link (with hyper-text-link) to docs for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe let's wait for rstudio/renv#2048? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add the version of {precommit} this hook was added to (similar to other hooks)?