Repository navigation
103 lines (91 loc) · 3.42 KB
/
Copy pathtest-coverage.yaml
File metadata and controls
103 lines (91 loc) · 3.42 KB
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
on:
workflow_dispatch: # Enables manual triggering
name: test-coverage.yaml
permissions: read-all
jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v7
- name: Assert CODECOV_TOKEN is set
run: |
if [[ -z "${{secrets.CODECOV_TOKEN}}" ]]; then
>&2 echo "::error::ERROR: 'secrets.CODECOV_TOKEN' not set"
exit 1
fi
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
needs: coverage
- name: Install itself
run: |
install.packages(".", repos = NULL, type = "source")
shell: Rscript {0}
- name: Test coverage
run: |
## Workaround: Background processes terminated while writing their
## covr trace files (e.g. canceled workers) can leave truncated files
## behind, or still be writing when covr merges the files. Either
## makes covr::package_coverage() fail with "Error in readRDS(f) :
## error reading from connection". Wait for the files to settle, and
## skip any that remain unreadable.
local({
ns <- asNamespace("covr")
merge_list <- get("merge_coverage.list", envir = ns)
new <- function(x) {
## Wait for stray processes to finish writing their trace files
size <- function() file.size(x)
t_end <- Sys.time() + 120
prev <- size()
while (Sys.time() < t_end) {
Sys.sleep(2)
cur <- size()
if (identical(cur, prev)) break
prev <- cur
}
## Read each file once; retry, then give up on unreadable files
read <- function(f) {
for (kk in 1:3) {
res <- try(as.list(suppressWarnings(readRDS(f))), silent = TRUE)
if (!inherits(res, "try-error")) return(res)
Sys.sleep(5)
}
NULL
}
objs <- lapply(x, read)
bad <- vapply(objs, is.null, NA)
if (any(bad)) {
warning(sprintf("Ignoring %d unreadable covr trace file(s): %s",
sum(bad), paste(basename(x[bad]), collapse = ", ")),
call. = FALSE, immediate. = TRUE)
}
merge_list(objs[!bad])
}
utils::assignInNamespace("merge_coverage.character", new, ns = "covr")
})
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
print(cov)
covr::to_cobertura(cov)
shell: Rscript {0}
- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test results
if: failure()
uses: actions/upload-artifact@v7
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package