-
Notifications
You must be signed in to change notification settings - Fork 217
/
Copy pathaction.yaml
210 lines (201 loc) · 9.31 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
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" and "devel".'
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'
runs:
using: "composite"
steps:
- name: Set site library path
run: |
# Set site library path
cat("::group::Set site library path\n")
if (Sys.getenv("RENV_PROJECT") != "") {
message("renv project detected, no need to set R_LIBS_SITE")
cat(sprintf("R_LIB_FOR_PAK=%s\n", .libPaths()[1]), file = Sys.getenv("GITHUB_ENV"), append = TRUE)
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)
cat(sprintf("R_LIB_FOR_PAK=%s\n", lib), file = Sys.getenv("GITHUB_ENV"), append = TRUE)
message("Setting R_LIBS_SITE to ", lib)
} else {
message("R_LIBS_SITE is already set to ", lib)
cat(sprintf("R_LIB_FOR_PAK=%s\n", strsplit(lib, .Platform$path.sep)[[1]][[1]]), file = Sys.getenv("GITHUB_ENV"), append = TRUE)
}
cat("::endgroup::\n")
shell: Rscript {0}
- name: Install pak (Windows)
if: runner.os == 'Windows'
run: |
# Install pak
cat("::group::Install pak\n")
lib <- Sys.getenv("R_LIB_FOR_PAK")
dir.create(lib, showWarnings = FALSE, recursive = TRUE)
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'
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 '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: 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]])
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: R package cache
if: inputs.cache != 'false'
uses: actions/cache@v4
with:
path: |
${{ env.R_LIBS_USER }}/*
!${{ env.R_LIBS_USER }}/pak
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) }}
# Used to save package installation on troublesome Actions
save-always: ${{ inputs.cache == 'always' }}
- 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: |
cat("::group::Check if package needs pandoc\n")
o <- '${{ inputs.install-pandoc }}'
if (! o %in% c('true', 'false')) {
if (Sys.which("pandoc") != "") {
o <- 'false'
} else if (file.exists("DESCRIPTION")) {
deptypes <- list(direct = "all", indirect = character())
deps <- pak::pkg_deps(".", dependencies = deptypes)
if ("rmarkdown" %in% deps$package) {
o <- 'true'
} else {
o <- 'false'
}
} else {
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: 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