Skip to content
Merged
Show file tree
Hide file tree
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
26 changes: 17 additions & 9 deletions .github/workflows/publish_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@ on:
paths: [mkdocs.yml, docs/**, src/**]
workflow_dispatch:

# Shared with the docs job in release.yml -- both commit to gh-pages, and mike
# rejects a deploy when its local view of the branch is behind the remote.
concurrency:
group: publish-docs
cancel-in-progress: false

jobs:
build-deploy:
name: Deploy dev docs
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch gh-pages branch
run: git fetch origin gh-pages:gh-pages || echo "No gh-pages branch yet; mike will create it."
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Sync dependencies
run: make install
- name: Build site
run: make docs-build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: build/documentation/site
publish_branch: gh-pages
force_orphan: true
- name: Configure git for github-actions[bot]
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Deploy the dev version to GitHub Pages
run: make docs-deploy-dev DOCS_PUSH=true
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,36 @@ jobs:
tag_name: ${{ needs.bump.outputs.VERSION_TAG }}
name: ${{ needs.bump.outputs.VERSION_TAG }}
generate_release_notes: true

publish-docs:
name: Publish versioned docs
needs: [bump, publish-to-pypi]
if: ${{ github.event.inputs.dry-run == 'false' }}
runs-on: ubuntu-latest
permissions:
contents: write
# Shared with publish_docs.yml -- both commit to gh-pages, and mike rejects a
# deploy when its local view of the branch is behind the remote.
concurrency:
group: publish-docs
cancel-in-progress: false
steps:
- name: Checkout the release tag
uses: actions/checkout@v4
with:
ref: ${{ needs.bump.outputs.VERSION_TAG }}
fetch-depth: 0
- name: Fetch gh-pages branch
run: git fetch origin gh-pages:gh-pages || echo "No gh-pages branch yet; mike will create it."
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Sync dependencies
run: make install
- name: Configure git for github-actions[bot]
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Docs are versioned per minor release (SHORT_VERSION), so patch releases
# refresh the docs for their minor version instead of adding a new entry.
- name: Deploy ${{ needs.bump.outputs.SHORT_VERSION }} docs and move the latest alias
run: make docs-deploy-release DOCS_VERSION=${{ needs.bump.outputs.SHORT_VERSION }} DOCS_PUSH=true
31 changes: 29 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ DEVELOPER_MODE := 1
COVERAGE_SERVER_PORT := 8000
COVERAGE_DIR := $(PACKAGE_DIR)/build/documentation/coverage/

# Versioned documentation (mike). DOCS_PUSH=true pushes $(DOCS_BRANCH) to $(DOCS_REMOTE);
# leave it unset to build the commit locally so you can inspect it before publishing.
DOCS_BRANCH := gh-pages
DOCS_REMOTE := origin
DOCS_PUSH ?= false
DOCS_VERSION ?=
MIKE_FLAGS := --branch $(DOCS_BRANCH) --remote $(DOCS_REMOTE)
MIKE_PUSH_FLAG := $(if $(filter true,$(DOCS_PUSH)),--push)
# `copy` aliases are plain directories, so they do not depend on the host resolving
# git symlinks (mike's default). Git de-duplicates the identical blobs, so the
# duplicated files cost almost nothing on the $(DOCS_BRANCH) branch.
MIKE_DEPLOY_FLAGS := $(MIKE_FLAGS) $(MIKE_PUSH_FLAG) --update-aliases --alias-type=copy

DEP_FILES := $(wildcard setup.*) $(wildcard requirements*.txt) $(wildcard pyproject.toml)

####################
Expand Down Expand Up @@ -154,13 +167,27 @@ coverage-server: install ## Run coverage server
##@ Documentation Commands
########################

docs-serve: .uv ## Serve MkDocs site locally
docs-serve: .uv ## Serve MkDocs site locally (single version, from the working tree)
uv run mkdocs serve --watch-theme

docs-build: .uv ## Build MkDocs site into build/documentation/site
uv run mkdocs build --clean

.PHONY: docs-serve docs-build
docs-versions: .uv ## List the doc versions published on the $(DOCS_BRANCH) branch
uv run mike list $(MIKE_FLAGS)

docs-serve-versions: .uv ## Serve all published doc versions locally, with the version selector
uv run mike serve $(MIKE_FLAGS)

docs-deploy-dev: .uv ## Deploy working-tree docs as the `dev` version (DOCS_PUSH=true to push)
uv run mike deploy $(MIKE_DEPLOY_FLAGS) dev

docs-deploy-release: .uv ## Deploy docs as DOCS_VERSION + `latest` alias (DOCS_PUSH=true to push)
@test -n "$(DOCS_VERSION)" || { echo "DOCS_VERSION is required, e.g. make docs-deploy-release DOCS_VERSION=1.1"; exit 1; }
uv run mike deploy $(MIKE_DEPLOY_FLAGS) --title "$(DOCS_VERSION)" $(DOCS_VERSION) latest
uv run mike set-default $(MIKE_FLAGS) $(MIKE_PUSH_FLAG) latest

.PHONY: docs-serve docs-build docs-versions docs-serve-versions docs-deploy-dev docs-deploy-release

#####################
##@ Docker Commands
Expand Down
30 changes: 30 additions & 0 deletions docs/developer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,36 @@ make docs-serve
make docs-build
```

### Versioned documentation

The published site keeps one entry per minor release alongside a `dev` build, using [mike](https://github.com/jimporter/mike). The version selector in the site header switches between them.

| URL | Contents |
| --- | --- |
| `/` | Redirect to `latest/` |
| `latest/` | The newest release (an alias for the highest `X.Y`) |
| `X.Y/` | Built from that minor version's most recent release tag |
| `dev/` | Built from the tip of `main` |

Publishing is automatic:

- Pushes to `main` redeploy `dev` (`.github/workflows/publish_docs.yml`).
- A release redeploys its `X.Y` version and moves the `latest` alias (the `publish-docs` job in `.github/workflows/release.yml`). It builds from the release tag, so published docs match the released code. Patch releases refresh their minor version rather than adding an entry.

To preview or publish by hand:

```bash
# Serve every published version, with the version selector
make docs-serve-versions

# List published versions
make docs-versions

# Commit to gh-pages without pushing; add DOCS_PUSH=true to publish
make docs-deploy-dev
make docs-deploy-release DOCS_VERSION=1.1
```

## Docker Development

The package includes Docker support for Lambda container build:
Expand Down
4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ markdown_extensions:
alternate_style: true
extra:
version:
provider: mkdocs
provider: mike
default: latest
alias: true
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ release = [

docs = [
"griffe-pydantic~=1.1",
"mike~=2.1",
"mkdocs~=1.6",
"mkdocs-material~=9.5",
"mkdocstrings[python]~=0.25",
Expand Down
39 changes: 39 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading