-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_2021.R
158 lines (119 loc) · 5.44 KB
/
script_2021.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# This version of the script uses 2022 as a basis, and tries to
# build the environment "retro-actively"
# Load necessary libraries
library(git2r)
library(stringr)
library(data.table)
library(dplyr)
library(parallel)
library(BiocManager)
bioc_versions <- read.csv("bioc_versions.csv")
r_versions <- read.csv("r_versions.csv")
set_bioc_version <- function(target_date, bioc_versions){
bioc_versions |>
dplyr::arrange(desc(date)) |>
dplyr::mutate(date = as.POSIXct(date)) |>
dplyr::filter(target_date >= date) |>
head(1) |>
dplyr::pull(bioc_version)
}
set_r_version <- function(target_date, r_versions){
r_versions |>
dplyr::arrange(desc(date)) |>
dplyr::mutate(date = as.POSIXct(date)) |>
dplyr::filter(target_date >= date) |>
head(1) |>
dplyr::pull(r_version)
}
target_date <- as.POSIXct("2021-08-03 12:00:00")
commit_date <- as.POSIXct("2021-12-01 12:00:00")
previous_date <- "2022-01-16"
bioc_version <- set_bioc_version(target_date, bioc_versions)
r_version <- set_r_version(target_date, r_versions)
# Now, we try for 2021 by using this commit at january 2022
target_commit <- "7d73fd6e94000f1a5bce2ed8f1852ba848da554d"
# Set the local repository path
repo_path <- "../nixpkgs"
repo <- repository(repo_path)
target_date <- substr(target_date, 1, 10)
system(paste0("cd ", repo_path, " && git reset --hard ", target_commit))
# Replace the repository with a snapshot from posit at target date
file_path <- file.path(repo_path,
"pkgs/development/r-modules/generate-r-packages.R")
file_content <- readLines(file_path)
old_string <- paste0("cran/", previous_date)
new_string <- paste0("cran/", target_date)
modified_content <- str_replace(file_content, old_string, new_string)
writeLines(modified_content, file_path)
# Do the same for the default.nix
file_path <- file.path(repo_path,
"pkgs/development/r-modules/default.nix")
file_content <- readLines(file_path)
old_string <- paste0("cran/", previous_date)
new_string <- paste0("cran/", target_date)
modified_content <- str_replace_all(file_content, old_string, new_string)
writeLines(modified_content, file_path)
# Download previous file to make bumping faster
system(paste0("cd ",
repo_path,
paste0("/pkgs/development/r-modules/ && rm bioc-annotation-packages.nix && wget https://raw.githubusercontent.com/rstats-on-nix/nixpkgs/refs/heads/",
previous_date, "/pkgs/development/r-modules/bioc-annotation-packages.nix")))
system(paste0("cd ",
repo_path,
paste0("/pkgs/development/r-modules/ && rm bioc-experiment-packages.nix && wget https://raw.githubusercontent.com/rstats-on-nix/nixpkgs/refs/heads/",
previous_date, "/pkgs/development/r-modules/bioc-experiment-packages.nix")))
system(paste0("cd ",
repo_path,
paste0("/pkgs/development/r-modules/ && rm bioc-packages.nix && wget https://raw.githubusercontent.com/rstats-on-nix/nixpkgs/refs/heads/",
previous_date, "/pkgs/development/r-modules/bioc-packages.nix")))
system(paste0("cd ",
repo_path,
paste0("/pkgs/development/r-modules/ && rm cran-packages.nix && wget https://raw.githubusercontent.com/rstats-on-nix/nixpkgs/refs/heads/",
previous_date, "/pkgs/development/r-modules/cran-packages.nix")))
# Bump the tree
system(paste0("cd ",
repo_path,
"/pkgs/development/r-modules/ && Rscript generate-r-packages.R cran > new && mv new cran-packages.nix"))
system(paste0("cd ",
repo_path,
"/pkgs/development/r-modules/ && Rscript generate-r-packages.R bioc > new && mv new bioc-packages.nix"))
system(paste0("cd ",
repo_path,
"/pkgs/development/r-modules/ && Rscript generate-r-packages.R bioc-annotation > new && mv new bioc-annotation-packages.nix"))
system(paste0("cd ",
repo_path,
"/pkgs/development/r-modules/ && Rscript generate-r-packages.R bioc-experiment > new && mv new bioc-experiment-packages.nix"))
# .dev attribute from dependencies needs to be removed because it wasn't always
# used
system(paste0("cd ",
repo_path,
"/pkgs/development/r-modules/ && sed -i 's/\\.dev / /g' default.nix"))
# For some reason r_import is defined twice, but the one where
# name = r_import is wrong so let's get rid of that
system(paste0("cd ",
repo_path,
"/pkgs/development/r-modules/ && ",
"sed -i '/r_import.*name=\"r_import\"/d' cran-packages.nix")
)
# Get correct version of R for that day. It should be the same as the
# one in nixpkgs at that time most of the time
system(paste0("cp r_versions/", r_version, ".nix ",
repo_path,
"/pkgs/applications/science/math/R/default.nix"
))
# Put the GA workflow file in there to build on build_tree repo
system(paste0("cp trigger_build.yml ",
repo_path,
"/.github/workflows/"
))
# Update date in trigger_build.yml
system(paste0("cd ",
repo_path,
"/.github/workflows/ && ",
paste0("sed -i 's|REPLACE_DATE|", target_date, "|g' trigger_build.yml"))
)
system(paste0("cd ",
repo_path,
" && git checkout -b '", target_date, "'",
" && git add . && git commit -m 'R CRAN update'",
" && git push --force origin ", target_date))