Skip to content

Add multi-version pkgdown documentation with version dropdown menu#173

Open
Copilot wants to merge 10 commits intomainfrom
copilot/copy-pkgdown-setup
Open

Add multi-version pkgdown documentation with version dropdown menu#173
Copilot wants to merge 10 commits intomainfrom
copilot/copy-pkgdown-setup

Conversation

Copy link
Contributor

Copilot AI commented Jan 9, 2026

Implementation Complete ✅

Successfully implemented multi-version pkgdown documentation with version dropdown menus, matching the insightsengineering/tern setup.

What was implemented

  • Understand current pkgdown setup in serodynamics
  • Research insightsengineering's pkgdown multi-version approach
  • Create new .github/workflows/docs.yaml workflow with multi-version support
  • Replace old pkgdown.yaml with comprehensive workflow
  • Add PR preview functionality to new workflow
  • Add PR cleanup job for closed PRs
  • Fix workflow conditions and syntax
  • Validate YAML syntax
  • Verify pkgdown configuration meets requirements
  • Add NEWS entry documenting the change
  • Create comprehensive documentation in .github/MULTI_VERSION_DOCS.md
  • Fix security vulnerabilities in GitHub Actions
  • Configure path filters and draft PR handling
  • Address code review feedback for workflow reliability

Security Fixes Applied

Updated all GitHub Actions to latest stable v4 versions:

  • actions/download-artifact: v4 → v4.1.8

    • Critical Fix: Patches CVE-2024-42471 (Arbitrary File Write via artifact extraction)
    • Affected versions: >= 4.0.0, < 4.1.3
  • actions/checkout: v4 → v4.3.1 (latest stable v4)

  • actions/upload-artifact: v4 → v4.6.2 (latest stable v4)

Key Features

1. Multi-version documentation

  • Uses insightsengineering/r-pkgdown-multiversion@v3 action
  • Documentation built for each version (main branch + version tags)
  • Each version stored in separate directory on gh-pages branch
  • Default landing page: latest-tag (most recent release)
  • Proper version tagging: Uses devel = FALSE for releases, devel = TRUE for development

2. Version dropdown

  • Shows: main, latest-tag, and version tags (v*..)
  • Order: main first, then latest-tag, then other versions
  • Regex filter: ^main$|^latest-tag$|^v([0-9]+\\.)?([0-9]+\\.)?([0-9]+)$
  • Note: Version dropdown only appears on deployed versions (main/tags), not PR previews

3. PR preview functionality

  • PR previews in preview/pr<number> directories
  • Preview URLs posted as PR comments
  • Automatic cleanup when PRs close
  • Works on draft PRs for early feedback
  • No version dropdown in previews (by design - previews are temporary)

