Skip to content

Commit 4b9fc72

Browse files
authored
Merge pull request #404 from cmu-delphi/ds/ci
ci: fix pkgdown
2 parents 3892a53 + 6165a89 commit 4b9fc72

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

.github/workflows/pkgdown.yaml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
22
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
33
#
4-
# Created with usethis + edited to run on PRs to dev, use API key.
4+
# Modifications:
5+
# * workflow_dispatch added to allow manual triggering of the workflow
6+
# * trigger branches changed
7+
# * API key secrets.SECRET_EPIPREDICT_GHACTIONS_DELPHI_EPIDATA_KEY
58
on:
69
push:
710
branches: [main, dev]
@@ -21,8 +24,9 @@ jobs:
2124
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
2225
env:
2326
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
27+
DELPHI_EPIDATA_KEY: ${{ secrets.SECRET_EPIPREDICT_GHACTIONS_DELPHI_EPIDATA_KEY }}
2428
steps:
25-
- uses: actions/checkout@v3
29+
- uses: actions/checkout@v4
2630

2731
- uses: r-lib/actions/setup-pandoc@v2
2832

@@ -32,19 +36,31 @@ jobs:
3236

3337
- uses: r-lib/actions/setup-r-dependencies@v2
3438
with:
35-
extra-packages: any::pkgdown, local::.
39+
extra-packages: any::pkgdown, local::., any::cli
3640
needs: website
3741

3842
- name: Build site
39-
env:
40-
DELPHI_EPIDATA_KEY: ${{ secrets.SECRET_EPIPROCESS_GHACTIONS_DELPHI_EPIDATA_KEY }}
43+
# - target_ref gets the ref from a different variable, depending on the event
44+
# - override allows us to set the pkgdown mode and version_label
45+
# - mode: release is the standard build mode, devel places the site in /dev
46+
# - version_label: 'light' and 'success' are CSS labels for Bootswatch: Cosmo
47+
# https://bootswatch.com/cosmo/
48+
# - we use pkgdown:::build_github_pages to build the site because of an issue in pkgdown
49+
# https://github.com/r-lib/pkgdown/issues/2257
4150
run: |
42-
if (startsWith("${{ github.event_name }}", "pull_request")) {
43-
mode <- ifelse("${{ github.base_ref }}" == "main", "release", "devel")
51+
target_ref <- "${{ github.event_name == 'pull_request' && github.base_ref || github.ref }}"
52+
override <- if (target_ref == "main" || target_ref == "refs/heads/main") {
53+
list(development = list(mode = "release", version_label = "light"))
54+
} else if (target_ref == "dev" || target_ref == "refs/heads/dev") {
55+
list(development = list(mode = "devel", version_label = "success"))
4456
} else {
45-
mode <- ifelse("${{ github.ref_name }}" == "main", "release", "devel")
57+
stop("Unexpected target_ref: ", target_ref)
4658
}
47-
pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE, override=list(PKGDOWN_DEV_MODE=mode))
59+
pkg <- pkgdown::as_pkgdown(".", override = override)
60+
cli::cli_rule("Cleaning files from old site...")
61+
pkgdown::clean_site(pkg)
62+
pkgdown::build_site(pkg, preview = FALSE, install = FALSE, new_process = FALSE)
63+
pkgdown:::build_github_pages(pkg)
4864
shell: Rscript {0}
4965

5066
- name: Deploy to GitHub pages 🚀
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# expect error if `by` selector does not match
2+
3+
Code
4+
wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) %>% add_frosting(f)
5+
Condition
6+
Error in `hardhat::validate_column_names()`:
7+
! The following required columns are missing: 'a'.
8+
9+
---
10+
11+
Code
12+
forecast(wf)
13+
Condition
14+
Error in `hardhat::validate_column_names()`:
15+
! The following required columns are missing: 'nothere'.
16+

tests/testthat/_snaps/step_epi_slide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
r %>% step_epi_slide(value, .f = mean, .window_size = c(3L, 6L))
1313
Condition
1414
Error in `epiprocess:::validate_slide_window_arg()`:
15-
! Slide function expected `.window_size` to be a non-null, scalar integer >= 1.
15+
! Slide function expected `.window_size` to be a length-1 difftime with units in days or non-negative integer or Inf.
1616

1717
---
1818

@@ -60,7 +60,7 @@
6060
r %>% step_epi_slide(value, .f = mean, .window_size = 1.5)
6161
Condition
6262
Error in `epiprocess:::validate_slide_window_arg()`:
63-
! Slide function expected `.window_size` to be a difftime with units in days or non-negative integer or Inf.
63+
! Slide function expected `.window_size` to be a length-1 difftime with units in days or non-negative integer or Inf.
6464

6565
---
6666

tests/testthat/test-grf_quantiles.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test_that("quantile_rand_forest defaults work", {
1010
expect_silent(out <- fit(spec, formula = y ~ x + z, data = tib))
1111
pars <- parsnip::extract_fit_engine(out)
1212
manual <- quantile_forest(as.matrix(tib[, 2:3]), tib$y, quantiles = c(0.1, 0.5, 0.9))
13-
expect_identical(pars$quantiles.orig, manual$quantiles)
13+
expect_identical(pars$quantiles.orig, manual$quantiles.orig)
1414
expect_identical(pars$`_num_trees`, manual$`_num_trees`)
1515

1616
fseed <- 12345

tests/testthat/test-snapshots.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ test_that("arx_forecaster output format snapshots", {
117117
jhu, "death_rate",
118118
c("case_rate", "death_rate")
119119
)
120-
expect_equal(as.Date(out1$metadata$forecast_created), Sys.Date())
120+
expect_equal(as.Date(format(out1$metadata$forecast_created, "%Y-%m-%d")), Sys.Date())
121121
out1$metadata$forecast_created <- as.Date("0999-01-01")
122122
expect_snapshot(out1)
123123
out2 <- arx_forecaster(jhu, "case_rate",
@@ -129,7 +129,7 @@ test_that("arx_forecaster output format snapshots", {
129129
forecast_date = as.Date("2022-01-03")
130130
)
131131
)
132-
expect_equal(as.Date(out2$metadata$forecast_created), Sys.Date())
132+
expect_equal(as.Date(format(out2$metadata$forecast_created, "%Y-%m-%d")), Sys.Date())
133133
out2$metadata$forecast_created <- as.Date("0999-01-01")
134134
expect_snapshot(out2)
135135
out3 <- arx_forecaster(jhu, "death_rate",
@@ -140,7 +140,7 @@ test_that("arx_forecaster output format snapshots", {
140140
forecast_date = as.Date("2022-01-03")
141141
)
142142
)
143-
expect_equal(as.Date(out3$metadata$forecast_created), Sys.Date())
143+
expect_equal(as.Date(format(out3$metadata$forecast_created, "%Y-%m-%d")), Sys.Date())
144144
out3$metadata$forecast_created <- as.Date("0999-01-01")
145145
expect_snapshot(out3)
146146
})

0 commit comments

Comments
 (0)