Skip to content

Commit

Permalink
Write version_issues.json
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Mar 5, 2024
1 parent 31551bf commit fa0b67c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 27 deletions.
4 changes: 3 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
^LICENSE\.md$
^.*~$
^.*\.json$
^.*\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^main$
^pull_request$
^packages\.json$
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*~
*.json
.Rproj.user
.Rhistory
.RData
Expand Down
61 changes: 41 additions & 20 deletions R/record_versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,42 @@
#' @keywords internal
#' @description Record the manifest of versions of packages
#' and their MD5 hashes.
#' @details As well as their versions and MD5 hashes, this function
#' records the highest version ever recorded and the MD5 of that
#' version. This information helps check if a package complies with
#' best practices for version numbers: the version number should increment
#' on each new release.
#' @return `NULL` (invisibly). Writes a package manifest as a JSON file.
#' @details This function tracks a manifest containing the current version,
#' the current MD5 hash, the highest version ever released, and
#' the MD5 hash of the highest version ever released. Each time it runs,
#' it reads scrapes the package repository for the current releases,
#' reads the old manifest, and updates recorded highest version and MD5
#' for all packages which incremented their version numbers.
#' After recording these incremented versions, the current version should
#' be the highest version, and the current and highest-version
#' MD5 hashes should agree. Packages
#' that fall out of alignment are recorded in a small JSON with only
#' the packages with version issues.
#' @return `NULL` (invisibly). Writes a package version manifest
#' and a manifest of version issues as JSON files.
#' @param manifest Character of length 1, file path to the JSON manifest.
#' @param issues Character of length 1, file path to a JSON file
#' which records packages with version issues.
#' @param repos Character string of package repositories to track.
record_versions <- function(
manifest = "versions.json",
issues = "version_issues.json",
repos = "https://r-releases.r-universe.dev"
) {
current <- get_versions(repos = repos)
current <- get_current_versions(repos = repos)
if (!file.exists(manifest)) {
jsonlite::write_json(x = current, path = manifest, pretty = TRUE)
return(invisible())
}
previous <- read_previous(manifest = manifest)
new <- update_manifest(current = current, previous = previous)
previous <- read_versions_previous(manifest = manifest)
new <- update_version_manifest(current = current, previous = previous)
jsonlite::write_json(x = new, path = manifest, pretty = TRUE)
new_issues <- new[!versions_aligned(new = new),, drop = FALSE] # nolint
jsonlite::write_json(x = new_issues, path = issues, pretty = TRUE)
invisible()
}

get_versions <- function(repos) {
get_current_versions <- function(repos) {
out <- available.packages(repos = "https://r-releases.r-universe.dev")
out <- as.data.frame(out)
out <- out[, c("Package", "Version", "MD5sum")]
Expand All @@ -34,7 +47,7 @@ get_versions <- function(repos) {
out
}

read_previous <- function(manifest) {
read_versions_previous <- function(manifest) {
out <- jsonlite::read_json(path = manifest)
out <- do.call(what = vctrs::vec_rbind, args = out)
for (field in colnames(out)) {
Expand All @@ -51,21 +64,29 @@ read_previous <- function(manifest) {
out
}

update_manifest <- function(current, previous) {
update_version_manifest <- function(current, previous) {
new <- merge(x = current, y = previous, all = TRUE)
incremented <- apply(
X = new,
incremented <- manifest_compare_versions(manifest = new) > 0.5
new$version_highest[incremented] <- new$version_current[incremented]
new$md5_highest[incremented] <- new$md5_current[incremented]
new
}

manifest_compare_versions <- function(manifest) {
apply(
X = manifest,
MARGIN = 1L,
FUN = function(row) {
print(.subset2(row, "version_current"))
print(.subset2(row, "version_highest"))
utils::compareVersion(
a = .subset2(row, "version_current"),
b = .subset2(row, "version_highest")
) > 0.5
)
}
)
new$version_highest[incremented] <- new$version_current[incremented]
new$md5_highest[incremented] <- new$md5_current[incremented]
new
}

versions_aligned <- function(manifest) {
versions_agree <- manifest$version_current == manifest$version_highest
hashes_agree <- manifest$md5_current == manifest$md5_highest
versions_agree & hashes_agree
}
23 changes: 17 additions & 6 deletions man/record_versions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fa0b67c

Please sign in to comment.