-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathaction.yaml
146 lines (141 loc) · 6.29 KB
/
action.yaml
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
name: 'setup-lesson-deps'
description: 'Action to set up package dependencies for Carpentries Lessons'
author: 'Zhian N. Kamvar'
inputs:
cache-version:
description: 'The version of the cache, change this from the default (1) to start over with a fresh cache'
required: true
default: 1
runs:
using: "composite"
steps:
- name: Get R and OS version
id: get-version
run: |
cat("os-version=", sessionInfo()$running, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
cat("r-version=", if (grepl("development", rv <- R.Version()$version.string)) as.character(getRversion()) else rv, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
shell: Rscript {0}
- name: "Restore {renv} Cache"
uses: actions/cache@v4
with:
path: ${{ env.RENV_PATHS_ROOT }}
key: renv-${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}-${{ hashFiles('**/renv.lock') }}
restore-keys: renv-${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}-
- name: "Setup System Dependencies"
shell: Rscript {0}
run: |
cat("::group::Register Repositories\n")
on_linux <- Sys.info()[["sysname"]] == "Linux"
if (on_linux) {
if (Sys.getenv("RSPM") == "") {
release <- system("lsb_release -c | awk '{print $2}'", intern = TRUE)
Sys.setenv("RSPM" =
paste0("https://packagemanager.posit.co/all/__linux__/", release, "/latest"))
}
}
repos <- list(
RSPM = Sys.getenv("RSPM"),
carpentries = "https://carpentries.r-universe.dev/",
archive = "https://carpentries.github.io/drat/",
CRAN = "https://cran.rstudio.com"
)
options(pak.no_extra_messages = TRUE, repos = repos)
cat("Repositories Used")
print(getOption("repos"))
cat("::endgroup::\n")
# Set up system dependencies
req <- function(pkg, ...) {
if (!requireNamespace(pkg, quietly = TRUE)) {
install.packages(pkg, ...)
}
}
wd <- '${{ github.workspace }}'
has_lock <- file.exists(file.path(wd, 'renv'))
if (Sys.info()[["sysname"]] == "Linux" && has_lock) {
req("renv")
req("remotes")
rmts <- asNamespace("remotes")
# extract the function
sov <- rmts$supported_os_versions
# if 22.04 is not present, we need to modify the function
if (!grepl("22.04", body(sov)[2])) {
unlockBinding("supported_os_versions", rmts)
# modify the list in the body to include 22.04
vers <- eval(parse(text = as.character(body(sov)[2])))
vers$ubuntu <- c(vers$ubuntu, "22.04")
# replace the body
body(sov)[2] <- list(str2lang(paste(capture.output(dput(vers)), collapse = "")))
# replace the function in the namespace
rmts$supported_os_versions <- sov
}
req("desc")
remotes::install_github("carpentries/vise")
if (file.exists("DESCRIPTION")) {
file.rename("DESCRIPTION", "DESCRIPTION.bak")
}
Sys.setenv("RENV_PROFILE" = "lesson-requirements")
Sys.setenv("RSPM_ROOT" = "https://packagemanager.posit.co")
vise::lock2desc(renv::paths$lockfile(), desc = "${{ github.workspace }}/DESCRIPTION")
writeLines(readLines("${{ github.workspace }}/DESCRIPTION"))
vise::ci_sysreqs(renv::paths$lockfile(), execute = TRUE)
}
- name: "Fortify Local {renv} Packages"
shell: Rscript {0}
run: |
cat("::group::Register Repositories\n")
on_linux <- Sys.info()[["sysname"]] == "Linux"
if (on_linux) {
if (Sys.getenv("RSPM") == "") {
release <- system("lsb_release -c | awk '{print $2}'", intern = TRUE)
Sys.setenv("RSPM" =
paste0("https://packagemanager.posit.co/all/__linux__/", release, "/latest"))
}
}
repos <- list(
RSPM = Sys.getenv("RSPM"),
carpentries = "https://carpentries.r-universe.dev/",
archive = "https://carpentries.github.io/drat/",
CRAN = "https://cran.rstudio.com"
)
Sys.unsetenv("RENV_CONFIG_REPOS_OVERRIDE")
options(pak.no_extra_messages = TRUE, repos = repos)
cat("Repositories Used")
print(getOption("repos"))
cat("::endgroup::\n")
# Fortify local {renv} packages
cat("::group::Fortify local {renv} packages\n")
wd <- '${{ github.workspace }}'
req <- function(pkg) {
if (!requireNamespace(pkg, quietly = TRUE))
install.packages(pkg)
}
if (file.exists("DESCRIPTION")) {
req("remotes")
remotes::install_deps()
}
cat("::endgroup::\n")
if (file.exists(file.path(wd, 'renv'))) {
cat("::group::Fortify local {renv} packages\n")
if (file.exists("DESCRIPTION.bak")) {
file.rename("DESCRIPTION.bak", "DESCRIPTION")
} else {
try(file.remove("DESCRIPTION"), silent = TRUE)
}
req("renv")
Sys.setenv("RENV_PROFILE" = "lesson-requirements")
tryCatch(sandpaper::manage_deps(path = wd, quiet = FALSE),
error = function(e) {
iss <- "https://github.com/rstudio/renv/issues/1184"
cli::cli_alert_danger("run failed... attempting to re-run (see {.url {iss}} for details.")
sandpaper::manage_deps(path = wd, quiet = FALSE)
})
cat("::endgroup::\n")
} else {
writeLines("Package cache not used")
}
- name: Don't use tar 1.30 from Rtools35 to store the cache
shell: bash
run: |
if command -v /c/Rtools/bin/tar && /c/Rtools/bin/tar --version | grep -q 'tar (GNU tar) 1.30'
then echo 'C:/Program Files/Git/usr/bin' >> $GITHUB_PATH
fi