4. Automated deployment

  • Tags (v*): Documentation built and added to gh-pages
  • Main branch: Documentation rebuilt for main
  • Path filtering: Workflow runs when documentation-related files or workflow file changes
    • inst/templates/**, pkgdown/**, _pkgdown.*
    • DESCRIPTION, **.md, **.Rmd
    • man/**, LICENSE.*, NAMESPACE
    • .github/workflows/docs.yaml

5. Release integration

  • pkgdown.zip uploaded to GitHub releases for tagged versions

Workflow Jobs

  1. docs: Builds pkgdown site, deploys to version-specific directories
  2. multi-version-docs: Creates version dropdown and navigation structure (only for push/workflow_dispatch)
  3. upload-release-assets: Uploads pkgdown.zip to releases
  4. cleanup-pr-preview: Removes PR previews when PRs close

Files Changed

  1. .github/workflows/docs.yaml (new)

    • Replaces old pkgdown.yaml
    • 4 jobs: docs, multi-version-docs, upload-release-assets, cleanup-pr-preview
    • All actions updated to latest secure versions
    • Path filters optimize workflow execution
    • Runs on draft PRs for early preview
    • Conditional devel parameter for proper version labeling
    • Robust commit message and ref checking
  2. NEWS.md (updated)

    • Added entry documenting the new multi-version setup
  3. .github/MULTI_VERSION_DOCS.md (new)

    • Comprehensive guide for using the multi-version documentation

Prerequisites Verified ✅

  • pkgdown/_pkgdown.yml has bootstrap: 5
  • pkgdown/_pkgdown.yml has url field
  • DESCRIPTION has URL field with pkgdown site URL
  • GitHub Pages enabled on gh-pages branch
  • Using pkgdown >= 2.0.0

User Experience

When visiting https://ucd-serg.github.io/serodynamics/, users will see:

  • Dropdown menu in navbar showing available versions
  • Ability to switch between documentation for different versions
  • Default view showing latest tagged release documentation

Note on PR Previews: PR previews are standalone documentation builds for reviewing changes. They do not include the version dropdown menu - that only appears after merging to main or creating a version tag.

Next Steps

  1. Approve workflow: Repository admin needs to approve first workflow run in Actions tab
  2. Test PR preview: This PR should generate a preview once approved (no version dropdown expected)
  3. Create version tag: Tag a release (e.g., v0.1.0) to test version-specific documentation with dropdown
  4. Verify dropdown: After merging to main or tagging, check that version dropdown appears on documentation site

See .github/MULTI_VERSION_DOCS.md for complete documentation on using the new setup.

Original prompt

This section details on the original issue you should resolve

<issue_title>copy the pkgdown setup from insightsengineering</issue_title>
<issue_description>https://github.com/insightsengineering/tern

in particular, I want the dropdown menu for package versions</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits January 9, 2026 06:17
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
- Update actions/download-artifact from v4 to v4.1.8 (fixes CVE-2024-42471: arbitrary file write)
- Update actions/checkout from v4 to v4.3.1 (latest stable v4)
- Update actions/upload-artifact from v4 to v4.6.2 (latest stable v4)

Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Copilot AI changed the title [WIP] Copy pkgdown setup from insightsengineering repository Add multi-version pkgdown documentation with version dropdown menu Jan 9, 2026
Copilot AI requested a review from d-morrison January 9, 2026 06:26
Copy link
Collaborator

@d-morrison d-morrison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add pr preview to docs workflow

Copy link
Contributor Author

Copilot AI commented Jan 9, 2026

add pr preview to docs workflow

PR preview functionality is already implemented in the docs.yaml workflow (lines 226-273). It deploys PR previews to preview/pr<number>/ and posts the preview URL as a comment on the PR, just like the original pkgdown.yaml did.

Could you clarify what specific change you'd like regarding PR previews? For example:

  • Modify how/where previews are deployed?
  • Change the preview URL format?
  • Add additional preview features?

Copy link
Collaborator

@d-morrison d-morrison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure the docs workflow runs when it is modified

Ensure the docs workflow runs when .github/workflows/docs.yaml is modified, allowing workflow changes to be tested automatically on PRs and pushes.

Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 9, 2026

make sure the docs workflow runs when it is modified

Added .github/workflows/docs.yaml to the path filters for both push and pull_request events in commit b016f79. The workflow will now run when the workflow file itself is modified, enabling automatic testing of workflow changes.

Copy link
Collaborator

@d-morrison d-morrison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs workflow still didn't run; fix

Path filters were preventing the workflow from running reliably. Removing them ensures the workflow runs on all PR and push events, which is needed for testing workflow changes.

Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 9, 2026

docs workflow still didn't run; fix

Removed path filters from the docs workflow in commit c4ca44d. The workflow will now run on all PR and push events, ensuring it executes whenever the workflow file is modified. Path filters were preventing reliable workflow execution.

Copilot AI requested a review from d-morrison January 9, 2026 09:50
@d-morrison d-morrison marked this pull request as ready for review January 9, 2026 09:52
Copilot AI review requested due to automatic review settings January 9, 2026 09:52
Copy link
Collaborator

@d-morrison d-morrison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put the path filters back and remove the requirement that the pr is not a draft

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

📖 https://ucdavis.github.io/serodynamics/preview/pr173/
Preview documentation for this PR (at commit 989119c)

github-actions bot added a commit that referenced this pull request Jan 9, 2026
- Restored path filters for push and pull_request events to optimize workflow execution
- Removed draft PR check to allow workflow to run on draft PRs
- Workflow now runs when documentation-related files or the workflow file itself is modified

Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 9, 2026

put the path filters back and remove the requirement that the pr is not a draft

Restored path filters and removed draft PR check in commit cf0c771. The workflow will now:

  • Run on draft PRs (no longer skips them)
  • Only trigger when documentation-related files or the workflow file itself is modified
  • Path filters include: inst/templates/, pkgdown/, _pkgdown.*, DESCRIPTION, **.md, **.Rmd, man/, LICENSE.*, NAMESPACE, and .github/workflows/docs.yaml

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements multi-version pkgdown documentation with a version dropdown menu, replacing the previous single-version setup. The implementation is based on the insightsengineering/tern reference setup and uses the insightsengineering/r-pkgdown-multiversion@v3 action to provide version navigation.

Key changes:

  • New comprehensive docs.yaml workflow with 4 jobs for building docs, creating multi-version navigation, uploading release assets, and cleaning up PR previews
  • Removal of the old pkgdown.yaml workflow
  • Documentation for the new multi-version setup in .github/MULTI_VERSION_DOCS.md

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
.github/workflows/docs.yaml New multi-version documentation workflow replacing pkgdown.yaml, with jobs for building docs, version navigation, release asset uploads, and PR preview cleanup
.github/workflows/pkgdown.yaml Removed old single-version pkgdown workflow
.github/MULTI_VERSION_DOCS.md Comprehensive documentation explaining the multi-version setup, features, configuration, and troubleshooting
NEWS.md Added entry documenting the new multi-version documentation feature

Comment on lines +29 to +30
- main
paths:
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition !contains(github.event.commits[0].message, '[skip docs]') may fail when the workflow is triggered by tag pushes or workflow_dispatch, because the github.event.commits array might not exist in these contexts. Consider using github.event.head_commit.message instead, which is more reliable across different event types, or wrap the check in a condition that only applies to push events on branches.

Copilot uses AI. Check for mistakes.
sudo apt-get update
sudo apt-get install -y jags libcurl4-openssl-dev
shell: bash

Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pkgdown::build_site() call uses devel = TRUE for all builds, including tagged releases. For version tags (releases), you typically want devel = FALSE to indicate it's a released version, not a development version. Consider adding conditional logic to set devel = FALSE when building documentation for version tags, and devel = TRUE only for PRs and main branch builds.

Copilot uses AI. Check for mistakes.
Comment on lines +103 to +113
### Path Filtering
The workflow only runs when these files change:
- `inst/templates/**`
- `pkgdown/**`
- `_pkgdown.*`
- `DESCRIPTION`
- `**.md`, `**.Rmd`
- `man/**`
- `LICENSE.*`
- `NAMESPACE`

Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states that the workflow has path filtering, but the actual workflow file (docs.yaml) does not have any path filters in its trigger configuration. Lines 104-112 in this documentation file should be removed as they are inaccurate. The PR description correctly mentions "No path filtering: Workflow runs on all PR and push events for reliable execution", which aligns with the actual workflow implementation.

Suggested change
### Path Filtering
The workflow only runs when these files change:
- `inst/templates/**`
- `pkgdown/**`
- `_pkgdown.*`
- `DESCRIPTION`
- `**.md`, `**.Rmd`
- `man/**`
- `LICENSE.*`
- `NAMESPACE`

Copilot uses AI. Check for mistakes.
Comment on lines +61 to +66

- name: Get current branch or tag 🏷️
id: current-branch-or-tag
run: |
if [ "${{ steps.branch-name.outputs.is_tag }}" == "true" ]; then
echo "Current tag: ${{ steps.branch-name.outputs.tag }}"
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the workflow is triggered by a tag push, using steps.branch-name.outputs.current_branch as the ref may not work correctly since tags don't have a "current_branch". For tag events, the ref should be the tag itself. Consider modifying the checkout to handle tags explicitly, similar to how it's done in the "Get current branch or tag" step above. A better approach would be to use the output from that step (steps.current-branch-or-tag.outputs.ref-name) or to add a separate checkout step for tags that uses the tag ref directly.

Copilot uses AI. Check for mistakes.
Comment on lines +259 to +261
echo "url=https://${REPO_OWNER}.github.io/${REPO_NAME}/${PREVIEW_DIR}/" >> $GITHUB_OUTPUT
shell: bash

Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition !contains(github.event.commits[0].message, '[skip docs]') may fail when the workflow is triggered by workflow_dispatch or tag pushes, because the github.event.commits array might not exist or be structured differently in these contexts. Consider using a safer condition that handles cases where commits might not be available, or move the commit message check to only run when it's applicable (push events on branches). Alternatively, use github.event.head_commit.message which is more reliable across different event types.

Copilot uses AI. Check for mistakes.
Comment on lines 281 to 283
(github.event_name == 'push' || github.event_name == 'workflow_dispatch')
&& !contains(github.event.commits[0].message, '[skip docs]')
steps:
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition !contains(github.event.commits[0].message, '[skip docs]') may fail for tag push events because the github.event.commits array might not exist or be structured differently when pushing tags. Consider using github.event.head_commit.message instead, or remove this check for tag-specific jobs since tags are deliberate version releases where you'd always want documentation built.

Copilot uses AI. Check for mistakes.
Copilot AI requested a review from d-morrison January 9, 2026 09:59
github-actions bot added a commit that referenced this pull request Jan 9, 2026
Copy link
Collaborator

@d-morrison d-morrison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why doesn't the version selector drop down menu appear in the preview?

Copy link
Contributor Author

Copilot AI commented Jan 9, 2026

why doesn't the version selector drop down menu appear in the preview?

The version dropdown menu only appears on the deployed versioned documentation (main branch and release tags), not in PR previews. This is by design:

  1. The multi-version-docs job (lines 276-296) creates the dropdown menu using the r-pkgdown-multiversion action
  2. This job only runs on push or workflow_dispatch events (line 281), not on pull requests
  3. PR previews (lines 227-273) are standalone documentation builds that don't get added to the version navigation structure

PR previews are temporary and meant for reviewing documentation changes before merging. Once the PR is merged to main or a version tag is created, the multi-version-docs job will run and add that version to the dropdown menu.

To see the version dropdown:

  • Merge the PR to main (or wait for it to be merged), then the dropdown will show "main"
  • Create a version tag (e.g., v0.1.0), and it will appear in the dropdown as a selectable version

- Fix commit message check to use github.event.head_commit.message (more reliable across event types)
- Fix tag checkout to use the ref-name output from current-branch-or-tag step
- Add conditional logic for pkgdown devel parameter: FALSE for version tags, TRUE for dev builds
- Remove redundant commit message checks from jobs that depend on the docs job
- Addresses code review feedback for better workflow reliability

Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Copilot AI requested a review from d-morrison January 9, 2026 10:15
github-actions bot added a commit that referenced this pull request Jan 9, 2026
@d-morrison d-morrison removed their request for review January 21, 2026 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

copy the pkgdown setup from insightsengineering

3 participants