Skip to content

Commit

Permalink
issue #120: add reusable workflow to check pkgdown builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
k-doering-NOAA committed May 23, 2024
1 parent 6fbec81 commit a528853
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build-pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
workflow_call:

name: build-pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

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

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

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

- name: build pkgdown
run: |
Rscript -e 'pkgdown::build_site()'
- name: save pkgdown output
uses: actions/upload-artifact@v4
with:
name: pkgdown-site
path: docs/

11 changes: 11 additions & 0 deletions R/use_r_workflows.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ use_update_pkgdown <- function(workflow_name = "call-update-pkgdown.yml") {
)
}

#' use workflow in current pkg to check pkgdown site builds.
#' @template workflow_name
#' @export
use_build_pkgdown <- function(workflow_name = "call-build-pkgdown.yml") {
check_workflow_name(workflow_name)
usethis::use_github_action("call-build-pkgdown.yml",
save_as = workflow_name,
url = "https://raw.githubusercontent.com/nmfs-fish-tools/ghactions4r/main/inst/templates/call-build-pkgdown.yml"
)
}

#' use workflow in current pkg to run devtools::document() and submit results as a PR
#' @template workflow_name
#' @export
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ ghactions4r::use_doc_and_style_r(use_rm_dollar_sign = FALSE)
ghactions4r::use_update_pkgdown()
```

- To check that a pkgdown site builds:
```r
ghactions4r::use_build_pkgdown()
```

- To automatically build and deploy bookdown (to a branch called gh-pages in the same repository) that is in an R package repository:
```r
ghactions4r::use_build_deploy_bookdown()
Expand Down
15 changes: 15 additions & 0 deletions inst/templates/call-build-pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Checks that the pkgdown site builds for a repository.
# this assumes pkgdown is already set up.
name: call-build-pkgdown
# on specifies the build triggers. See more info at https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
# this workflow runs on pushes to main or master or any time a new tag is pushed
# it also runs everytime a pull request to main or master is opened.
push:
branches: [main, master]
tags: ['*']
pull_request:
branches: [main, master]
jobs:
call-workflow:
uses: nmfs-fish-tools/ghactions4r/.github/workflows/build-pkgdown.yml@main
7 changes: 7 additions & 0 deletions tests/testthat/test-use_r_workflows.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ test_that("use_update_pkgdown()) works", {
expect_snapshot(test)
})

test_that("use_build_pkgdown()) works", {
use_build_pkgdown()
expect_true(file.exists(".github/workflows/call-build-pkgdown.yml"))
test <- readLines(".github/workflows/call-build-pkgdown.yml")
expect_snapshot(test)
})

test_that("use_update_roxygen_docs() works", {
use_update_roxygen_docs()
expect_true(file.exists(".github/workflows/call-update-docs.yml"))
Expand Down

0 comments on commit a528853

Please sign in to comment.