@@ -199,25 +199,41 @@ jobs:
199199 git clone --depth=1 [email protected] :amaranth-lang/amaranth-lang.github.io.git ~/amaranth-lang.github.io 200200 cd ~/amaranth-lang.github.io/docs/amaranth/
201201
202- (
203- venv_path=$(mktemp -d)
202+ venv_path=~/.generate-versions-json-venv
204203 python3 -m venv "$venv_path"
205204 source "$venv_path"/bin/activate
206205 pip install packaging
207- python >versions.json <<EOF
206+
207+ python <<EOF
208+ import re
208209 import json
209210 from pathlib import Path
210211 from packaging.version import Version
211212
212- versions = Path('.').glob('v*')
213- versions = (path.name[1:] for path in versions if path.is_dir())
214- versions = sorted(versions, key=Version, reverse=True)
215- versions = ({"name": version, "root_url": f"/docs/amaranth/v{version}/"} for version in versions)
216- print(json.dumps(list(versions), indent=2))
213+ versions = []
214+ for version_dir in [Path("latest"), *Path(".").glob("v*")]:
215+ if not version_dir.is_dir():
216+ continue
217+ with open(version_dir / "_static" / "documentation_options.js", "r") as f:
218+ doc_options = f.read()
219+ match = re.search(r"""VERSION:\s+(['"])(.+?)\1""", doc_options)
220+ if match is None:
221+ continue
222+ versions.append({
223+ "name": match.group(2),
224+ "root_url": f"/docs/amaranth/{version_dir.name}/",
225+ })
226+
227+ versions.sort(key=lambda x: Version(x["name"]), reverse=True)
228+
229+ if len(versions) > 0:
230+ with open("versions.json", "w") as f:
231+ json.dump(versions, f, indent=2)
232+ else:
233+ Path("versions.json").unlink()
217234 EOF
218- )
219235
220- git add versions.json
236+ [[ -f versions.json ]] && git add versions.json || git rm versions.json || true
221237 if ! git diff-index --quiet --cached HEAD; then
222238 git \
223239 -c user.name="$GITHUB_ACTOR" \
0 commit comments