-
Notifications
You must be signed in to change notification settings - Fork 2
329 lines (280 loc) · 11.3 KB
/
ci.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
---
name: CI
# yamllint disable-line rule:truthy
on:
push:
branches:
- develop
workflow_dispatch:
repository_dispatch:
concurrency:
group: ci
cancel-in-progress: true
jobs:
lint:
name: Apply lintr in all R and Rmd files
runs-on: ubuntu-latest
# runs-on: self-hosted
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RENV_PATHS_ROOT: ~/.local/share/renv
steps:
- name: Checking out shallow repository
uses: actions/checkout@v2
- run: git branch
- name: Setting up R installation
uses: r-lib/actions/setup-r@v2
- name: Cache R packages
uses: actions/cache@v2.1.4
id: cache-packages
with:
path: ${{ env.RENV_PATHS_ROOT }}
key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}-targets-v2
restore-keys: |
${{ runner.os }}-renv-
- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}
- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install other dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgit2-dev libharfbuzz-dev libcurl4-openssl-dev \
libfribidi-dev libzmq3-dev libmagick++-dev
- name: Install dependencies
run: |
if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv")
Sys.unsetenv("GITHUB_PAT")
renv::restore()
shell: Rscript {0}
- name: Lint
run: |
library(lintr)
for (i in c("analysis", "R", "scripts", "review", "thesis", "output")) {
print(lint_dir(i, linters = with_defaults(
open_curly_linter = NULL, T_and_F_symbol_linter,
assignment_linter, closed_curly_linter = NULL, commas_linter, commented_code_linter = NULL,
cyclocomp_linter(50), object_name_linter(styles = "snake_case"), object_length_linter(30),
equals_na_linter, function_left_parentheses_linter, infix_spaces_linter,
line_length_linter(500), no_tab_linter, object_usage_linter = NULL, paren_brace_linter,
absolute_path_linter(lax = TRUE), nonportable_path_linter = NULL, pipe_continuation_linter,
semicolon_terminator_linter(semicolon = "trailing"), seq_linter, single_quotes_linter,
spaces_inside_linter, spaces_left_parentheses_linter, trailing_blank_lines_linter,
trailing_whitespace_linter, undesirable_function_linter, undesirable_operator_linter,
unneeded_concatenation_linter
), exclusions = list("R/RcppExports.R")))
}
shell: Rscript {0}
targets:
name: Run targets pipeline
needs: lint
runs-on: ubuntu-latest
# runs-on: self-hosted
if: "contains(github.event.head_commit.message, 'targets')"
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RENV_PATHS_ROOT: ~/.local/share/renv
steps:
- name: Checking out shallow repository
uses: actions/checkout@v2
- run: git branch
- name: Setting up R installation
uses: r-lib/actions/setup-r@v2
- name: Setting up pandoc and pandoc-citeproc
uses: r-lib/actions/setup-pandoc@v2
- name: Cache R packages
uses: actions/cache@v2.1.4
id: cache-packages
with:
path: ${{ env.RENV_PATHS_ROOT }}
key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}-targets-v2
restore-keys: |
${{ runner.os }}-renv-
- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}
- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install other dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgit2-dev libharfbuzz-dev libcurl4-openssl-dev \
libfribidi-dev libzmq3-dev libmagick++-dev
- name: Install dependencies
run: |
if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv")
Sys.unsetenv("GITHUB_PAT")
renv::install(".")
renv::restore()
shell: Rscript {0}
- name: Check if previous runs exist
id: runs-exist
run: git ls-remote --exit-code --heads origin targets-runs
continue-on-error: true
- name: Checking out shallow previous run
if: steps.runs-exist.outcome == 'success'
uses: actions/checkout@v2
with:
ref: targets-runs
path: .targets-runs
- name: Restore output files from the previous run
if: steps.runs-exist.outcome == 'success'
run: |
for (dest in scan(".targets-runs/.targets-files", what = character())) {
source <- file.path(".targets-runs", dest)
if (!file.exists(dirname(dest))) dir.create(dirname(dest), recursive = TRUE)
if (file.exists(source)) file.rename(source, dest)
}
shell: Rscript {0}
- name: Run targets pipeline
run: renv::run('run.R')
shell: Rscript {0}
continue-on-error: true # if the pipeline fails, the workspace is saved for inspection.
- name: Identify files that the targets pipeline produced
id: check-new-files
run: |
git ls-files -mo -x renv -x inst -x src > .targets-files
([ -s .targets-files ] && echo "New files produced" && cat .targets-files && echo "::set-output name=newfiles::true") || (echo "Nothing to do" && echo "::set-output name=newfiles::false")
- name: Update the current repository without the objects
if: steps.check-new-files.outputs.newfiles == 'true'
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "actions@github.com"
git add --all -- ':!renv'
git commit -am "Update current branch"
git push --quiet
continue-on-error: true
- name: Create the runs branch if it does not already exist
if: steps.check-new-files.outputs.newfiles == 'true' && steps.runs-exist.outcome != 'success'
run: git checkout --orphan targets-runs
continue-on-error: true # if the pipeline fails, the workspace is saved for inspection.
- name: Put the worktree in the runs branch if the latter already exists
if: steps.check-new-files.outputs.newfiles == 'true' && steps.runs-exist.outcome == 'success'
run: |
rm -r .git
mv .targets-runs/.git .
rm -r .targets-runs
continue-on-error: true # if the pipeline fails, the workspace is saved for inspection.
- name: Upload latest run to the runs branch
if: steps.check-new-files.outputs.newfiles == 'true'
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "actions@github.com"
rm -r .github/workflows
git add --all -- ':!renv'
git add -f .targets-files
git add -f _targets
git commit -am "Run pipeline"
git push origin targets-runs
continue-on-error: true # if the pipeline fails, the workspace is saved for inspection.
- name: Prepare failure artifact
if: failure()
run: rm -rf .git .github .targets-files .targets-runs
- name: Post failure artifact
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r-targets-results
path: .
workflowr:
name: Runs Workflowr versioning
runs-on: ubuntu-latest
# runs-on: self-hosted
if: "contains(github.event.head_commit.message, 'workflowr')"
needs:
- lint
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RENV_PATHS_ROOT: ~/.local/share/renv
steps:
- name: Checking out deep repository
uses: actions/checkout@v2
with:
fetch-depth: 0 ## all history
ref: ${{ github.event.workflow_run.head_branch }}
- run: git branch
- run: echo ${{ github.event.head_commit.message }}
- name: Setting up R installation
uses: r-lib/actions/setup-r@v2
- name: Setting up pandoc and pandoc-citeproc
uses: r-lib/actions/setup-pandoc@v2
- name: Setting up tinytex
uses: r-lib/actions/setup-tinytex@v2
- name: Install additional LaTeX packages
run: |
tlmgr --version
tlmgr install svg subfig
tlmgr list --only-installed
- name: Cache R packages
uses: actions/cache@v2.1.4
id: cache-packages
with:
path: ${{ env.RENV_PATHS_ROOT }}
key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}-targets-v2
restore-keys: |
${{ runner.os }}-renv-
- name: Query dependencies
run: |
install.packages('remotes')
install.packages('yaml')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}
- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install other dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgit2-dev libharfbuzz-dev libcurl4-openssl-dev \
libfribidi-dev libzmq3-dev libmagick++-dev
- name: Install dependencies
run: |
if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv")
Sys.unsetenv("GITHUB_PAT")
renv::restore()
shell: Rscript {0}
# - name: pull database
# run: |
# chmod 755 run.R && ./run.R -r FALSE
# shell: bash
- name: Knit thesisdown
run: |
bookdown::render_book("thesis", output_format="all")
shell: Rscript {0}
- name: Configure git and stage changes
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "actions@github.com"
git add --all -- ':!renv'
git commit -am "Update thesisdown"
- name: Build workflowr that creates the commit
run: workflowr::wflow_publish(all = TRUE, update = TRUE, verbose = TRUE)
shell: Rscript {0}
- name: Push changes
run: |
git push