|
| 1 | +# Multi-Version Documentation Setup |
| 2 | + |
| 3 | +This repository uses multi-version pkgdown documentation with a version dropdown menu, based on the [insightsengineering/tern](https://github.com/insightsengineering/tern) setup. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +### Version Dropdown Menu |
| 8 | +Users can switch between different versions of the documentation using a dropdown menu in the navbar: |
| 9 | +- **main**: Development version (latest commits on main branch) |
| 10 | +- **latest-tag**: Most recent release version |
| 11 | +- **v\*.\*.\***: Version-tagged releases (e.g., v1.0.0, v1.1.0) |
| 12 | + |
| 13 | +### Default Landing Page |
| 14 | +The default page at https://ucd-serg.github.io/serocalculator/ shows the **latest-tag** (most recent release) documentation. |
| 15 | + |
| 16 | +### PR Previews |
| 17 | +Pull requests automatically generate preview documentation at: |
| 18 | +- `https://ucd-serg.github.io/serocalculator/preview/pr<number>/` |
| 19 | +- Preview link is posted as a comment on the PR |
| 20 | +- Previews are automatically cleaned up when PRs are closed |
| 21 | + |
| 22 | +## How It Works |
| 23 | + |
| 24 | +### Workflow: `.github/workflows/docs.yaml` |
| 25 | + |
| 26 | +The workflow has four jobs: |
| 27 | + |
| 28 | +1. **docs**: Builds the pkgdown site |
| 29 | + - Runs on: PRs, pushes to main, version tags |
| 30 | + - Deploys to version-specific directories on gh-pages |
| 31 | + |
| 32 | +2. **multi-version-docs**: Creates version dropdown |
| 33 | + - Runs on: pushes to main, workflow_dispatch |
| 34 | + - Uses `insightsengineering/r-pkgdown-multiversion@v3` |
| 35 | + - Generates navigation between versions |
| 36 | + |
| 37 | +3. **upload-release-assets**: Upload pkgdown.zip |
| 38 | + - Runs on: version tags only |
| 39 | + - Uploads documentation to GitHub Releases |
| 40 | + |
| 41 | +4. **cleanup-pr-preview**: Clean up PR previews |
| 42 | + - Runs on: PR close events |
| 43 | + - Removes preview directories from gh-pages |
| 44 | + |
| 45 | +### Configuration |
| 46 | + |
| 47 | +#### `pkgdown/_pkgdown.yml` |
| 48 | +```yaml |
| 49 | +template: |
| 50 | + bootstrap: 5 # Required for multi-version action |
| 51 | + |
| 52 | +url: https://ucd-serg.github.io/serocalculator/ # Required |
| 53 | + |
| 54 | +search: |
| 55 | + exclude: ['preview/'] # Exclude PR previews from search |
| 56 | +``` |
| 57 | +
|
| 58 | +#### `DESCRIPTION` |
| 59 | +``` |
| 60 | +URL: https://github.com/UCD-SERG/serocalculator, |
| 61 | + https://ucd-serg.github.io/serocalculator/ |
| 62 | +``` |
| 63 | +
|
| 64 | +### Version Filtering |
| 65 | +
|
| 66 | +Versions shown in the dropdown are controlled by: |
| 67 | +
|
| 68 | +**refs-order**: `"main latest-tag"` |
| 69 | +- Determines the order of versions in the dropdown |
| 70 | +
|
| 71 | +**branches-or-tags-to-list**: `'^main$|^latest-tag$|^v([0-9]+\\.)?([0-9]+\\.)?([0-9]+)$'` |
| 72 | +- Regex pattern matching versions to include |
| 73 | +- Matches: `main`, `latest-tag`, and semver tags like `v1.0.0` |
| 74 | +
|
| 75 | +## Creating a New Version |
| 76 | +
|
| 77 | +To create a new versioned documentation: |
| 78 | +
|
| 79 | +1. **Tag a release**: |
| 80 | + ```bash |
| 81 | + git tag v1.0.0 |
| 82 | + git push origin v1.0.0 |
| 83 | + ``` |
| 84 | + |
| 85 | +2. **Workflow runs automatically**: |
| 86 | + - Builds pkgdown site for v1.0.0 |
| 87 | + - Deploys to `gh-pages/v1.0.0/` |
| 88 | + - Updates version dropdown to include v1.0.0 |
| 89 | + - Uploads pkgdown.zip to the GitHub release |
| 90 | + |
| 91 | +3. **Version appears in dropdown**: |
| 92 | + - Users can now select v1.0.0 from the versions menu |
| 93 | + - If it's the latest tag, it becomes the default landing page |
| 94 | + |
| 95 | +## Triggering Builds |
| 96 | + |
| 97 | +### Automatic Triggers |
| 98 | +- **PR opened/updated**: Builds preview documentation |
| 99 | +- **Push to main**: Rebuilds main version docs |
| 100 | +- **Version tag pushed**: Builds new version docs |
| 101 | +- **PR closed**: Cleans up preview |
| 102 | + |
| 103 | +### Manual Trigger |
| 104 | +Use the Actions tab to manually trigger the workflow via `workflow_dispatch`. |
| 105 | + |
| 106 | +## Troubleshooting |
| 107 | + |
| 108 | +### Workflow requires approval |
| 109 | +First-time workflows using external actions need manual approval: |
| 110 | +1. Go to repository Actions tab |
| 111 | +2. Find the workflow run |
| 112 | +3. Click "Approve and run" |
| 113 | +4. Subsequent runs will execute automatically |
| 114 | + |
| 115 | +### Version not appearing in dropdown |
| 116 | +Check that: |
| 117 | +1. Documentation was successfully built for that version |
| 118 | +2. Version name matches the regex pattern |
| 119 | +3. Version is listed in `refs-order` or matches `branches-or-tags-to-list` |
| 120 | + |
| 121 | +### Default landing page not updating |
| 122 | +Ensure: |
| 123 | +1. `default-landing-page: "latest-tag"` is set in workflow |
| 124 | +2. Latest tag has documentation built |
| 125 | +3. Multi-version-docs job completed successfully |
| 126 | + |
| 127 | +## Comparison to Original Setup |
| 128 | + |
| 129 | +### Before (pkgdown.yaml) |
| 130 | +- Single version (main branch only) |
| 131 | +- PR previews only |
| 132 | +- No version switching |
| 133 | + |
| 134 | +### After (docs.yaml) |
| 135 | +- Multiple versions (main + all releases) |
| 136 | +- Version dropdown menu |
| 137 | +- PR previews maintained |
| 138 | +- Default to latest release |
| 139 | +- Version-specific documentation URLs |
| 140 | + |
| 141 | +## Resources |
| 142 | + |
| 143 | +- [insightsengineering/r-pkgdown-multiversion](https://github.com/insightsengineering/r-pkgdown-multiversion) |
| 144 | +- [insightsengineering/tern](https://github.com/insightsengineering/tern) (reference implementation) |
| 145 | +- [pkgdown documentation](https://pkgdown.r-lib.org/) |
0 commit comments