-
-
Notifications
You must be signed in to change notification settings - Fork 51
Add renv.lock validation hook
#558
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
Merged
lorenzwalthert
merged 7 commits into
lorenzwalthert:main
from
jrdnbradford:add-renv-hook
Jan 7, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bf64c5e
Add `renv-lockfile-validate` hook
jrdnbradford 37ed44f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 58dc4f3
Suggest `renv`
jrdnbradford 8574bf8
Fix heading
jrdnbradford fe7d246
Fix tests
jrdnbradford c1a118c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] acdd572
Add `lockfile_validate` docs
jrdnbradford File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| Package: precommit | ||
| Title: Pre-Commit Hooks | ||
| Version: 0.4.3.9004 | ||
| Version: 0.4.3.9005 | ||
| Author: Lorenz Walthert | ||
| Maintainer: Lorenz Walthert <[email protected]> | ||
| Description: Useful git hooks for R building on top of the multi-language | ||
|
|
@@ -22,16 +22,18 @@ Imports: | |
| rprojroot, | ||
| withr, | ||
| yaml | ||
| Suggests: | ||
| Suggests: | ||
| desc, | ||
| docopt (>= 0.7.1), | ||
| git2r, | ||
| glue, | ||
| jsonvalidate, | ||
| knitr, | ||
| lintr, | ||
| pkgload, | ||
| pkgdown, | ||
| reticulate (>= 1.16), | ||
| renv (>= 1.0.8), | ||
| rmarkdown, | ||
| roxygen2, | ||
| rstudioapi, | ||
|
|
@@ -40,7 +42,7 @@ Suggests: | |
| testthat (>= 2.1.0), | ||
| tibble, | ||
| usethis (>= 2.0.0) | ||
| VignetteBuilder: | ||
| VignetteBuilder: | ||
| knitr | ||
| Encoding: UTF-8 | ||
| Roxygen: list(markdown = TRUE, roclets = c( "rd", "namespace", "collate", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.