From 72c1e95e3167beb609444eb7ad575d14eec3c855 Mon Sep 17 00:00:00 2001 From: eitsupi Date: Mon, 22 Apr 2024 13:21:36 +0000 Subject: [PATCH] chore: update R version limit logic [skip ci] --- build/matrix/all.json | 46 +++-------------------- build/matrix/latest.json | 12 ++---- build/scripts/clean-files.R | 30 +++++++++++++++ build/scripts/generate-args.R | 9 ++--- build/scripts/generate-main-bakefiles.R | 4 +- build/scripts/generate-main-dockerfiles.R | 4 +- build/scripts/generate-matrix.R | 37 ++++++++++++++++++ 7 files changed, 86 insertions(+), 56 deletions(-) create mode 100644 build/scripts/clean-files.R create mode 100644 build/scripts/generate-matrix.R diff --git a/build/matrix/all.json b/build/matrix/all.json index 734766cf..e4e7a79d 100644 --- a/build/matrix/all.json +++ b/build/matrix/all.json @@ -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" } diff --git a/build/matrix/latest.json b/build/matrix/latest.json index 192092e6..aa6c0655 100644 --- a/build/matrix/latest.json +++ b/build/matrix/latest.json @@ -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" } diff --git a/build/scripts/clean-files.R b/build/scripts/clean-files.R new file mode 100644 index 00000000..7abd7115 --- /dev/null +++ b/build/scripts/clean-files.R @@ -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) diff --git a/build/scripts/generate-args.R b/build/scripts/generate-args.R index 8129cc17..93644d38 100644 --- a/build/scripts/generate-args.R +++ b/build/scripts/generate-args.R @@ -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( @@ -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, diff --git a/build/scripts/generate-main-bakefiles.R b/build/scripts/generate-main-bakefiles.R index 79ffe008..400d26e8 100644 --- a/build/scripts/generate-main-bakefiles.R +++ b/build/scripts/generate-main-bakefiles.R @@ -190,7 +190,9 @@ df_args <- fs::dir_ls(path = "build/args", regexp = r"((\d+\.){3}json)") |> purrr::modify_if(is.null, \(x) NA) |> tibble::as_tibble() ) |> - purrr::list_rbind() + purrr::list_rbind() |> + # Limit to the last 2 versions + utils::tail(2) df_args |> purrr::pwalk( diff --git a/build/scripts/generate-main-dockerfiles.R b/build/scripts/generate-main-dockerfiles.R index 10fa16f0..06373536 100644 --- a/build/scripts/generate-main-dockerfiles.R +++ b/build/scripts/generate-main-dockerfiles.R @@ -47,7 +47,9 @@ df_args <- fs::dir_ls(path = "build/args", glob = "*.json") |> purrr::modify_if(is.null, \(x) NA) |> tibble::as_tibble() ) |> - purrr::list_rbind() + purrr::list_rbind() |> + # Limit to the last 2 versions and devel + utils::tail(3) tibble::tibble( diff --git a/build/scripts/generate-matrix.R b/build/scripts/generate-matrix.R new file mode 100644 index 00000000..5f2c3893 --- /dev/null +++ b/build/scripts/generate-matrix.R @@ -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")