Repository navigation
315 lines (275 loc) · 11.2 KB
/
Copy pathci.yaml
File metadata and controls
315 lines (275 loc) · 11.2 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
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
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main]
pull_request:
branches: [main]
release:
types: [published]
workflow_dispatch:
name: CI
permissions: read-all
jobs:
air-format:
if: github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: posit-dev/setup-air@v1
- name: Check formatting
run: |
air format . --check || {
echo "::error::Code is not formatted with air. Run 'air format .' locally and commit the result (install: curl -LsSf https://github.com/posit-dev/air/releases/latest/download/air-installer.sh | sh)."
exit 1
}
lintr:
if: github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
container:
image: daratools/robase:latest
permissions:
contents: write
env:
GITHUB_PAT: ${{ secrets.AT_ROvis || secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v5
# rocker-based images run as root; mark the workspace as safe for git,
# otherwise git operations fail with "dubious ownership"
- name: Fix git safe directory
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
# R is already baked into daratools/robase - no setup-r needed.
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::lintr
needs: lint
# Deliberately doesn't use LINTR_ERROR_ON_LINT here: we need the lint
# count available afterwards to write the badge, and to fail the job
# explicitly only once the badge has been pushed.
- name: Lint package
id: lint
run: |
lints <- lintr::lint_package()
n <- length(lints)
cat("Lint issues found:", n, "\n")
if (n > 0) print(lints)
writeLines(as.character(n), "lint_count.txt")
shell: Rscript {0}
- name: Push lint badge to gh-pages
if: always() && github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
N=$(cat lint_count.txt 2>/dev/null || echo "0")
if [ "$N" -eq 0 ]; then
COLOR="brightgreen"; MESSAGE="passing"
else
COLOR="red"; MESSAGE="${N} issue(s)"
fi
mkdir -p /tmp/badge-output
printf '{\n "schemaVersion": 1,\n "label": "lintr",\n "message": "%s",\n "color": "%s"\n}\n' \
"$MESSAGE" "$COLOR" > /tmp/badge-output/lint.json
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin gh-pages 2>/dev/null || true
if git show-ref --quiet refs/remotes/origin/gh-pages; then
git checkout gh-pages
else
git checkout --orphan gh-pages
git rm -rf . --quiet
fi
mkdir -p badges
cp /tmp/badge-output/lint.json badges/lint.json
git add badges/lint.json
git diff --cached --quiet || git commit -m "chore: update lint badge [skip ci]"
git push origin gh-pages
env:
GITHUB_TOKEN: ${{ secrets.AT_ROvis || secrets.GITHUB_TOKEN }}
- name: Fail if lint issues found
if: always()
run: |
N=$(cat lint_count.txt 2>/dev/null || echo "0")
if [ "$N" -ne 0 ]; then
echo "::error::$N lint issue(s) found above (file:line:column - message). Run 'lintr::lint_package()' locally to reproduce, fix the code, or adjust .lintr if a rule genuinely shouldn't apply here."
exit 1
fi
R-CMD-check:
if: github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
container:
image: daratools/robase:latest
env:
# AT_ROvis authenticates installs of private rivm-syso/ROvis.* dependencies
# (via the Remotes: field in DESCRIPTION). Falls back to the default
# GITHUB_TOKEN for packages with no private cross-repo dependencies.
GITHUB_PAT: ${{ secrets.AT_ROvis || secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
steps:
- uses: actions/checkout@v5
# rocker-based images run as root; mark the workspace as safe for git,
# otherwise git operations fail with "dubious ownership"
- name: Fix git safe directory
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
# R and pandoc are already baked into daratools/robase - no setup-r/setup-pandoc needed.
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual", "--compact-vignettes=gs+qpdf")'
ci-badge:
needs: [air-format, R-CMD-check]
# Runs even when air-format/R-CMD-check fail (needs.*.result may be
# 'failure') so the badge can turn red instead of just not updating.
if: always() && github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Push CI badge to gh-pages
run: |
if [ "${{ needs.air-format.result }}" = "success" ] && [ "${{ needs.R-CMD-check.result }}" = "success" ]; then
COLOR="brightgreen"; MESSAGE="passing"
else
COLOR="red"; MESSAGE="failing"
fi
mkdir -p /tmp/badge-output
printf '{\n "schemaVersion": 1,\n "label": "CI",\n "message": "%s",\n "color": "%s"\n}\n' \
"$MESSAGE" "$COLOR" > /tmp/badge-output/ci.json
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin gh-pages 2>/dev/null || true
if git show-ref --quiet refs/remotes/origin/gh-pages; then
git checkout gh-pages
else
git checkout --orphan gh-pages
git rm -rf . --quiet
fi
mkdir -p badges
cp /tmp/badge-output/ci.json badges/ci.json
git add badges/ci.json
git diff --cached --quiet || git commit -m "chore: update CI badge [skip ci]"
git push origin gh-pages
env:
GITHUB_TOKEN: ${{ secrets.AT_ROvis || secrets.GITHUB_TOKEN }}
test-coverage:
needs: R-CMD-check
if: github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
container:
image: daratools/robase:latest
permissions:
contents: write
env:
GITHUB_PAT: ${{ secrets.AT_ROvis || secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
# rocker-based images run as root; mark the workspace as safe for git,
# otherwise git operations below fail with "dubious ownership"
- name: Fix git safe directory
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
# R is already baked into daratools/robase - no setup-r step needed.
- name: Setup R dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::jsonlite, any::dplyr
needs: coverage
- name: Run tests and compute coverage
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(
normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"),
"package"
)
)
covr::to_cobertura(cov)
pct <- round(covr::percent_coverage(cov), 1)
color <- dplyr::case_when(
pct >= 90 ~ "brightgreen",
pct >= 75 ~ "green",
pct >= 60 ~ "yellowgreen",
pct >= 50 ~ "yellow",
pct >= 40 ~ "orange",
TRUE ~ "red"
)
badge <- jsonlite::toJSON(
list(
schemaVersion = 1,
label = "coverage",
message = paste0(pct, "%"),
color = color
),
auto_unbox = TRUE,
pretty = TRUE
)
dir.create("/tmp/badge-output", showWarnings = FALSE, recursive = TRUE)
writeLines(badge, "/tmp/badge-output/coverage.json")
cat("Coverage:", pct, "%\n")
shell: Rscript {0}
- name: Upload coverage badge JSON to GitHub Pages branch
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Switch to (or create) the gh-pages branch
git fetch origin gh-pages 2>/dev/null || true
if git show-ref --quiet refs/remotes/origin/gh-pages; then
git checkout gh-pages
else
git checkout --orphan gh-pages
git rm -rf . --quiet
fi
# Place the badge file and commit
mkdir -p badges
cp /tmp/badge-output/coverage.json badges/coverage.json
git add badges/coverage.json
git diff --cached --quiet || git commit -m "chore: update coverage badge [skip ci]"
git push origin gh-pages
env:
GITHUB_TOKEN: ${{ secrets.AT_ROvis || secrets.GITHUB_TOKEN }}
# pkgdown:
# needs: test-coverage
# # test-coverage only runs on push/pull_request (see its `if:`), so on a
# # release/workflow_dispatch trigger it's skipped rather than successful -
# # explicitly allow that here, otherwise the default needs-gating would
# # skip this job too.
# if: |
# github.event_name != 'pull_request' &&
# !cancelled() &&
# (needs.test-coverage.result == 'success' || needs.test-coverage.result == 'skipped')
# runs-on: ubuntu-latest
# container:
# image: daratools/robase:latest
# permissions:
# contents: write
# pages: write
# env:
# GITHUB_PAT: ${{ secrets.AT_ROvis || secrets.GITHUB_TOKEN }}
# steps:
# - name: Checkout repository
# uses: actions/checkout@v5
# # rocker-based images run as root; mark the workspace as safe for git
# - name: Fix git safe directory
# run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
# # No setup-r step needed — R is already installed in your Docker image
# - name: Setup pandoc
# uses: r-lib/actions/setup-pandoc@v2
# - name: Setup R dependencies
# uses: r-lib/actions/setup-r-dependencies@v2
# with:
# extra-packages: any::pkgdown, local::.
# needs: website
# - name: Build pkgdown site
# run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
# shell: Rscript {0}
# - name: Deploy to GitHub Pages
# uses: JamesIves/github-pages-deploy-action@v4
# with:
# clean: false # keeps the badges/ folder written by the coverage job
# branch: gh-pages
# folder: docs