Skip to content

Commit ceb32bc

Browse files
authored
Merge pull request #1178 from EnergySystemsModellingLab/versioned-docs
Publish old versions of docs
2 parents 312f691 + b19525a commit ceb32bc

File tree

11 files changed

+206
-3
lines changed

11 files changed

+206
-3
lines changed

.github/actions/generate-docs/action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Generate documentation
22
description: Generate all documentation
3+
inputs:
4+
build:
5+
description: Just subcommand for `build-docs` to run
6+
default: all
37

48
runs:
59
using: composite
@@ -18,4 +22,4 @@ runs:
1822
enable-cache: true
1923
- name: Build documentation
2024
shell: bash
21-
run: just build-docs
25+
run: just build-docs::${{ inputs.build }}

.github/workflows/deploy-docs.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,17 @@ jobs:
2323
steps:
2424
- name: Checkout repository
2525
uses: actions/checkout@v6
26+
with:
27+
fetch-tags: true
28+
fetch-depth: 0
29+
- name: Set user name and email for git
30+
run: |
31+
# Needed so we can apply patches
32+
git config --global user.name "GitHub Actions"
33+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
2634
- uses: ./.github/actions/generate-docs
35+
with:
36+
build: all_with_old
2737
- name: Setup pages
2838
uses: actions/configure-pages@v5
2939
- name: Upload artifact

.lycheeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# For some reason these spurious links appear in some cargo doc-generated files
22
^file://.+/MUSE2/book/api/index\.html$
3+
^file://.+/MUSE2/book/README\.html$
34

45
# Some of these links give a 404, even though they're generated in the API docs. No idea why.
56
^https://docs.rs/erased-serde/

build-docs.just

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Make rustdoc warnings fatal
22
export RUSTDOCFLAGS := "-D warnings"
33

4-
# Build all documentation
5-
all: cli-help file-format examples book api
4+
# Build all documentation, except old docs
5+
all: cli-help file-format examples versions book api
6+
7+
# Build all documentation, including old docs
8+
all_with_old: all old
69

710
# Build book
811
book:
@@ -33,3 +36,15 @@ file-format *ARGS:
3336
examples:
3437
@echo Building docs for examples
3538
@uv run docs/generate_example_docs.py
39+
40+
# Build TOC for old versions
41+
versions:
42+
@echo Building TOC for old versions of documentation
43+
@uv run docs/generate_versions_docs.py
44+
45+
# Build documentation for previous releases
46+
old:
47+
@# Clean output dir
48+
@rm -rf book/release
49+
50+
@uv run docs/build_old_docs.py

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Generated documentation files
22
command_line_help.md
33
examples.md
4+
versions.md

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
- [Release notes](release_notes/README.md)
2424
- [MUSE2 v2.0.0 (October 14, 2025)](release_notes/v2.0.0.md)
2525
- [Next unreleased version](release_notes/upcoming.md)
26+
- [Other versions of documentation](versions.md)

