Skip to content

Commit

Permalink
chore: update R version limit logic [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Apr 22, 2024
1 parent a2eb4db commit 4b4883e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 54 deletions.
46 changes: 6 additions & 40 deletions build/matrix/all.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,8 @@
{
"r_version": ["4.0.5", "4.1.3", "4.2.0", "4.2.1", "4.2.2", "4.2.3", "4.3.0", "4.3.1", "4.3.2", "4.3.3"],
"group": ["default"],
"include": [
{
"r_version": "4.1.3",
"group": "cuda11images"
},
{
"r_version": "4.2.0",
"group": "cuda11images"
},
{
"r_version": "4.2.1",
"group": "cuda11images"
},
{
"r_version": "4.2.2",
"group": "cuda11images"
},
{
"r_version": "4.2.3",
"group": "cuda11images"
},
{
"r_version": "4.3.0",
"group": "cuda11images"
},
{
"r_version": "4.3.1",
"group": "cuda11images"
},
{
"r_version": "4.3.2",
"group": "cuda11images"
},
{
"r_version": "4.3.3",
"group": "cuda11images"
}
]
"r_version": [
"4.2.3",
"4.3.2",
"4.3.3"
],
"group": "default"
}
12 changes: 4 additions & 8 deletions build/matrix/latest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"r_version": ["4.3.3"],
"group": ["default"],
"include": [
{
"r_version": "4.3.3",
"group": "cuda11images"
}
]
"r_version": [
"4.3.3"
],
"group": "default"
}
30 changes: 30 additions & 0 deletions build/scripts/clean-files.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
remove_unsupported_files <- function(files, supported_versions) {
files |>
purrr::discard(
\(x) stringr::str_detect(x, supported_versions) |> any()
) |>
purrr::walk(
fs::file_delete
)
}


supported_versions <- jsonlite::read_json(
"build/matrix/all.json",
simplifyVector = TRUE
)$r_version


# Clean up args files
fs::dir_ls(path = "build/args", regexp = r"((\d+\.){3}json)") |>
remove_unsupported_files(supported_versions)


# Clean up Dockerfiles
fs::dir_ls(path = "dockerfiles", regexp = r"((\d+\.){3}Dockerfile)") |>
remove_unsupported_files(supported_versions)


# Clean up docker-bake.json files
fs::dir_ls(path = "bakefiles", regexp = r"((\d+\.){3}docker-bake.json)") |>
remove_unsupported_files(supported_versions)
9 changes: 3 additions & 6 deletions build/scripts/generate-args.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ rocker_versioned_args <- function(
...,
r_versions_file = "build/variables/r-versions.tsv",
ubuntu_lts_versions_file = "build/variables/ubuntu-lts-versions.tsv",
rstudio_versions_file = "build/variables/rstudio-versions.tsv") {
rstudio_versions_file = "build/variables/rstudio-versions.tsv",
n_r_versions = 6) {
df_all <- readr::read_tsv(r_versions_file, show_col_types = FALSE) |>
dplyr::arrange(as.numeric_version(r_version)) |>
dplyr::mutate(
Expand All @@ -180,11 +181,7 @@ rocker_versioned_args <- function(
.by = r_major_version
) |>
dplyr::select(!c(r_minor_version, r_major_version)) |>
# Supports the latest two patch versions and the latest two minor versions.
dplyr::filter(
r_minor_latest | dplyr::lead(r_major_latest, default = FALSE)
) |>
dplyr::slice_tail(n = 3) |>
dplyr::slice_tail(n = n_r_versions) |>
tidyr::expand_grid(
readr::read_tsv(
ubuntu_lts_versions_file,
Expand Down
37 changes: 37 additions & 0 deletions build/scripts/generate-matrix.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' @param r_versions A character vector of R versions to include in the matrix
#' @param file The file path to write the matrix to
#' @examples
#' write_matrix(c("4.0.0", "4.0.1"), "build/matrix/all.json")
write_matrix <- function(r_versions, file) {
list(
r_version = as.list(r_versions),
group = "default"
) |>
jsonlite::write_json(file, pretty = TRUE, auto_unbox = TRUE)
}

supported_versions <- fs::dir_ls(path = "build/args", regexp = r"((\d+\.){3}json)") |>
stringr::str_extract(r"((\d+\.){2}\d)") |>
R_system_version() |>
sort() |>
tibble::tibble(r_version = _) |>
dplyr::mutate(
major = r_version$major,
minor = r_version$minor,
patch = r_version$patch
) |>
dplyr::slice_tail(n = 2, by = c(major, minor)) |>
dplyr::filter(
minor == dplyr::last(minor) | patch >= dplyr::lead(patch)
) |>
dplyr::pull(r_version) |>
as.character()


supported_versions |>
write_matrix("build/matrix/all.json")


supported_versions |>
utils::tail(1) |>
write_matrix("build/matrix/latest.json")

0 comments on commit 4b4883e

Please sign in to comment.