From e537fc646fc41f75ceb293aeb2980a64d12c993b Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Mon, 14 Oct 2024 16:59:59 -0700 Subject: [PATCH 1/6] - switched to pkgdown workflow from https://github.com/rstudio/education-workflows/blob/main/examples/pkgdown.yaml --- .github/workflows/pkgdown.yaml | 150 +++++++++++++++++++++++++++------ 1 file changed, 125 insertions(+), 25 deletions(-) diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 12811eec..f1e8c137 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -1,28 +1,54 @@ -# 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 +# Deploys pkgdown for Pull Requests, tags, and pushes to main branch +# PRs are deployed to /preview/pr/ +# Tags are deployed to // +# copied from https://github.com/rstudio/education-workflows/blob/main/examples/pkgdown.yaml +# referred from https://github.com/r-lib/actions/issues/865 on: - push: - branches: [main, master] pull_request: - branches: [main, master] - release: - types: [published] + branches: + - main + types: + - opened + - reopened + - synchronize + - closed + paths: + - 'man/**' + - 'pkgdown/**' + - 'vignettes/**' + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' # build on version tags + - '!v[0-9]+.[0-9]+.[0-9]+.[0-9]+' # but not if version involves a dev component + branches: + - main workflow_dispatch: + inputs: + tag: + description: Tag to deploy + required: true + default: '' -name: pkgdown.yaml +name: pkgdown jobs: - pkgdown: + pkgdown-build: runs-on: ubuntu-latest - # Only restrict concurrency for non-PR jobs - concurrency: - group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + if: ${{ !(github.event_name == 'pull_request' && github.event.action == 'closed') }} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - permissions: - contents: write steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v2 + + - name: Configure git + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - uses: r-lib/actions/pr-fetch@v2 + if: ${{ github.event_name == 'pull_request' }} + with: + repo-token: ${{ github.token }} - uses: r-lib/actions/setup-pandoc@v2 @@ -32,17 +58,91 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::pkgdown, local::. - needs: website + needs: | + connect + website + extra-packages: | + local::. + any::pkgdown + + # If events is a PR, set subdir to 'preview/pr' + - name: "[PR] Set documentation subdirectory" + if: github.event_name == 'pull_request' + run: | + echo "PKGDOWN_DEV_MODE=unreleased" >> $GITHUB_ENV + echo "subdir=preview/pr${{ github.event.number }}" >> $GITHUB_ENV - - name: Build site - run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + # If event is a tag, set subdir to '' + - name: "[tag] Set documentation subdirectory" + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + run: | + echo "PKGDOWN_DEV_MODE=release" >> $GITHUB_ENV + echo "subdir=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + # If event is workflow_dispatch, set subdir to 'inputs.tag' + - name: '[dispatch] Set documentation subdirectory' + if: github.event_name == 'workflow_dispatch' + run: | + echo "subdir=${{ github.event.inputs.tag }}" >> $GITHUB_ENV + + - name: Deploy pkgdown site + id: deploy shell: Rscript {0} + run: | + subdir <- "${{ env.subdir }}" + pkg <- pkgdown::as_pkgdown(".") + + # Deploy pkgdown site to branch + pkgdown::deploy_to_branch(subdir = if (nzchar(subdir)) subdir, clean = nzchar(subdir)) + + # Report deployed site URL + deployed_url <- file.path(pkg$meta$url, subdir) + cat(sprintf('url=%s', deployed_url), file = Sys.getenv("GITHUB_OUTPUT"), append = TRUE) + + - name: Notify pkgdown deployment + if: github.event_name == 'pull_request' + uses: hasura/comment-progress@v2.2.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.repository }} + number: ${{ github.event.number }} + id: pkgdown-deploy + append: false + message: > + :book: ${{ steps.deploy.outputs.url }} + + Preview documentation for this PR (at commit ${{ github.event.pull_request.head.sha }}) + + pkgdown-clean: + if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' }} + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + with: + ref: "gh-pages" + + - name: Clean up PR Preview + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + + preview_dir="preview/pr${{ github.event.pull_request.number }}" + if [ -d "$preview_dir" ]; then + git rm -r $preview_dir + git commit -m "Remove $preview_dir (GitHub Actions)" || echo 'No preview to remove' + git push origin || echo 'No preview to remove' + else + echo 'No preview to remove' + fi - - name: Deploy to GitHub pages 🚀 - if: github.event_name != 'pull_request' - uses: JamesIves/github-pages-deploy-action@v4.5.0 + - name: Notify pkgdown cleanup + uses: hasura/comment-progress@v2.2.0 with: - clean: false - branch: gh-pages - folder: docs + github-token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.repository }} + number: ${{ github.event.number }} + id: pkgdown-deploy + message: | + _:closed_book: Preview documentation for this PR has been cleaned up._ From ce8c36834542c646d453801de75b89804180d2ab Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Mon, 14 Oct 2024 17:08:17 -0700 Subject: [PATCH 2/6] test formatting --- vignettes/articles/enteric_fever_example.Rmd | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vignettes/articles/enteric_fever_example.Rmd b/vignettes/articles/enteric_fever_example.Rmd index b7934dcb..057735bd 100644 --- a/vignettes/articles/enteric_fever_example.Rmd +++ b/vignettes/articles/enteric_fever_example.Rmd @@ -13,7 +13,12 @@ bibliography: ../references.bib --- ## Introduction -This vignette provides users with an example analysis using the [**serocalculator**](https://github.com/UCD-SERG/serocalculator) package by reproducing the analysis for: [**Estimating typhoid incidence from community-based serosurveys: a multicohort study**](https://www.thelancet.com/journals/lanmic/article/PIIS2666-5247(22)00114-8/fulltext) (@Aiemjoy_2022_Lancet). We review the methods underlying the analysis and then walk through an example of enteric fever incidence in Pakistan. Note that because this is a simplified version of the analysis, the results here will differ slightly from those presented in the publication. +This vignette provides users with an example analysis using the [**serocalculator**](https://github.com/UCD-SERG/serocalculator) package +by reproducing the analysis for: +[**Estimating typhoid incidence from community-based serosurveys: a multicohort study**](https://www.thelancet.com/journals/lanmic/article/PIIS2666-5247(22)00114-8/fulltext) (@Aiemjoy_2022_Lancet). +We review the methods underlying the analysis +and then walk through an example of enteric fever incidence in Pakistan. +Note that because this is a simplified version of the analysis, the results here will differ slightly from those presented in the publication. In this example, users will determine the seroincidence of enteric fever in cross-sectional serosurveys conducted as part of the SeroEpidemiology and Environmental Surveillance (SEES) for enteric fever study in Bangladesh, Nepal, and Pakistan. Longitudinal antibody responses were modeled from 1420 blood culture-confirmed enteric fever cases enrolled from the same countries. From ff6366458eb0655c4b09df5abf0f4acee25c7108 Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Mon, 14 Oct 2024 17:20:36 -0700 Subject: [PATCH 3/6] Increment version number to 1.2.0.9017 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index cd89fe11..21eeb85e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: serocalculator Title: Estimating Infection Rates from Serological Data -Version: 1.2.0.9016 +Version: 1.2.0.9017 Authors@R: c( person("Peter", "Teunis", , "p.teunis@emory.edu", role = c("aut", "cph"), comment = "Author of the method and original code."), From 73f3bc39130f9998fce9128b853d3cc4e850ccae Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Mon, 14 Oct 2024 17:21:40 -0700 Subject: [PATCH 4/6] updated news --- NEWS.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 4abcd819..c5afce88 100644 --- a/NEWS.md +++ b/NEWS.md @@ -19,7 +19,9 @@ * Added template for pull requests (from ) (#265) -## Developer-facing changes +## Internal changes + +* Added online preview builds for PRs that change the `pkgdown` website (#309) * initialized [`lintr`](https://lintr.r-lib.org/) with `lintr::use_lint()` (#278) @@ -28,6 +30,7 @@ * fixed `dplyr::select()` deprecation warning in `df_to_array()` (#276) * Added `devtag` to package (using `devtag::use_devtag()`) (#292) + * Added `@dev` tag to `?df_to_array()` (#292) * Generalized `get_()` and `set_()` methods to be general-purpose From d96c630bc2369338837675d0b0372b37df2fae8e Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Mon, 14 Oct 2024 17:25:22 -0700 Subject: [PATCH 5/6] - updated wordlist --- inst/WORDLIST | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/inst/WORDLIST b/inst/WORDLIST index f03a07b0..ef8029da 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -53,6 +53,7 @@ Nadu OSF Orientia PLoS +PRs Pebody Polina RStudio @@ -84,9 +85,6 @@ Valk Vectorized Vellore Versteegh -VignetteEncoding -VignetteEngine -VignetteIndexEntry Volterra Wetering Wiens @@ -97,7 +95,6 @@ behaviour bioassays biomarker boldsymbol -bookdown callout campylobacteriosis cdot @@ -125,7 +122,6 @@ isotypes jinf jitter kDa -knitr le leq llik @@ -155,7 +151,6 @@ qquad recombinant renewcommand rescale -rmarkdown savePath sectionally sera @@ -178,11 +173,9 @@ subfigures th tibble titers -toc tsutsugamushi undercount unstratified varepsilon vec vee -xsectionalData From 265b9d8616a99376cabdc39ce2e0d5c841581fc2 Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Mon, 14 Oct 2024 17:50:04 -0700 Subject: [PATCH 6/6] - disabled search indexing within the preview subdirectories (see https://github.com/rstudio/education-workflows/tree/main/examples) --- _pkgdown.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/_pkgdown.yml b/_pkgdown.yml index e837b2fc..f41dd17c 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -4,3 +4,6 @@ template: light-switch: true bibliography: vignettes/references.bib + +search: + exclude: ['preview/']