Skip to content

Commit

Permalink
Merge pull request #404 from cmu-delphi/ds/ci
Browse files Browse the repository at this point in the history
ci: fix pkgdown
  • Loading branch information
dshemetov authored Oct 4, 2024
2 parents 3892a53 + 6165a89 commit 4b9fc72
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
34 changes: 25 additions & 9 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# 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
#
# Created with usethis + edited to run on PRs to dev, use API key.
# Modifications:
# * workflow_dispatch added to allow manual triggering of the workflow
# * trigger branches changed
# * API key secrets.SECRET_EPIPREDICT_GHACTIONS_DELPHI_EPIDATA_KEY
on:
push:
branches: [main, dev]
Expand All @@ -21,8 +24,9 @@ jobs:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
DELPHI_EPIDATA_KEY: ${{ secrets.SECRET_EPIPREDICT_GHACTIONS_DELPHI_EPIDATA_KEY }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

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

Expand All @@ -32,19 +36,31 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
extra-packages: any::pkgdown, local::., any::cli
needs: website

- name: Build site
env:
DELPHI_EPIDATA_KEY: ${{ secrets.SECRET_EPIPROCESS_GHACTIONS_DELPHI_EPIDATA_KEY }}
# - target_ref gets the ref from a different variable, depending on the event
# - override allows us to set the pkgdown mode and version_label
# - mode: release is the standard build mode, devel places the site in /dev
# - version_label: 'light' and 'success' are CSS labels for Bootswatch: Cosmo
# https://bootswatch.com/cosmo/
# - we use pkgdown:::build_github_pages to build the site because of an issue in pkgdown
# https://github.com/r-lib/pkgdown/issues/2257
run: |
if (startsWith("${{ github.event_name }}", "pull_request")) {
mode <- ifelse("${{ github.base_ref }}" == "main", "release", "devel")
target_ref <- "${{ github.event_name == 'pull_request' && github.base_ref || github.ref }}"
override <- if (target_ref == "main" || target_ref == "refs/heads/main") {
list(development = list(mode = "release", version_label = "light"))
} else if (target_ref == "dev" || target_ref == "refs/heads/dev") {
list(development = list(mode = "devel", version_label = "success"))
} else {
mode <- ifelse("${{ github.ref_name }}" == "main", "release", "devel")
stop("Unexpected target_ref: ", target_ref)
}
pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE, override=list(PKGDOWN_DEV_MODE=mode))
pkg <- pkgdown::as_pkgdown(".", override = override)
cli::cli_rule("Cleaning files from old site...")
pkgdown::clean_site(pkg)
pkgdown::build_site(pkg, preview = FALSE, install = FALSE, new_process = FALSE)
pkgdown:::build_github_pages(pkg)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/_snaps/population_scaling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# expect error if `by` selector does not match

Code
wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) %>% add_frosting(f)
Condition
Error in `hardhat::validate_column_names()`:
! The following required columns are missing: 'a'.

---

Code
forecast(wf)
Condition
Error in `hardhat::validate_column_names()`:
! The following required columns are missing: 'nothere'.

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/step_epi_slide.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
r %>% step_epi_slide(value, .f = mean, .window_size = c(3L, 6L))
Condition
Error in `epiprocess:::validate_slide_window_arg()`:
! Slide function expected `.window_size` to be a non-null, scalar integer >= 1.
! Slide function expected `.window_size` to be a length-1 difftime with units in days or non-negative integer or Inf.

---

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

---

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-grf_quantiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("quantile_rand_forest defaults work", {
expect_silent(out <- fit(spec, formula = y ~ x + z, data = tib))
pars <- parsnip::extract_fit_engine(out)
manual <- quantile_forest(as.matrix(tib[, 2:3]), tib$y, quantiles = c(0.1, 0.5, 0.9))
expect_identical(pars$quantiles.orig, manual$quantiles)
expect_identical(pars$quantiles.orig, manual$quantiles.orig)
expect_identical(pars$`_num_trees`, manual$`_num_trees`)

fseed <- 12345
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-snapshots.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ test_that("arx_forecaster output format snapshots", {
jhu, "death_rate",
c("case_rate", "death_rate")
)
expect_equal(as.Date(out1$metadata$forecast_created), Sys.Date())
expect_equal(as.Date(format(out1$metadata$forecast_created, "%Y-%m-%d")), Sys.Date())
out1$metadata$forecast_created <- as.Date("0999-01-01")
expect_snapshot(out1)
out2 <- arx_forecaster(jhu, "case_rate",
Expand All @@ -129,7 +129,7 @@ test_that("arx_forecaster output format snapshots", {
forecast_date = as.Date("2022-01-03")
)
)
expect_equal(as.Date(out2$metadata$forecast_created), Sys.Date())
expect_equal(as.Date(format(out2$metadata$forecast_created, "%Y-%m-%d")), Sys.Date())
out2$metadata$forecast_created <- as.Date("0999-01-01")
expect_snapshot(out2)
out3 <- arx_forecaster(jhu, "death_rate",
Expand All @@ -140,7 +140,7 @@ test_that("arx_forecaster output format snapshots", {
forecast_date = as.Date("2022-01-03")
)
)
expect_equal(as.Date(out3$metadata$forecast_created), Sys.Date())
expect_equal(as.Date(format(out3$metadata$forecast_created, "%Y-%m-%d")), Sys.Date())
out3$metadata$forecast_created <- as.Date("0999-01-01")
expect_snapshot(out3)
})
Expand Down

0 comments on commit 4b9fc72

Please sign in to comment.