-
Notifications
You must be signed in to change notification settings - Fork 218
/
Copy pathaction.yaml
336 lines (321 loc) · 14.8 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
name: 'setup-r-dependencies'
description: 'Action to setup installation tools and install R dependencies'
author: 'Jim Hester'
inputs:
cache:
description: 'Whether packages should be cached across runs or not. If `"always"` is provided, the package cache will be saved even if the workflow fails.'
required: true
default: true
cache-version:
description: 'The version of the cache, change this from the default (1) to start over with a fresh cache. Ignored if cache: false'
required: true
default: 1
extra-packages:
description: 'Any extra packages to install outside of the packages listed in the dependencies'
needs:
description: 'Any extra Config/Needs fields which need to be included when installing dependencies'
packages:
description: 'Which package(s) to install.'
default: 'deps::., any::sessioninfo'
pak-version:
description: |
Which pak version to use. Possible values are "stable", "rc",
"devel", "none", "repo". The first three install pak from our
repository at GitHub Pages.
"none" will skip pak installation. Use this if you want to install
pak yourself. Set the `R_LIB_FOR_PAK` environment variable to point
to the library where pak is installed.
`repo` means that the action will install pak from the configured
repositories, using `install.packages()`. `repo` is appropriate on
systems that do not have access to our pak reporitory on GitHUb.
default: 'stable'
working-directory:
description: 'Using the working-directory keyword, you can specify the working directory of where "pkg_deps" command searches for dependencies in the "DESCRIPTION" file.'
default: '.'
dependencies:
description: 'Types of dependencies to install. Must be an R expression. Note that it often needs to be quoted in YAML, see the README for details.'
default: '"all"'
upgrade:
description: 'Whether to install the latest available versions of the dependencies. Must be an R expression. See the README for details if you need quoting.'
default: 'FALSE'
lockfile-create-lib:
description: 'The package library to consider when creating the pak lockfile. This is passed to the `lib` argument of `pak::lockfile_create()`. Defaults to an empty library, for reproducibility. Must be an R expression. Note that it often needs to be quoted in YAML, see the README for detail\
s.'
default: 'NULL'
install-pandoc:
description: 'Whether to install pandoc. By default it is installed if it is not on the PATH and the local package suggests or depends on the rmarkdown package.'
pandoc-version:
description: 'Pandoc version to install.'
default: '3.1.11'
install-quarto:
description: |
Whether to install quarto. If it is 'auto' (the default), it is
installed if there is at least one `.qmd` file in the repository,
inside `working-directory`. Set to 'true' to always install it.
Set to 'false' to never install it.
default: 'auto'
quarto-version:
description: |
Version of quarto to install, if quarto is installed. It is passed
to the `quarto-dev/quarto-actions/setup@v2` action. The default is
'release' to install the latest release. Other possible values are
a version number number (without the `v` prefix), and 'pre-release'.
default: 'release'
runs:
using: "composite"
steps:
- name: Set site library path
run: |
# Set site library path
cat("::group::Set site library path\n")
libpak <- Sys.getenv("R_LIB_FOR_PAK")
if (libpak != "") {
message("R_LIB_FOR_PAK is already set to ", libpak)
}
if (Sys.getenv("RENV_PROJECT") != "") {
message("renv project detected, no need to set R_LIBS_SITE")
if (libpak == "") {
cat(sprintf("R_LIB_FOR_PAK=%s\n", .libPaths()[1]), file = Sys.getenv("GITHUB_ENV"), append = TRUE)
message("Setting R_LIB_FOR_PAK to ", .libPaths()[1])
}
q("no")
}
lib <- Sys.getenv("R_LIBS_SITE")
if (lib == "") {
lib <- file.path(dirname(.Library), "site-library")
cat(sprintf("R_LIBS_SITE=%s\n", lib), file = Sys.getenv("GITHUB_ENV"), append = TRUE)
message("Setting R_LIBS_SITE to ", lib)
if (libpak == "") {
cat(sprintf("R_LIB_FOR_PAK=%s\n", lib), file = Sys.getenv("GITHUB_ENV"), append = TRUE)
message("Setting R_LIB_FOR_PAK to ", lib)
}
} else {
message("R_LIBS_SITE is already set to ", lib)
if (libpak == "") {
plib <- strsplit(lib, .Platform$path.sep)[[1]][[1]]
cat(sprintf("R_LIB_FOR_PAK=%s\n", plib), file = Sys.getenv("GITHUB_ENV"), append = TRUE)
message("Setting R_LIB_FOR_PAK to ", plib)
}
}
if (nchar("${{ env.R_LIBS_USER && 'ok' || '' }}") == 0) {
message("R_LIBS_USER GH env var is unset, setting now: ", Sys.getenv("R_LIBS_USER"))
cat(sprintf("R_LIBS_USER=%s\n", Sys.getenv("R_LIBS_USER")), file = Sys.getenv("GITHUB_ENV"), append = TRUE)
} else {
message("R_LIBS_USER GH env var is already set: ", Sys.getenv("R_LIBS_USER"))
}
dir.create(Sys.getenv("R_LIBS_SITE"), recursive = TRUE, showWarnings = FALSE)
dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE, showWarnings = FALSE)
cat("::endgroup::\n")
shell: Rscript {0}
- name: Install pak (Windows)
if: ${{ runner.os == 'Windows' && inputs.pak-version != 'none' }}
run: |
# Install pak
cat("::group::Install pak\n")
lib <- Sys.getenv("R_LIB_FOR_PAK")
dir.create(lib, showWarnings = FALSE, recursive = TRUE)
if ("${{ inputs.pak-version }}" == "repo") {
install.packages("pak", lib = lib)
} else {
install.packages("pak", lib = lib, repos = sprintf(
"https://r-lib.github.io/p/pak/%s/%s/%s/%s",
"${{ inputs.pak-version }}",
.Platform$pkgType,
R.Version()$os,
R.Version()$arch
))
}
cat("::endgroup::\n")
shell: Rscript {0}
- name: Install pak (Unix)
if: ${{ runner.os != 'Windows' && inputs.pak-version != 'none' }}
run: |
# Install pak
echo "::group::Install pak"
if which sudo >/dev/null; then SUDO="sudo -E --preserve-env=PATH env"; else SUDO=""; fi
$SUDO R -q -e 'dir.create(Sys.getenv("R_LIB_FOR_PAK"), recursive = TRUE, showWarnings = FALSE)'
$SUDO R -q -e 'if ("${{ inputs.pak-version }}" == "repo") { install.packages("pak", lib = Sys.getenv("R_LIB_FOR_PAK")) } else { install.packages("pak", lib = Sys.getenv("R_LIB_FOR_PAK"), repos = sprintf("https://r-lib.github.io/p/pak/%s/%s/%s/%s", "${{ inputs.pak-version }}", .Platform$pkgType, R.Version()$os, R.Version()$arch)) }'
echo "::endgroup::"
shell: bash
- name: Repo status
run: |
# Repo status
cat("::group::Repo status\n")
options(width = 1000)
pak::repo_status()
cat("::endgroup::\n")
shell: Rscript {0}
- name: Query dependencies
id: install
run: |
# Dependency resolution
cat("::group::Dependency resolution\n")
cat("os-version=", sessionInfo()$running, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
r_version <-
if (grepl("development", R.version.string)) {
pdf(tempfile())
ge_ver <- attr(recordPlot(), "engineVersion")
dev.off()
paste0("R version ", getRversion(), " (ge:", ge_ver, "; iid:", .Internal(internalsID()), ")")
} else {
R.version.string
}
cat("r-version=", r_version, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
needs <- sprintf("Config/Needs/%s", strsplit("${{ inputs.needs }}", "[[:space:],]+")[[1]])
if (length(needs) == 0L) needs <- NULL
deps <- strsplit("${{ inputs.packages }}", "[[:space:],]+")[[1]]
extra_deps <- strsplit("${{ inputs.extra-packages }}", "[[:space:],]+")[[1]]
dir.create(".github", showWarnings=FALSE)
Sys.setenv("PKGCACHE_HTTP_VERSION" = "2")
library(pak, lib.loc = Sys.getenv("R_LIB_FOR_PAK"))
pak::lockfile_create(
c(deps, extra_deps),
lockfile = ".github/pkg.lock",
upgrade = (${{ inputs.upgrade }}),
dependencies = c(needs, (${{ inputs.dependencies }})),
lib = ${{ inputs.lockfile-create-lib }}
)
cat("::endgroup::\n")
cat("::group::Show Lockfile\n")
writeLines(readLines(".github/pkg.lock"))
cat("::endgroup::\n")
shell: Rscript {0}
working-directory: ${{ inputs.working-directory }}
- name: Adjust PATH to avoid using zstd from Rtools
if: runner.os == 'Windows'
shell: bash
run: |
echo 'C:/tools/zstd' >> $GITHUB_PATH
- name: R package cache
if: inputs.cache == 'true'
uses: actions/cache@v4
with:
path: |
${{ env.R_LIBS_USER }}/*
renv/library
!${{ env.R_LIBS_USER }}/pak
!${{ env.R_LIBS_USER }}/_cache
key: ${{ format('{0}-{1}-{2}-{3}', steps.install.outputs.os-version, steps.install.outputs.r-version, inputs.cache-version, hashFiles(format('{0}/.github/pkg.lock', inputs.working-directory ))) }}
restore-keys: ${{ format('{0}-{1}-{2}-', steps.install.outputs.os-version, steps.install.outputs.r-version, inputs.cache-version) }}
- name: R package cache restore
id: cache-packages-restore
if: inputs.cache == 'always'
uses: actions/cache/restore@v4
with:
path: |
${{ env.R_LIBS_USER }}/*
renv/library
!${{ env.R_LIBS_USER }}/pak
!${{ env.R_LIBS_USER }}/_cache
key: ${{ format('{0}-{1}-{2}-{3}', steps.install.outputs.os-version, steps.install.outputs.r-version, inputs.cache-version, hashFiles(format('{0}/.github/pkg.lock', inputs.working-directory ))) }}
restore-keys: ${{ format('{0}-{1}-{2}-', steps.install.outputs.os-version, steps.install.outputs.r-version, inputs.cache-version) }}
- name: Install dependencies
run: |
# Install/Update packages
cat("::group::Install/update packages\n")
Sys.setenv("PKGCACHE_HTTP_VERSION" = "2")
library(pak, lib.loc = Sys.getenv("R_LIB_FOR_PAK"))
pak::lockfile_install(".github/pkg.lock")
## Clean up lock file
unlink(".github/pkg.lock")
cat("::endgroup::\n")
shell: Rscript {0}
working-directory: ${{ inputs.working-directory }}
- name: Check whether pandoc needs to be installed
id: check-pandoc
run: |
# Pandoc check
cat("::group::Check if package needs pandoc\n")
o <- '${{ inputs.install-pandoc }}'
if (! o %in% c('true', 'false')) {
if (Sys.which("pandoc") != "") {
cat("Pandoc is already installed at", Sys.which("pandoc"), "\n")
o <- 'false'
} else if (file.exists("DESCRIPTION")) {
deptypes <- list(direct = "all", indirect = character())
deps <- pak::pkg_deps(".", dependencies = deptypes)
if ("rmarkdown" %in% deps$package) {
cat("Pandoc is needed for rmarkdown\n")
o <- 'true'
} else {
cat("Pandoc is not needed\n")
o <- 'false'
}
} else {
cat("Pandoc is not needed, no R package found\n")
o <- 'false'
}
}
cat("install=", o, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
cat("::endgroup::\n")
shell: Rscript {0}
working-directory: ${{ inputs.working-directory }}
- name: Install pandoc if needed
if: ${{ steps.check-pandoc.outputs.install == 'true' }}
uses: r-lib/actions/setup-pandoc@v2
with:
pandoc-version: ${{ inputs.pandoc-version }}
- name: Check whether quarto if needed
id: check-quarto
run: |
# Quarto check
cat("::group::Check if package needs quarto\n")
o <- '${{ inputs.install-quarto }}'
if (! o %in% c('true', 'false')) {
if (Sys.which("quarto") != "") {
cat("Quarto is already installed at", Sys.which("quarto"), "\n")
o <- "false"
} else {
qmd <- dir(recursive = TRUE, pattern = "[.]qmd$")
if (length(qmd) > 0) {
cat("Quarto is needed for qmd file(s):", qmd[1], "...\n")
o <- "true"
} else {
cat("No qmd files found, Quarto is not needed.\n")
o <- "false"
}
}
}
cat("install=", o, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
cat("::endgroup::\n")
shell: Rscript {0}
working-directory: ${{ inputs.working-directory }}
- name: Install quarto if needed
if: ${{ steps.check-quarto.outputs.install == 'true' }}
uses: quarto-dev/quarto-actions/setup@9e48da27e184aa238fcb49f5db75469626d43adb
with:
version: ${{ inputs.quarto-version }}
- name: Session info
run: |
# Session info
cat("::group::Session info\n")
if (requireNamespace("sessioninfo", quietly = TRUE)) {
if (packageVersion("sessioninfo") >= "1.2.1") {
sessioninfo::session_info(pkgs = "installed", include_base = TRUE)
} else {
options(width = 200)
sessioninfo::session_info(rownames(installed.packages()), include_base=TRUE)
}
} else {
sessionInfo()
}
cat("::endgroup::\n")
shell: Rscript {0}
working-directory: ${{ inputs.working-directory }}
- name: Don't use tar 1.30 from Rtools35 to store the cache
if: runner.os == 'Windows'
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
- name: R package cache save
if: ${{ always() && steps.cache-packages-restore.outputs.cache-hit != 'true' && inputs.cache == 'always' }}
uses: actions/cache/save@v4
with:
path: |
${{ env.R_LIBS_USER }}/*
renv/library
!${{ env.R_LIBS_USER }}/pak
!${{ env.R_LIBS_USER }}/_cache
key: ${{ steps.cache-packages-restore.outputs.cache-primary-key }}