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
58on :
69 push :
710 branches : [main, dev]
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 🚀
0 commit comments