@@ -46,36 +46,103 @@ jobs:
4646 - name : Install docs dependencies
4747 run : pip install -r docs/requirements.txt
4848
49- - name : Copy example notebooks
50- run : python docs/copy_notebooks.py
51-
5249 - name : Build versioned documentation
53- run : sphinx-multiversion docs docs/_build/html
54-
55- - name : Create root redirect
5650 run : |
57- # Find the latest tag that matches our whitelist, fall back to main
58- LATEST_TAG=$(git tag --sort=-v:refname | grep -E '^v0\.4\.([1-9][0-9]*)$|^v0\.([5-9]|[0-9]{2,})\.[0-9]+$|^v[1-9][0-9]*\.[0-9]+\.[0-9]+$' | head -1)
51+ set -e
52+ OUTPUT_DIR="docs/_build/html"
53+ mkdir -p "$OUTPUT_DIR"
54+
55+ # Tag regex: match v0.4.1+ and v1.0.0+ (v0.4.0 and earlier lack docs/)
56+ TAG_REGEX='^v0\.4\.([1-9][0-9]*)$|^v0\.([5-9]|[0-9]{2,})\.[0-9]+$|^v[1-9][0-9]*\.[0-9]+\.[0-9]+$'
57+
58+ # Collect matching tags (newest first)
59+ TAGS=$(git tag --sort=-v:refname | grep -E "$TAG_REGEX" || true)
60+
61+ # Track versions for versions.json
62+ VERSIONS_JSON='[]'
63+ LATEST_TAG=""
64+
65+ # Build docs for each matching tag
66+ for tag in $TAGS; do
67+ echo "=== Building docs for tag: $tag ==="
68+ # Check if this tag has a docs/ directory
69+ if ! git ls-tree --name-only "$tag" -- docs/ > /dev/null 2>&1; then
70+ echo " Skipping $tag (no docs/ directory)"
71+ continue
72+ fi
73+
74+ git checkout "$tag" -- docs/ examples/ || git checkout "$tag" -- docs/
75+ python docs/copy_notebooks.py || true
76+ sphinx-build -b html docs "$OUTPUT_DIR/$tag"
77+ git checkout HEAD -- docs/ examples/ 2>/dev/null || git checkout HEAD -- docs/
78+
79+ if [ -z "$LATEST_TAG" ]; then
80+ LATEST_TAG="$tag"
81+ fi
82+ VERSIONS_JSON=$(echo "$VERSIONS_JSON" | python3 -c "
83+ import json, sys
84+ v = json.load(sys.stdin)
85+ v.append({'name': '$tag', 'tag': True})
86+ print(json.dumps(v))")
87+ done
88+
89+ # Build docs for main (current HEAD)
90+ echo "=== Building docs for main ==="
91+ git checkout HEAD -- docs/ examples/ 2>/dev/null || true
92+ python docs/copy_notebooks.py
93+ sphinx-build -b html docs "$OUTPUT_DIR/main"
94+
95+ VERSIONS_JSON=$(echo "$VERSIONS_JSON" | python3 -c "
96+ import json, sys
97+ v = json.load(sys.stdin)
98+ v.append({'name': 'main', 'tag': False})
99+ print(json.dumps(v))")
100+
101+ # Determine redirect target
59102 TARGET="${LATEST_TAG:-main}"
60- cat > docs/_build/html/index.html << 'REDIRECT_EOF'
103+
104+ # Write versions.json
105+ python3 -c "
106+ import json
107+ versions = json.loads('$VERSIONS_JSON')
108+ data = {'versions': versions, 'latest': '${LATEST_TAG}', 'current': ''}
109+ with open('$OUTPUT_DIR/versions.json', 'w') as f:
110+ json.dump(data, f, indent=2)
111+ "
112+
113+ # Inject current version into each build's versions.json copy
114+ for dir in "$OUTPUT_DIR"/*/; do
115+ name=$(basename "$dir")
116+ cp "$OUTPUT_DIR/versions.json" "$dir/versions.json"
117+ python3 -c "
118+ import json
119+ with open('$dir/versions.json') as f:
120+ data = json.load(f)
121+ data['current'] = '$name'
122+ with open('$dir/versions.json', 'w') as f:
123+ json.dump(data, f, indent=2)
124+ "
125+ done
126+
127+ # Create root redirect
128+ cat > "$OUTPUT_DIR/index.html" << REDIRECT_EOF
61129 <!DOCTYPE html>
62130 <html>
63131 <head>
64132 <meta charset="utf-8">
65133 <title>Redirecting...</title>
66- <script>
67- // Redirect to latest tagged version, or main if none exist
68- var defined_target = "DEFINED_TARGET_PLACEHOLDER";
69- window.location.href = defined_target + "/index.html";
70- </script>
71- <meta http-equiv="refresh" content="0; url=DEFINED_TARGET_PLACEHOLDER/index.html">
134+ <meta http-equiv="refresh" content="0; url=${TARGET}/index.html">
72135 </head>
73136 <body>
74- <p>Redirecting to <a href="DEFINED_TARGET_PLACEHOLDER /index.html">latest documentation</a>...</p>
137+ <p>Redirecting to <a href="${TARGET} /index.html">latest documentation</a>...</p>
75138 </body>
76139 </html>
77140 REDIRECT_EOF
78- sed -i "s|DEFINED_TARGET_PLACEHOLDER|${TARGET}|g" docs/_build/html/index.html
141+
142+ echo "=== Build complete ==="
143+ echo "Versions built:"
144+ ls -d "$OUTPUT_DIR"/*/
145+ echo "Root redirects to: $TARGET"
79146
80147 - name : Upload artifact
81148 uses : actions/upload-pages-artifact@v3
0 commit comments