-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathr-ci.yml
279 lines (246 loc) · 9.22 KB
/
r-ci.yml
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
---
# Run the playbook using:
# ansible-playbook -i localhost, r-ci.yml
# Use the 'sysreqs' variable to specify a comma separated list of
# system requirements that must be present.
# Example:
# ansible-playbook -i localhost, --extra-vars "sysreqs=gdal-devel,geos-devel,proj-devel,sqlite-devel" r-ci.yml
# Default is to run static code analysis of the R code using lintr.
# Set 'r_ci_lintr=false' to disable this check.
# Example:
# ansible-playbook -i localhost, --extra-vars "r_ci_lintr=false" r-ci.yml
# Use the 'r_ci_covr' variable to run covr on a package and specify
# the target for the code coverage report.
# Valid targets are:
# - azure: output the result so it is available on Azure Pipelines
# - codecov: upload the result to codecov.io
# - coveralls: upload the result to coveralls
# - gitlab: create report for GitLab
# - standalone: output the result 'covr.html'
# Example, run code coverage and output the result to 'covr.html':
# ansible-playbook -i localhost, --extra-vars "r_ci_covr=standalone" r-ci.yml
# Use raw to disable tag processing {% raw %}
- name: Run the playbook to check the package
hosts: localhost
connection: local
vars:
r_ci_build_args: --no-build-vignettes --no-manual
r_ci_check_args: --ignore-vignettes --no-manual --no-stop-on-test-error --as-cran
r_ci_lintr: true
r_ci_repos: https://cloud.r-project.org
tasks:
- name: Check if R is installed
ansible.builtin.command:
cmd: R --version
register: is_r_installed
changed_when: false
failed_when: false
become: false
- name: Install R
ansible.builtin.dnf:
name:
- devscripts-checkbashisms
- dnf-command(copr)
- R
- tidy
state: present
become: true
when: is_r_installed.rc != 0
- name: Install the 'checkbashisms' script on Ubuntu
ansible.builtin.package:
name:
- devscripts
state: present
become: true
when: ansible_facts['distribution'] == "Ubuntu"
- name: Install system requirements
ansible.builtin.package:
name: "{{ sysreqs.split(',') }}"
state: present
become: true
when: sysreqs is defined
- name: Enable the iucar/cran Copr repo
ansible.builtin.command:
cmd: dnf --assumeyes copr enable iucar/cran
become: true
when: is_r_installed.rc != 0
- name: Setup Copr to install binary R packages
ansible.builtin.dnf:
name: R-CoprManager
state: present
become: true
when: is_r_installed.rc != 0
- name: Determine the package name from the DESCRIPTION file
ansible.builtin.command:
cmd: >
Rscript --vanilla
-e "x <- tryCatch(read.dcf('DESCRIPTION', 'Package'), error = function(e) NULL)"
-e "if (is.null(x)) quit(save = 'no', status = 1, runLast = FALSE)"
-e "cat(x)"
chdir: "{{ lookup('env', 'PWD') }}"
register: pkg_name
changed_when: false
become: false
- name: Determine the package version from the DESCRIPTION file
ansible.builtin.command:
cmd: >
Rscript --vanilla
-e "x <- tryCatch(read.dcf('DESCRIPTION', 'Version'), error = function(e) NULL)"
-e "if (is.null(x)) quit(save = 'no', status = 1, runLast = FALSE)"
-e "cat(x)"
chdir: "{{ lookup('env', 'PWD') }}"
register: pkg_version
changed_when: false
become: false
- name: Install package dependencies
ansible.builtin.command:
cmd: >
Rscript
-e "fields <- c('Imports', 'Depends', 'Suggests')"
-e "x <- tryCatch(read.dcf('DESCRIPTION', fields), error = function(e) NULL)"
-e "if (is.null(x)) quit(save = 'no', status = 1, runLast = FALSE)"
-e "x <- trimws(unlist(strsplit(as.character(x), ',')))"
-e "x <- vapply(strsplit(x, ' '), '[[', character(1), 1)"
-e "x <- unique(x[x != 'R'])"
-e "x <- x[!(x %in% installed.packages()[, 1])]"
-e "if (length(x)) install.packages(x, repos = '{{ r_ci_repos }}')"
-e "cat(length(x) > 0)"
chdir: "{{ lookup('env', 'PWD') }}"
register: pkg_dependencies
changed_when: "'TRUE' in pkg_dependencies.stdout"
become: false
- name: Build the package
ansible.builtin.command:
cmd: "R CMD build {{ r_ci_build_args }} ."
chdir: "{{ lookup('env', 'PWD') }}"
register: pkg_build_log
changed_when: false
failed_when: false
become: false
- name: Display the package build log
ansible.builtin.debug:
msg: "{{ pkg_build_log.stdout_lines + pkg_build_log.stderr_lines }}"
failed_when: pkg_build_log.rc != 0
become: false
- name: Check the package
ansible.builtin.command:
cmd: "R CMD check {{ r_ci_check_args }} {{ pkg_name.stdout }}_{{ pkg_version.stdout }}.tar.gz"
chdir: "{{ lookup('env', 'PWD') }}"
environment:
_R_CHECK_CRAN_INCOMING_: "FALSE"
_R_CHECK_SYSTEM_CLOCK_: "FALSE"
register: pkg_check
changed_when: false
failed_when: false
become: false
- name: Check if the package install log exists
ansible.builtin.stat:
path: "{{ lookup('env', 'PWD') }}/{{ pkg_name.stdout }}.Rcheck/00install.out"
register: pkg_install
become: false
- name: Read the package install log
ansible.builtin.command:
cmd: cat "{{ pkg_name.stdout }}.Rcheck/00install.out"
chdir: "{{ lookup('env', 'PWD') }}"
register: pkg_install_log
changed_when: false
become: false
when: pkg_install.stat.exists
- name: Display the package install log
ansible.builtin.debug:
msg: "{{ pkg_install_log.stdout_lines }}"
changed_when: false
become: false
when: pkg_install.stat.exists
- name: Check if the package check log exists
ansible.builtin.stat:
path: "{{ lookup('env', 'PWD') }}/{{ pkg_name.stdout }}.Rcheck/00check.log"
register: pkg_00check
failed_when: pkg_00check.stat.exists == false
become: false
- name: Read the package check log
ansible.builtin.command:
cmd: "cat {{ pkg_name.stdout }}.Rcheck/00check.log"
chdir: "{{ lookup('env', 'PWD') }}"
register: pkg_check_log
changed_when: false
become: false
when: pkg_00check.stat.exists
- name: Display the package check log
ansible.builtin.debug:
msg: "{{ pkg_check_log.stdout_lines }}"
failed_when: pkg_check.rc != 0 or "WARNING" in pkg_check_log.stdout
become: false
when: pkg_00check.stat.exists
- name: Check if lintr is installed
ansible.builtin.command:
cmd: Rscript -e "cat(any(installed.packages()[, 1] == 'lintr'))"
chdir: "{{ lookup('env', 'PWD') }}"
register: is_lintr_installed
changed_when: false
become: false
when: r_ci_lintr | bool
- name: Install lintr
ansible.builtin.command:
cmd: Rscript -e "install.packages('lintr', repos = '{{ r_ci_repos }}')"
chdir: "{{ lookup('env', 'PWD') }}"
become: false
when: r_ci_lintr | bool and is_lintr_installed.stdout == "FALSE"
- name: Install package
ansible.builtin.command:
cmd: "R CMD INSTALL {{ pkg_name.stdout }}_{{ pkg_version.stdout }}.tar.gz"
chdir: "{{ lookup('env', 'PWD') }}"
become: false
when: r_ci_lintr | bool
- name: Static code analysis of R code using lintr
ansible.builtin.command:
cmd: >
Rscript
-e "library(lintr)"
-e "result <- lint_package()"
-e "print(result)"
-e "quit(save = 'no', status = length(result) > 0)"
chdir: "{{ lookup('env', 'PWD') }}"
register: pkg_lintr_log
changed_when: false
failed_when: false
become: false
when: r_ci_lintr | bool
- name: Display the package lintr log
ansible.builtin.debug:
msg: "{{ pkg_lintr_log.stdout_lines }}"
failed_when: pkg_lintr_log.rc != 0
become: false
when: r_ci_lintr | bool
- name: Check if covr is installed
ansible.builtin.command:
cmd: Rscript -e "cat(any(installed.packages()[, 1] == 'covr'))"
chdir: "{{ lookup('env', 'PWD') }}"
register: is_covr_installed
changed_when: false
become: false
when: r_ci_covr is defined
- name: Install covr
ansible.builtin.command:
cmd: Rscript -e "install.packages('covr', repos = '{{ r_ci_repos }}')"
chdir: "{{ lookup('env', 'PWD') }}"
become: false
when: r_ci_covr is defined and is_covr_installed.stdout == "FALSE"
- name: Run code coverage
ansible.builtin.command:
cmd: >
Rscript
-e "library(covr)"
-e "targets <- c('azure', 'codecov', 'coveralls', 'gitlab', 'standalone')"
-e "target <- match.arg('{{ r_ci_covr }}', targets)"
-e "switch(target,"
-e " azure = azure(),"
-e " codecov = codecov(),"
-e " coveralls = coveralls(),"
-e " gitlab = gitlab(),"
-e " standalone = report(file = 'covr.html'))"
chdir: "{{ lookup('env', 'PWD') }}"
changed_when: false
become: false
when: r_ci_covr is defined
# {% endraw %}