-
Notifications
You must be signed in to change notification settings - Fork 7
179 lines (162 loc) · 6.06 KB
/
test-coverage.yml
File metadata and controls
179 lines (162 loc) · 6.06 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
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
on:
push:
branches:
- main
paths:
- R/**
- tests/**
workflow_dispatch:
name: Code Coverage
jobs:
coverage:
name: Test Coverage
runs-on: ubuntu-latest
container:
image: "ghcr.io/pharmaverse/admiralci-release:latest"
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
outputs:
coverage-percent: ${{ steps.set-coverage-percentage.outputs.coverage-percentage }}
steps:
##################### BEGIN boilerplate steps #####################
- name: Get branch names
id: branch-name
uses: tj-actions/branch-names@v8
- name: Checkout repo (PR) 🛎
uses: actions/checkout@v4.2.2
if: github.event_name == 'pull_request'
with:
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
repository: ${{ github.event.repository }}
- name: Checkout repository
uses: actions/checkout@v4.2.2
if: github.event_name != 'pull_request'
with:
ref: ${{ steps.branch-name.outputs.head_ref_branch }}
- name: Setup Pandoc
uses: r-lib/actions/setup-pandoc@v2
- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- name: Install R Dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
needs: tests
extra-packages: local::.
##################### END boilerplate steps #####################
- name: Run coverage 👟
run: |
tryCatch(
expr = {
x <- covr::package_coverage(
path=".",
clean = FALSE,
quiet = FALSE
)
print(x)
covr::to_cobertura(x, filename = "coverage.xml")
p <- round(covr::percent_coverage(x))
cat(p, file = "coverage.txt", sep = "")
covr::report(
x,
file = "coverage-report.html",
browse = FALSE
)
},
error = function(e) {
message("Errors generated during coverage analysis:")
print(e)
error_file <- list.files(path = "/tmp", pattern="*.fail$", recursive = T, full.names = T)[1]
if (length(error_file) && file.exists(error_file)) {
cat("__________FULL OUTPUT__________")
writeLines(readLines(error_file))
}
},
warning = function(w) {
message("Warnings generated during coverage analysis:")
print(w)
}
)
shell: Rscript {0}
- name: Check whether coverage reports exists
id: check_coverage_reports
uses: andstor/file-existence-action@v1
with:
files: "coverage.xml, coverage.txt, coverage-report.html"
- name: Set coverage percentage as output
id: set-coverage-percentage
run: echo "coverage-percentage=$(cat coverage.txt)" >> $GITHUB_OUTPUT
if: steps.check_coverage_reports.outputs.files_exists == 'true'
- name: Generate Coverage Summary Report
if: steps.check_coverage_reports.outputs.files_exists == 'true' && github.event_name == 'pull_request'
uses: irongut/CodeCoverageSummary@v1.2.0
with:
filename: coverage.xml
badge: true
fail_below_min: false
format: markdown
hide_branch_rate: true
hide_complexity: true
indicators: true
output: both
thresholds: "60 80"
- name: Upload report for review
if: steps.check_coverage_reports.outputs.files_exists == 'true' && github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: "coverage-report.html"
continue-on-error: true
- name: Add Coverage PR Comment
if: steps.check_coverage_reports.outputs.files_exists == 'true' && github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: code-coverage
path: code-coverage-results.md
continue-on-error: true
badge:
name: Generate badge for coverage
needs: [coverage]
runs-on: ubuntu-22.04
steps:
- name: Checkout the badges branch in repo
uses: actions/checkout@v4.2.2
with:
ref: badges
path: badges
# Use the output from the `coverage` step
- name: Generate the badge SVG image
uses: emibcn/badge-action@v1
id: badge
with:
label: "Test Coverage"
status: "${{ needs.coverage.outputs.coverage-percent }}%"
color: ${{
needs.coverage.outputs.coverage-percent > 90 && 'green' ||
needs.coverage.outputs.coverage-percent > 80 && 'yellow,green' ||
needs.coverage.outputs.coverage-percent > 70 && 'yellow' ||
needs.coverage.outputs.coverage-percent > 60 && 'orange,yellow' ||
needs.coverage.outputs.coverage-percent > 50 && 'orange' ||
needs.coverage.outputs.coverage-percent > 40 && 'red,orange' ||
needs.coverage.outputs.coverage-percent > 30 && 'red,red,orange' ||
needs.coverage.outputs.coverage-percent > 20 && 'red,red,red,orange' ||
'red' }}
path: badges/test-coverage.svg
- name: Commit badge
working-directory: ./badges
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Actions"
BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
mkdir -p "${BRANCH}"
mv test-coverage.svg "${BRANCH}"
git add "${BRANCH}/test-coverage.svg"
git commit -m "Add/Update badge" || true
- name: Push badges
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: badges
directory: badges
continue-on-error: true