Skip to content

Commit 7adfe48

Browse files
committed
refactor(docs): make versioning the default
1 parent dde8d38 commit 7adfe48

3 files changed

Lines changed: 38 additions & 24 deletions

File tree

‎.github/workflows/docs.yml‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ on:
4343
default: false
4444
type: boolean
4545
docs_version:
46-
description: Optional version identifier used for a versioned GitHub Pages deployment
46+
description: Version identifier used for a GitHub Pages deployment
4747
required: false
48-
default: ''
48+
default: dev
4949
type: string
5050
docs_version_title:
5151
description: Optional display title for the documentation version
@@ -106,7 +106,7 @@ on:
106106

107107
concurrency:
108108
group: >-
109-
${{ inputs.docs_version != '' &&
109+
${{ inputs.deploy_github_pages &&
110110
format('versioned-docs-{0}-{1}', github.repository, inputs.docs_versions_branch) ||
111111
format('docs-build-{0}', github.run_id) }}
112112
cancel-in-progress: false
@@ -172,20 +172,15 @@ jobs:
172172
if-no-files-found: error
173173

174174
- name: Validate versioned documentation configuration
175-
if: inputs.docs_version != ''
175+
if: inputs.deploy_github_pages
176176
env:
177-
DEPLOY_GITHUB_PAGES: ${{ inputs.deploy_github_pages }}
178177
DOCS_ALIASES: ${{ inputs.docs_aliases }}
179178
DOCS_DEFAULT_VERSION: ${{ inputs.docs_default_version }}
180179
DOCS_VERSION: ${{ inputs.docs_version }}
181180
DOCS_VERSION_TITLE: ${{ inputs.docs_version_title }}
182181
DOCS_VERSIONS_BRANCH: ${{ inputs.docs_versions_branch }}
183182
run: |
184183
identifier_pattern='^[A-Za-z0-9][A-Za-z0-9._-]*$'
185-
if [[ "$DEPLOY_GITHUB_PAGES" != "true" ]]; then
186-
echo 'A documentation version requires GitHub Pages deployment.' >&2
187-
exit 2
188-
fi
189184
if [[ ! "$DOCS_VERSION" =~ $identifier_pattern ]]; then
190185
echo "Invalid documentation version: $DOCS_VERSION" >&2
191186
exit 2
@@ -211,13 +206,13 @@ jobs:
211206
fi
212207
213208
- name: Install versioned documentation support
214-
if: inputs.docs_version != ''
209+
if: inputs.deploy_github_pages
215210
env:
216211
MIKE_PACKAGE: mike @ git+https://github.com/squidfunk/mike.git@2d4ad799442f4592db8ad53b179bfb33db8c69ac
217212
run: uv pip install "$MIKE_PACKAGE"
218213

219214
- name: Assemble versioned documentation
220-
if: inputs.docs_version != ''
215+
if: inputs.deploy_github_pages
221216
env:
222217
DOCS_ALIASES: ${{ inputs.docs_aliases }}
223218
DOCS_DEFAULT_VERSION: ${{ inputs.docs_default_version }}
@@ -477,14 +472,8 @@ jobs:
477472
if: inputs.deploy_github_pages
478473
uses: actions/configure-pages@v6
479474

480-
- name: Upload GitHub Pages artifact
481-
if: inputs.deploy_github_pages && inputs.docs_version == ''
482-
uses: actions/upload-pages-artifact@v5
483-
with:
484-
path: ${{ inputs.site_path }}/
485-
486475
- name: Upload versioned GitHub Pages artifact
487-
if: inputs.deploy_github_pages && inputs.docs_version != ''
476+
if: inputs.deploy_github_pages
488477
uses: actions/upload-pages-artifact@v5
489478
with:
490479
path: versioned-site/

‎docs/documentation-workflows.md‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ jobs:
8383
8484
The project is created on the first trusted pull request, using `main` as its production branch by default. Set `cloudflare_production_branch` if the repository uses a different default branch. Set `cloudflare_preview_domain` to publish previews at `pr-42.preview.example.com`; leave it empty to use `pr-42.stacksmith-docs.pages.dev`. Set `cloudflare_preview_zone` when the preview domain is a subdomain of the DNS zone. The API token needs Pages Write, Zone Read, and Zone DNS Edit permissions when custom preview domains are enabled. Fork pull requests receive the build artifact but are not published because repository secrets are unavailable. A separate `pull_request`-closed workflow can remove the custom hostname, its matching DNS record, and older deployments for that preview branch while preserving the shared Pages project. Cloudflare retains the latest branch deployment.
8585

86-
## Deploy a single documentation site to GitHub Pages
86+
## Deploy documentation to GitHub Pages
8787

88-
Enable GitHub Actions as the repository's Pages source. A default-branch caller can then select production deployment. Existing callers continue to use this mode when `docs_version` is empty.
88+
Enable GitHub Actions as the repository's Pages source. GitHub Pages deployments are versioned by default and publish the current checkout as `dev` unless the caller selects another version. The caller must grant `contents: write` so the workflow can update the versions branch.
8989

9090
```yaml
9191
jobs:
@@ -96,14 +96,14 @@ jobs:
9696
dependency_group: dev
9797
deploy_github_pages: true
9898
permissions:
99-
contents: read
99+
contents: write
100100
pages: write
101101
id-token: write
102102
```
103103

104-
Pin the workflow to the release that matches the installed package. Pin an exact commit SHA when an immutable workflow reference is required.
104+
This initial deployment creates `dev` and uses it as the site root when the versions branch does not already contain a root redirect. Pin the workflow to the release that matches the installed package. Pin an exact commit SHA when an immutable workflow reference is required.
105105

106-
## Deploy versioned documentation to GitHub Pages
106+
## Configure versioned documentation
107107

108108
Versioned deployment uses the Zensical-compatible `mike` fork. The workflow keeps generated versions on a Git branch and publishes the assembled branch through GitHub Actions, so the repository's Pages source remains GitHub Actions. The fork is a transitional dependency until Zensical provides native versioning support.
109109

@@ -118,7 +118,7 @@ default = ["latest", "dev"]
118118
alias_type = "redirect"
119119
```
120120

121-
Pass a version identifier when deploying. The caller must grant `contents: write` so the workflow can update the versions branch.
121+
Pass a version identifier, title, aliases, and default version when publishing a release.
122122

123123
```yaml
124124
jobs:
@@ -142,6 +142,22 @@ jobs:
142142

143143
The workflow still performs the strict `poe docs-build` check and uploads the current checkout as the normal Actions artifact. It then builds through `mike`, updates the versions branch, and gives the complete assembled site to GitHub Pages.
144144

145+
## Preview multiple versions locally
146+
147+
`poe docs-serve` builds and watches only the current checkout. It is the quickest way to review content, but its version selector has no assembled `versions.json` to load.
148+
149+
Install the same pinned Zensical-compatible `mike` fork used by the workflow, assemble two versions on a disposable local Git branch, and serve that branch.
150+
151+
```shell
152+
uv pip install 'mike @ git+https://github.com/squidfunk/mike.git@2d4ad799442f4592db8ad53b179bfb33db8c69ac'
153+
uv run --no-sync mike deploy --branch local-docs --alias-type redirect --update-aliases --title Development dev
154+
uv run --no-sync mike deploy --branch local-docs --alias-type redirect --update-aliases --title 0.12.1 0.12 latest
155+
uv run --no-sync mike set-default --branch local-docs latest
156+
uv run --no-sync mike serve --branch local-docs
157+
```
158+
159+
Open `http://localhost:8000/`. The root redirects to `latest`, and the selector switches between `0.12` and `dev`. These commands create only local commits on `local-docs`; they do not push anything. Stop the server before removing the disposable branch with `git branch -D local-docs`.
160+
145161
## Publish development and release versions
146162

147163
Use one serialized production workflow for default-branch and tag deployment. Publish the default branch as `dev`, and publish stable tags to a major/minor documentation series. For example, `v2.4.3` updates version `2.4`, uses `2.4.3` as its display title, moves the `latest` alias, and makes `latest` the site root. Later default-branch deployments update `dev` without moving the root away from `latest`.

‎tests/test_docs.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ def test_reusable_docs_workflow_supports_artifacts_and_publishers():
6060
assert "docs_default_version:" in workflow
6161
assert "github.com/squidfunk/mike.git@2d4ad799" in workflow
6262
assert "Upload versioned GitHub Pages artifact" in workflow
63+
assert (
64+
"""docs_version:
65+
description: Version identifier used for a GitHub Pages deployment
66+
required: false
67+
default: dev"""
68+
in workflow
69+
)
70+
assert workflow.count("actions/upload-pages-artifact@v5") == 1
71+
assert "if: inputs.deploy_github_pages && inputs.docs_version == ''" not in workflow
6372

6473

6574
def test_repository_uses_reusable_docs_workflow():

0 commit comments

Comments
 (0)