Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 71 additions & 15 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# 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
on:
# build dev site on merged pushes
push:
branches: [main, master]
pull_request:
types: [opened, reopened, synchronize, labeled]
types: [opened, reopened, synchronize, labeled, closed]
# build full site on releases
release:
types: [published]
workflow_dispatch:
Expand All @@ -16,14 +18,18 @@ jobs:
# For PRs, only run when the PR has the build-website label.
if: >-
github.event_name != 'pull_request' ||
contains(github.event.pull_request.labels.*.name, 'build-website')
(
github.event.action != 'closed' &&
contains(github.event.pull_request.labels.*.name, 'build-website') &&
(github.event.action != 'labeled' || github.event.label.name == 'build-website')
)
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name == 'pull_request' && github.event.pull_request.number || 'production' }}
cancel-in-progress: true
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
NOT_CRAN: "true"
permissions:
contents: write
steps:
Expand All @@ -34,24 +40,40 @@ jobs:
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
extra-repositories: https://stan-dev.r-universe.dev

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

- name: Build site
id: pkgdown
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
pkgdown::build_site_github_pages(clean = FALSE, new_process = TRUE, install = FALSE)
shell: Rscript {0}
override <- list()

- name: Get pkgdown destination
if: github.event_name == 'pull_request'
id: pkgdown-dest
run: |
echo "folder=$(Rscript -e 'cat(fs::path_rel(pkgdown::as_pkgdown(".", override = list(destination = "docs"))$dst_path))')" >> "$GITHUB_OUTPUT"
pr_number <- Sys.getenv("PR_NUMBER")
if (nzchar(pr_number)) {
pkg <- pkgdown::as_pkgdown(".")

if (pkg$development$mode == "devel") {
Sys.setenv(PKGDOWN_DEV_MODE = "unreleased")
}

override <- list(
url = paste0(pkg$meta$url, "/pr/", pr_number),
template = list(
params = list(noindex = TRUE)
)
)
}

pkgdown::build_site_github_pages(
lazy = FALSE,
run_dont_run = TRUE,
new_process = TRUE,
override = override
)
shell: Rscript {0}

- name: Deploy PR preview
# Forks cannot deploy the site
Expand All @@ -61,7 +83,7 @@ jobs:
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: ${{ steps.pkgdown-dest.outputs.folder }}
folder: docs
target-folder: pr/${{ github.event.pull_request.number }}
clean: true
force: false
Expand All @@ -74,3 +96,37 @@ jobs:
folder: docs
clean: false
force: false
cleanup-preview:
if: >-
github.event_name == 'pull_request' && github.event.action == 'closed'
&& github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest

concurrency:
group: pkgdown-${{ github.event.pull_request.number }}
cancel-in-progress: true

permissions:
contents: write

steps:
- uses: actions/checkout@v7
with:
ref: gh-pages

- name: Remove PR preview
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

git rm -r --ignore-unmatch "pr/$PR_NUMBER"

if git diff --cached --quiet; then
exit 0
fi

git commit -m "Remove pkgdown preview for PR #$PR_NUMBER"
git pull --rebase origin gh-pages
git push origin HEAD:gh-pages
Loading