|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Build combined v1 + v2 MkDocs documentation for GitHub Pages. |
| 4 | +# |
| 5 | +# v1 docs (from the v1.x branch) are placed at the site root. |
| 6 | +# v2 docs (from main) are placed under /v2/. |
| 7 | +# |
| 8 | +# Both branches are fetched fresh from origin, so the output is identical |
| 9 | +# regardless of which branch triggered the workflow. This script is intended |
| 10 | +# to run in CI; for local single-branch preview use `uv run mkdocs serve`. |
| 11 | +# |
| 12 | +# Usage: |
| 13 | +# scripts/build-docs.sh [output-dir] |
| 14 | +# |
| 15 | +# Default output directory: site |
| 16 | +# |
| 17 | +set -euo pipefail |
| 18 | + |
| 19 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 20 | +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 21 | +OUTPUT_DIR="$(cd "$REPO_ROOT" && mkdir -p "${1:-site}" && cd "${1:-site}" && pwd)" |
| 22 | +V1_WORKTREE="$REPO_ROOT/.worktrees/v1-docs" |
| 23 | +V2_WORKTREE="$REPO_ROOT/.worktrees/v2-docs" |
| 24 | + |
| 25 | +cleanup() { |
| 26 | + cd "$REPO_ROOT" |
| 27 | + git worktree remove --force "$V1_WORKTREE" 2>/dev/null || true |
| 28 | + git worktree remove --force "$V2_WORKTREE" 2>/dev/null || true |
| 29 | + rmdir "$REPO_ROOT/.worktrees" 2>/dev/null || true |
| 30 | +} |
| 31 | +trap cleanup EXIT |
| 32 | + |
| 33 | +rm -rf "${OUTPUT_DIR:?}"/* |
| 34 | + |
| 35 | +build_branch() { |
| 36 | + local branch="$1" worktree="$2" dest="$3" |
| 37 | + |
| 38 | + echo "=== Building docs for ${branch} ===" |
| 39 | + git fetch origin "$branch" |
| 40 | + git worktree remove --force "$worktree" 2>/dev/null || true |
| 41 | + rm -rf "$worktree" |
| 42 | + git worktree add --detach "$worktree" "origin/${branch}" |
| 43 | + |
| 44 | + ( |
| 45 | + cd "$worktree" |
| 46 | + uv sync --frozen --group docs |
| 47 | + uv run --frozen --no-sync mkdocs build --site-dir "$dest" |
| 48 | + ) |
| 49 | +} |
| 50 | + |
| 51 | +build_branch v1.x "$V1_WORKTREE" "$OUTPUT_DIR" |
| 52 | +build_branch main "$V2_WORKTREE" "$OUTPUT_DIR/v2" |
| 53 | + |
| 54 | +echo "=== Combined docs built at $OUTPUT_DIR ===" |
0 commit comments