docs/build_old_docs.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env python3
2+
#
3+
# A script to generate documentation for previous releases of MUSE2.
4+
5+
import os
6+
import shutil
7+
import subprocess as sp
8+
from pathlib import Path
9+
from tempfile import TemporaryDirectory
10+
11+
from release import get_releases
12+
13+
DOCS_SITE_ROOT = "https://energysystemsmodellinglab.github.io/MUSE2"
14+
REPO_ROOT = Path(__file__).parent.parent.absolute()
15+
DOCS_DIR = REPO_ROOT / "docs"
16+
17+
18+
def clone_repo_to(dest: Path):
19+
"""Clone this repo somewhere else."""
20+
print("Making a copy of repo")
21+
sp.run(("git", "clone", REPO_ROOT, dest), check=True, capture_output=True)
22+
23+
# Add a symlink to cargo cache dir
24+
try:
25+
os.symlink(REPO_ROOT / "target", dest / "target")
26+
except (NotImplementedError, OSError):
27+
# Only newer versions of Windows support symlinks and these require the user to have
28+
# additional privileges (or to be in developer mode)
29+
print(
30+
"WARN: Could not create symlink to cache directory; cache will not be stored"
31+
)
32+
33+
34+
def apply_patches_for_release(release: str, repo_path: Path) -> None:
35+
"""Apply patches (if any) for the given release."""
36+
patches_dir = DOCS_DIR / "release" / "patches" / release
37+
for patch_path in sorted(patches_dir.glob("*.patch")):
38+
sp.run(("git", "-C", str(repo_path), "am", str(patch_path)), check=True)
39+
40+
41+
def build_docs_for_release(release: str, repo_path: Path, outdir: Path) -> None:
42+
"""Build documentation for a given release."""
43+
print(f"Building docs for {release}")
44+
45+
# Check out release
46+
sp.run(
47+
("git", "-C", str(repo_path), "checkout", release),
48+
check=True,
49+
capture_output=True,
50+
)
51+
52+
# Apply patches, if any
53+
apply_patches_for_release(release, repo_path)
54+
55+
# Build docs
56+
sp.run(("just", f"{repo_path!s}/build-docs"), check=True)
57+
58+
# Patch versions.html to redirect to main versions page
59+
with (repo_path / "book" / "versions.html").open("w", encoding="utf-8") as f:
60+
f.write(f"""<head>
61+
<meta http-equiv="Refresh" content="0; URL={DOCS_SITE_ROOT}/versions.html" />
62+
</head>""")
63+
64+
# Move to output directory
65+
release_outdir = outdir / release
66+
print(f"Copying to {release_outdir}")
67+
shutil.move((repo_path / "book"), release_outdir)
68+
69+
70+
def build_old_docs() -> None:
71+
"""Build documentation for previous releases."""
72+
outdir = REPO_ROOT / "book" / "release"
73+
outdir.mkdir(parents=True, exist_ok=True)
74+
75+
# Clone this repo to a temporary directory
76+
with TemporaryDirectory() as tmpdir:
77+
repo_path = Path(tmpdir)
78+
clone_repo_to(repo_path)
79+
80+
# Generate documentation for each previous release
81+
for release in get_releases():
82+
build_docs_for_release(release, repo_path, outdir)
83+
84+
85+
if __name__ == "__main__":
86+
build_old_docs()

docs/generate_versions_docs.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
# /// script
3+
# dependencies = [
4+
# "jinja2",
5+
# ]
6+
# ///
7+
#
8+
# A script to generate the versions.md file, listing links to old versions of documentation.
9+
10+
from pathlib import Path
11+
12+
from jinja2 import Environment, FileSystemLoader
13+
from release import get_releases
14+
15+
DOCS_DIR = Path(__file__).parent.absolute()
16+
17+
18+
def generate_versions_md() -> None:
19+
"""Write the versions.md file."""
20+
path = DOCS_DIR / "versions.md"
21+
print(f"Writing {path}")
22+
env = Environment(loader=FileSystemLoader(DOCS_DIR / "templates"))
23+
template = env.get_template("versions.md.jinja")
24+
out = template.render(releases=get_releases())
25+
26+
with path.open("w", encoding="utf-8") as f:
27+
f.write(out)
28+
29+
30+
if __name__ == "__main__":
31+
generate_versions_md()

docs/release/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Common functionality for working with different versions."""
2+
3+
import re
4+
import subprocess as sp
5+
6+
7+
def is_release_tag(tag: str) -> bool:
8+
"""Whether the git tag indicates a version.
9+
10+
We don't include pre-releases.
11+
"""
12+
return re.match(r"^v[0-9]+\.[0-9]+\.[0-9]+$", tag) is not None
13+
14+
15+
def get_releases() -> list[str]:
16+
"""Get all release tags for this repo, sorted by semantic version."""
17+
ret = sp.run(
18+
("git", "tag", "-l", "--sort=-version:refname"),
19+
capture_output=True,
20+
check=True,
21+
encoding="utf-8",
22+
)
23+
return [tag for tag in ret.stdout.splitlines() if is_release_tag(tag)]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
From 3129c56aea05dd2b7e88c76bb2050fded0529243 Mon Sep 17 00:00:00 2001
2+
From: Aurash Karimi <a.karimi@imperial.ac.uk>
3+
Date: Wed, 19 Nov 2025 09:48:11 +0000
4+
Subject: [PATCH] remove unrecognised parameter
5+
6+
---
7+
book.toml | 1 -
8+
1 file changed, 1 deletion(-)
9+
10+
diff --git a/book.toml b/book.toml
11+
index 41fba09c..84d181ee 100644
12+
--- a/book.toml
13+
+++ b/book.toml
14+
@@ -1,7 +1,6 @@
15+
[book]
16+
authors = ["Alex Dewar"]
17+
language = "en"
18+
-multilingual = false
19+
src = "docs"
20+
title = "MUSE2"
21+
22+
--
23+
2.53.0

0 commit comments

Comments
 (0)