Skip to content

Commit

Permalink
Use the generic term 'hash'
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Mar 5, 2024
1 parent 9f7aae7 commit 17ff61c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 48 deletions.
25 changes: 12 additions & 13 deletions R/record_versions.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#' @title Record the manifest of package versions.
#' @export
#' @description Record the manifest of versions of packages
#' and their MD5 hashes.
#' and their hashes.
#' @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,
#' the current hash, the highest version ever released, and
#' the 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
#' reads the old manifest, and updates recorded highest version and hash
#' 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
#' 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
Expand Down Expand Up @@ -43,16 +43,15 @@ record_versions <- function(
#' @export
#' @keywords internal
#' @description Get the current versions of packages in the repos.
#' @return A data frame of packages with their current versions and MD5
#' hashes.
#' @return A data frame of packages with their current versions and hashes.
#' @inheritParams record_versions
get_current_versions <- function(
repos = "https://r-releases.r-universe.dev"
) {
out <- utils::available.packages(repos = repos)
out <- as.data.frame(out)
out <- out[, c("Package", "Version", "MD5sum")]
colnames(out) <- c("package", "version_current", "md5_current")
colnames(out) <- c("package", "version_current", "hash_current")
rownames(out) <- NULL
out
}
Expand All @@ -66,19 +65,19 @@ read_versions_previous <- function(manifest) {
if (is.null(out$version_highest)) {
out$version_highest <- out$version_current
}
if (is.null(out$md5_highest)) {
out$md5_highest <- out$md5_current
if (is.null(out$hash_highest)) {
out$hash_highest <- out$hash_current
}
out$version_current <- NULL
out$md5_current <- NULL
out$hash_current <- NULL
out
}

update_version_manifest <- function(current, previous) {
new <- merge(x = current, y = previous, all = TRUE)
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$hash_highest[incremented] <- new$hash_current[incremented]
new
}

Expand All @@ -97,6 +96,6 @@ manifest_compare_versions <- function(manifest) {

versions_aligned <- function(manifest) {
versions_agree <- manifest$version_current == manifest$version_highest
hashes_agree <- manifest$md5_current == manifest$md5_highest
hashes_agree <- manifest$hash_current == manifest$hash_highest
versions_agree & hashes_agree
}
3 changes: 1 addition & 2 deletions man/get_current_versions.Rd

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

10 changes: 5 additions & 5 deletions man/record_versions.Rd

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

56 changes: 28 additions & 28 deletions tests/test-record_versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contents <- data.frame(
"version_unmodified"
),
version_current = rep("1.0.0", 4L),
md5_current = rep("md5_1.0.0", 4L)
hash_current = rep("hash_1.0.0", 4L)
)
r.releases.utils::record_versions(
manifest = manifest,
Expand All @@ -23,22 +23,22 @@ expected <- list(
list(
package = "package_unmodified",
version_current = "1.0.0",
md5_current = "md5_1.0.0"
hash_current = "hash_1.0.0"
),
list(
package = "version_decremented",
version_current = "1.0.0",
md5_current = "md5_1.0.0"
hash_current = "hash_1.0.0"
),
list(
package = "version_incremented",
version_current = "1.0.0",
md5_current = "md5_1.0.0"
hash_current = "hash_1.0.0"
),
list(
package = "version_unmodified",
version_current = "1.0.0",
md5_current = "md5_1.0.0"
hash_current = "hash_1.0.0"
)
)
stopifnot(identical(written, expected))
Expand All @@ -55,30 +55,30 @@ expected <- list(
list(
package = "package_unmodified",
version_current = "1.0.0",
md5_current = "md5_1.0.0",
hash_current = "hash_1.0.0",
version_highest = "1.0.0",
md5_highest = "md5_1.0.0"
hash_highest = "hash_1.0.0"
),
list(
package = "version_decremented",
version_current = "1.0.0",
md5_current = "md5_1.0.0",
hash_current = "hash_1.0.0",
version_highest = "1.0.0",
md5_highest = "md5_1.0.0"
hash_highest = "hash_1.0.0"
),
list(
package = "version_incremented",
version_current = "1.0.0",
md5_current = "md5_1.0.0",
hash_current = "hash_1.0.0",
version_highest = "1.0.0",
md5_highest = "md5_1.0.0"
hash_highest = "hash_1.0.0"
),
list(
package = "version_unmodified",
version_current = "1.0.0",
md5_current = "md5_1.0.0",
hash_current = "hash_1.0.0",
version_highest = "1.0.0",
md5_highest = "md5_1.0.0"
hash_highest = "hash_1.0.0"
)
)
stopifnot(identical(written, expected))
Expand All @@ -88,13 +88,13 @@ stopifnot(identical(jsonlite::read_json(issues), list()))
# Update the packages in all the ways indicated above.
index <- contents$package == "version_decremented"
contents$version_current[index] <- "0.0.1"
contents$md5_current[index] <- "md5_0.0.1"
contents$hash_current[index] <- "hash_0.0.1"
index <- contents$package == "version_incremented"
contents$version_current[index] <- "2.0.0"
contents$md5_current[index] <- "md5_2.0.0"
contents$hash_current[index] <- "hash_2.0.0"
index <- contents$package == "version_unmodified"
contents$version_current[index] <- "1.0.0"
contents$md5_current[index] <- "md5_1.0.0-modified"
contents$hash_current[index] <- "hash_1.0.0-modified"
r.releases.utils::record_versions(
manifest = manifest,
issues = issues,
Expand All @@ -105,30 +105,30 @@ expected <- list(
list(
package = "package_unmodified",
version_current = "1.0.0",
md5_current = "md5_1.0.0",
hash_current = "hash_1.0.0",
version_highest = "1.0.0",
md5_highest = "md5_1.0.0"
hash_highest = "hash_1.0.0"
),
list(
package = "version_decremented",
version_current = "0.0.1",
md5_current = "md5_0.0.1",
hash_current = "hash_0.0.1",
version_highest = "1.0.0",
md5_highest = "md5_1.0.0"
hash_highest = "hash_1.0.0"
),
list(
package = "version_incremented",
version_current = "2.0.0",
md5_current = "md5_2.0.0",
hash_current = "hash_2.0.0",
version_highest = "2.0.0",
md5_highest = "md5_2.0.0"
hash_highest = "hash_2.0.0"
),
list(
package = "version_unmodified",
version_current = "1.0.0",
md5_current = "md5_1.0.0-modified",
hash_current = "hash_1.0.0-modified",
version_highest = "1.0.0",
md5_highest = "md5_1.0.0"
hash_highest = "hash_1.0.0"
)
)
stopifnot(identical(written, expected))
Expand All @@ -138,16 +138,16 @@ expected_issues <- list(
list(
package = "version_decremented",
version_current = "0.0.1",
md5_current = "md5_0.0.1",
hash_current = "hash_0.0.1",
version_highest = "1.0.0",
md5_highest = "md5_1.0.0"
hash_highest = "hash_1.0.0"
),
list(
package = "version_unmodified",
version_current = "1.0.0",
md5_current = "md5_1.0.0-modified",
hash_current = "hash_1.0.0-modified",
version_highest = "1.0.0",
md5_highest = "md5_1.0.0"
hash_highest = "hash_1.0.0"
)
)
stopifnot(identical(written_issues, expected_issues))
Expand Down

0 comments on commit 17ff61c

Please sign in to comment.