-
Notifications
You must be signed in to change notification settings - Fork 5
/
template.qmd
271 lines (230 loc) · 7.69 KB
/
template.qmd
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
---
title: "Validation Report - `r sprintf('%s (v%s)',(dcf <- read.dcf(file.path(Sys.getenv('INPUT_REPORT_PKG_DIR', '.'), 'DESCRIPTION')))[,'Package'], dcf[,'Version'])`"
date: "`r Sys.time()`"
date-format: "ddd MMM DD hh:mm:ss A YYYY"
format:
typst:
toc: true
section-numbering: 1.1.1
df-print: default
margin:
x: 2cm
y: 2cm
---
```{r setup, include = FALSE}
options(width = 80L, covr.record_tests = TRUE)
remotes::install_local(
Sys.getenv('INPUT_REPORT_PKG_DIR', '.'),
force = TRUE,
quiet = TRUE,
INSTALL_opts = "--with-keep.source",
upgrade = "never"
)
library(magrittr)
library(tinytable)
```
# Context
This report was generated via the GH-action insightsengineering/validatoR (gh-action ID: `r Sys.getenv("GITHUB_ACTION")`). It produces automated
documentation of the installation of this package on an open source R environment, focussing on:
- Installation environment description
- Testing coverage
- Traceability matrix of specifications (documented behaviours) and testing
- Risk assessment benchmarks
This report is fully automated, so is limited to assess whether unit tests and documentation are present and can execute without error. An assessment would be required that the tests and documentation are meaningful. Validation aims to be system independent as the underlying workflow is based on the ["composite"](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action) type of Github Action.
# Installation environment and package
## System Info
```{r execution_info, echo = FALSE}
tt_sys_info_df <- data.frame(
Field = c("OS", "Platform", "System", "Execution Time"),
Value = c(
sessionInfo()$running,
R.version$platform,
R.version$system,
format(Sys.time(), tz = "UTC", usetz = TRUE)
)) %>%
dplyr::mutate(Value = paste0("``` ", Value, " ```"))
tt(
tt_sys_info_df,
caption = "System information",
theme = "bootstrap"
)
```
## Package installed
```{r version_control, echo = FALSE}
# find .git dir containing the package directory
gd <- system(
sprintf("cd '%s' && git rev-parse --absolute-git-dir", Sys.getenv('INPUT_REPORT_PKG_DIR', '.')),
intern = TRUE
)
# define reused git args to be sure we're picking up the right git info
gd <- sprintf("--git-dir='%s'", gd)
wt <- sprintf("--work-tree='%s'", Sys.getenv('INPUT_REPORT_PKG_DIR', '.'))
tt_git_df <- data.frame(
Field = c("server", "repository", "git ref", "branch", "commit `SHA1`", "commit date"),
Value = c(
Sys.getenv('GITHUB_SERVER_URL'),
Sys.getenv('GITHUB_REPOSITORY'),
Sys.getenv('GITHUB_REF'),
system2(
"git",
list(gd, wt, "rev-parse", "--abbrev-ref", "HEAD"),
stdout = TRUE
),
system2("git", list(gd, wt, "rev-parse", "HEAD"), stdout = TRUE),
system2(
"git",
list(gd, wt, "show", "-s", "--format=%ci", "HEAD"),
stdout = TRUE
)
)) %>%
dplyr::mutate(Value = paste0("``` ", Value, " ```"))
tt(
tt_git_df,
caption = "Git information",
theme = "bootstrap"
)
```
## R Session Info
```{r session_info, echo = TRUE, eval = TRUE}
sessionInfo()
capabilities()
```
# Metric based risk assessment
The following metrics are derived from the `riskmetric` R package. Metrics overlapping with `covr` and `R CMD Check` are removed.
```{r riskmetric, echo = FALSE, eval = TRUE}
d_riskmetric <- Sys.getenv('INPUT_REPORT_PKG_DIR', '.') %>%
riskmetric::pkg_ref() %>%
riskmetric::pkg_assess() %>%
purrr::map(1) %>%
lapply(as.character) %>%
tibble::enframe() %>%
tidyr::unnest(cols = dplyr::everything()) %>%
# add labels
dplyr::left_join(
lapply(riskmetric::all_assessments(), attributes) %>%
purrr::map_df(tibble::as_tibble),
by = c("name" = "column_name")
)
tt_riskmetric_df <- d_riskmetric %>%
dplyr::filter(
name %in% c(
"news_current", "has_vignettes",
"license", "downloads_1yr"
)
) %>%
dplyr::select(Metric = label, Status = value)
tt(
tt_riskmetric_df,
caption = "Package info assessed by the R package riskmetric",
theme = "bootstrap"
)
```
# Installation documentation
## `R CMD check`
```{r r_cmd_check, echo = FALSE, eval = TRUE}
rcmdcheck_results <- rcmdcheck::rcmdcheck(
Sys.getenv('INPUT_REPORT_PKG_DIR', '.'),
args = c(
"--timings", # include execution times in output
"--no-build-vignettes", # run vignette code, but disable pdf rendering
"--no-manual" # disable pdf manual rendering
),
quiet = TRUE
)
cat(rcmdcheck_results$stdout)
cat(rcmdcheck_results$stderr)
```
## Testing Coverage
```{r coverage, echo = FALSE, eval = TRUE}
covr_results <- covr::package_coverage(Sys.getenv('INPUT_REPORT_PKG_DIR', '.'))
covr_results
```
## Traceability
Tracebility matrix that maps each unit test to the corresponding documentation, creating a link
between intended use and testing.
```{=typst}
#show figure: set block(breakable: true)
```
### Testing matrix
```{r traceability, echo = FALSE, eval = TRUE}
if (require("covtracer", quietly = TRUE)) {
covtracer_df <- test_trace_df(covr_results)
covtracer_df$filename <- basename(covtracer_df$filepath)
covtracer_df_clean <- covtracer_df %>%
dplyr::select(
alias,
test_name,
file,
is_exported,
doctype,
direct
) %>%
dplyr::filter(!doctype %in% c("data", "class")) %>% # ignore objects without testable code
dplyr::filter(is_exported == TRUE) %>% # Only exported
dplyr::filter(!duplicated(.)) %>%
dplyr::mutate(alias = paste0(alias, "()")) %>%
dplyr::mutate(file = paste0("man/", file))
tt_covtracer_df <- covtracer_df_clean %>%
dplyr::filter(!duplicated(.)) %>%
dplyr::filter(!is.na(test_name)) %>%
dplyr::filter(!is.na(file)) %>% # unexported?
dplyr::arrange(file) %>%
dplyr::mutate(test_name = paste0("``` ", test_name, " ```")) %>%
dplyr::mutate(file = paste0("``` ", file, " ```")) %>%
dplyr::select(`Test Description` = test_name, Documentation = file)
if (nrow(tt_covtracer_df) > 0) {
tt(
tt_covtracer_df,
caption = "Tracebility matrix mapping unit tests to documented behaviours.",
theme = "bootstrap"
)
} else {
cat("No test suites.")
}
} else {
cat("{covtracer} not available to produce a traceability matrix")
}
```
```{=typst}
#show figure: set block(breakable: false)
```
### Untested
```{r traceability2, echo = FALSE, eval = TRUE}
if (require("covtracer", quietly = TRUE)) {
tt_untested_df <- covtracer_df_clean %>%
dplyr::filter(is.na(test_name)) %>%
dplyr::arrange(alias) %>%
dplyr::mutate(alias = paste0("``` ", alias, " ```")) %>%
dplyr::mutate(file = paste0("``` ", file, " ```")) %>%
dplyr::select(`Exported package object` = alias, Documentation = file)
if (nrow(tt_untested_df) > 0) {
tt(
tt_untested_df,
caption = "Untested behaviours: documentation that is not covered by any test.",
theme = "bootstrap"
)
}
} else {
cat("{covtracer} not available to produce a traceability matrix")
}
```
### Testing granularity
An indicator of test granularity by whether the function is directly tested.
```{r traceability3, echo = FALSE, eval = TRUE}
if (require("covtracer", quietly = TRUE)) {
tt_granularity_df <- covtracer_df_clean %>%
dplyr::group_by(alias) %>%
dplyr::summarize(any_direct_tests = any(direct, na.rm = TRUE)) %>%
dplyr::arrange(alias) %>%
dplyr::mutate(alias = paste0("``` ", alias, " ```")) %>%
dplyr::mutate(any_direct_tests = paste0("``` ", any_direct_tests, " ```")) %>%
dplyr::select(`Exported package object` = alias, `Tested Directly` = any_direct_tests)
tt(
tt_granularity_df,
caption = "Granularity of unit tests: directly tested exported functions.",
theme = "bootstrap"
)
} else {
cat("{covtracer} not available to produce a traceability matrix")
}
```