Skip to content

Commit bc38209

Browse files
Merge pull request #159 from hubverse-org/158/ci-testhub-val
158/ Move testhub config validation to CI
2 parents 246369f + b3b1db5 commit bc38209

5 files changed

+167
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Hub Config Validation (R)
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches: main
7+
paths:
8+
- 'inst/testhubs/flusight/hub-config/**'
9+
- '!inst/testhubs/flusight/**README**'
10+
11+
jobs:
12+
validate-hub-config:
13+
runs-on: ubuntu-latest
14+
env:
15+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
16+
PR_NUMBER: ${{ github.event.number }}
17+
HUB_PATH: "inst/testhubs/flusight"
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- uses: r-lib/actions/setup-r@v2
23+
with:
24+
install-r: false
25+
use-public-rspm: true
26+
extra-repositories: 'https://hubverse-org.r-universe.dev'
27+
28+
- name: Update R
29+
run: |
30+
sudo apt-get update
31+
32+
- uses: r-lib/actions/setup-r-dependencies@v2
33+
with:
34+
cache: 'always'
35+
packages: |
36+
any::hubAdmin
37+
any::sessioninfo
38+
39+
- name: Run validations
40+
id: validate
41+
run: |
42+
hub_path <- Sys.getenv("HUB_PATH")
43+
diff <- file.path(hub_path, "diff.md")
44+
output <- Sys.getenv("GITHUB_OUTPUT")
45+
timestamp <- function(outfile) {
46+
stamp <- format(Sys.time(), usetz = TRUE, tz = "UTC")
47+
cat(stamp, "\n", file = outfile, sep = "", append = TRUE)
48+
}
49+
v <- hubAdmin::validate_hub_config(
50+
hub_path = hub_path
51+
)
52+
# check if there were any failures
53+
invalid <- any(vapply(v, isFALSE, logical(1)))
54+
if (invalid) {
55+
cat("result=false", "\n", file = output, sep = "", append = TRUE)
56+
# write output to HTML
57+
tbl <- hubAdmin::view_config_val_errors(v)
58+
writeLines("## :x: Invalid Configuration\n", diff)
59+
cat("\nErrors were detected in one or more config files in `hub-config/`. Details about the exact locations of the errors can be found in the table below.\n", file = diff, append = TRUE)
60+
cat(gt::as_raw_html(tbl), "\n", file = diff, sep = "", append = TRUE)
61+
timestamp(diff)
62+
} else {
63+
cat("result=true", "\n", file = output, sep = "", append = TRUE)
64+
writeLines(":white_check_mark: Hub correctly configured!\n", diff)
65+
timestamp(diff)
66+
}
67+
shell: Rscript {0}
68+
- name: "Comment on PR"
69+
id: comment-diff
70+
if: ${{ github.event_name != 'workflow_dispatch' }}
71+
uses: carpentries/actions/comment-diff@main
72+
with:
73+
pr: ${{ env.PR_NUMBER }}
74+
path: ${{ env.HUB_PATH }}/diff.md
75+
- name: Error on Failure
76+
if: ${{ steps.validate.outputs.result == 'false' }}
77+
run: |
78+
echo "::error title=Invalid Configuration::Errors were detected in one or more config files in 'hub-config/'"
79+
exit 1
80+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Hub Config Validation (R)
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches: main
7+
paths:
8+
- 'inst/testhubs/simple/hub-config/**'
9+
- '!inst/testhubs/simple/**README**'
10+
11+
jobs:
12+
validate-hub-config:
13+
runs-on: ubuntu-latest
14+
env:
15+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
16+
PR_NUMBER: ${{ github.event.number }}
17+
HUB_PATH: "inst/testhubs/simple"
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- uses: r-lib/actions/setup-r@v2
23+
with:
24+
install-r: false
25+
use-public-rspm: true
26+
extra-repositories: 'https://hubverse-org.r-universe.dev'
27+
28+
- name: Update R
29+
run: |
30+
sudo apt-get update
31+
32+
- uses: r-lib/actions/setup-r-dependencies@v2
33+
with:
34+
cache: 'always'
35+
packages: |
36+
any::hubAdmin
37+
any::sessioninfo
38+
39+
- name: Run validations
40+
id: validate
41+
run: |
42+
hub_path <- Sys.getenv("HUB_PATH")
43+
diff <- file.path(hub_path, "diff.md")
44+
output <- Sys.getenv("GITHUB_OUTPUT")
45+
timestamp <- function(outfile) {
46+
stamp <- format(Sys.time(), usetz = TRUE, tz = "UTC")
47+
cat(stamp, "\n", file = outfile, sep = "", append = TRUE)
48+
}
49+
v <- hubAdmin::validate_hub_config(
50+
hub_path = hub_path
51+
)
52+
# check if there were any failures
53+
invalid <- any(vapply(v, isFALSE, logical(1)))
54+
if (invalid) {
55+
cat("result=false", "\n", file = output, sep = "", append = TRUE)
56+
# write output to HTML
57+
tbl <- hubAdmin::view_config_val_errors(v)
58+
writeLines("## :x: Invalid Configuration\n", diff)
59+
cat("\nErrors were detected in one or more config files in `hub-config/`. Details about the exact locations of the errors can be found in the table below.\n", file = diff, append = TRUE)
60+
cat(gt::as_raw_html(tbl), "\n", file = diff, sep = "", append = TRUE)
61+
timestamp(diff)
62+
} else {
63+
cat("result=true", "\n", file = output, sep = "", append = TRUE)
64+
writeLines(":white_check_mark: Hub correctly configured!\n", diff)
65+
timestamp(diff)
66+
}
67+
shell: Rscript {0}
68+
- name: "Comment on PR"
69+
id: comment-diff
70+
if: ${{ github.event_name != 'workflow_dispatch' }}
71+
uses: carpentries/actions/comment-diff@main
72+
with:
73+
pr: ${{ env.PR_NUMBER }}
74+
path: ${{ env.HUB_PATH }}/diff.md
75+
- name: Error on Failure
76+
if: ${{ steps.validate.outputs.result == 'false' }}
77+
run: |
78+
echo "::error title=Invalid Configuration::Errors were detected in one or more config files in 'hub-config/'"
79+
exit 1
80+

DESCRIPTION

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: hubUtils
22
Title: Utility Functions for Infectious Disease Modeling Hubs
3-
Version: 0.1.0
3+
Version: 0.1.1
44
Authors@R: c(
55
person("Anna", "Krystalli", , "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0002-2378-4915")),
@@ -36,14 +36,12 @@ Imports:
3636
utils
3737
Suggests:
3838
dplyr,
39-
hubAdmin,
4039
hubData,
4140
knitr,
4241
rmarkdown,
4342
testthat (>= 3.2.0)
4443
Additional_repositories: https://hubverse-org.r-universe.dev/
4544
Remotes:
46-
hubverse-org/hubAdmin,
4745
hubverse-org/hubData
4846
Config/Needs/website: hubverse-org/hubStyle
4947
Config/testthat/edition: 3

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# hubUtils 0.1.1
2+
3+
* Remove `hubAdmin` Suggests dependency by moving test hub configuration validation to CI
4+
(resolved: @annakrystalli, https://github.com/hubverse-org/hubUtils/issues/158)
5+
6+
17
# hubUtils 0.1.0
28

39
* Add `read_config_file()` helper function to read a JSON config file from a file path.

tests/testthat/test-validate-inst-hubs.R

-33
This file was deleted.

0 commit comments

Comments
 (0)