Skip to content

Commit 50e535f

Browse files
authored
Update docs build and version selector works as expected (microsoft#2500)
## Update docs build and version selector works as expected This PR fixes documentation version selection by making the Sphinx `version` come from CI (with a sensible local default) and by explicitly marking the “latest” docs entry as preferred so the version switcher behaves correctly on `main`. **Changes:** - Update Sphinx `conf.py` to source the docs version from `OLIVE_DOCS_VERSION` (defaulting to `main` for local/dev builds). - Mark the latest stable version as the preferred target in `versions.json`. - Improve the `update_versions_json.py` script to maintain a single `(latest)` entry, clear stale `preferred` flags, and keep the latest release positioned directly after `dev (main)`. ### Reviewed changes Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments. | File | Description | | ---- | ----------- | | `docs/source/conf.py` | Uses a CI-provided docs version (defaults to `main`) so `version_match` aligns with the built docs branch/version. | | `docs/source/_static/versions.json` | Adds `preferred: true` to the latest stable version to guide the version switcher fallback behavior. | | `.azure_pipelines/scripts/update_versions_json.py` | Ensures `(latest)` naming and `preferred` flag are consistently applied and keeps the latest entry in the expected position. | ## Checklist before requesting a review - [ ] Add unit tests for this change. - [ ] Make sure all tests can pass. - [ ] Update documents if necessary. - [x] Lint and apply fixes to your code by running `lintrunner -a` - [ ] Is this a user-facing change? If yes, give a description of this change to be included in the release notes. ## (Optional) Issue link
1 parent d93067d commit 50e535f

4 files changed

Lines changed: 91 additions & 17 deletions

File tree

.azure_pipelines/scripts/update_versions_json.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,32 @@ def main():
1515
with open(versions_file) as f:
1616
versions = json.load(f)
1717

18-
# Check if version already exists
19-
for v in versions:
20-
if v["version"] == new_version:
21-
return
18+
existing_entry = None
2219

23-
# Remove "(latest)" from all existing versions
20+
# Remove "(latest)" and stale preferred flags from all existing versions.
2421
for v in versions:
2522
if "(latest)" in v["name"]:
2623
v["name"] = v["version"]
27-
28-
# Insert new version after "dev (main)" with (latest) tag
29-
new_entry = {
30-
"name": f"{new_version} (latest)",
31-
"version": new_version,
32-
"url": f"https://microsoft.github.io/Olive/{new_version}/",
33-
}
34-
35-
# Insert after the first entry (dev/main)
36-
versions.insert(1, new_entry)
24+
v.pop("preferred", None)
25+
if v["version"] == new_version:
26+
existing_entry = v
27+
28+
if existing_entry is None:
29+
existing_entry = {
30+
"name": f"{new_version} (latest)",
31+
"version": new_version,
32+
"url": f"https://microsoft.github.io/Olive/{new_version}/",
33+
"preferred": True,
34+
}
35+
# Insert after the first entry (dev/main)
36+
versions.insert(1, existing_entry)
37+
else:
38+
existing_entry["name"] = f"{new_version} (latest)"
39+
existing_entry["url"] = f"https://microsoft.github.io/Olive/{new_version}/"
40+
existing_entry["preferred"] = True
41+
42+
# Keep the latest release directly after the dev/main entry.
43+
versions = [versions[0], existing_entry] + [v for v in versions[1:] if v is not existing_entry]
3744

3845
# Write updated versions.json
3946
with open(versions_file, "w") as f:

.github/workflows/docs.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
python-version: ${{ env.PYTHON_VERSION }}
3636

3737
- name: Build docs
38+
env:
39+
OLIVE_DOCS_VERSION: main
3840
run: |
3941
python -m pip install .
4042
cd docs
@@ -43,3 +45,62 @@ jobs:
4345
make html
4446
make linkcheck
4547
make schema
48+
49+
- name: Upload built docs
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: docs-html
53+
path: docs/build/html
54+
if-no-files-found: error
55+
56+
publish:
57+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
58+
needs: build
59+
runs-on: ubuntu-latest
60+
permissions:
61+
contents: write
62+
63+
steps:
64+
- name: Checkout Code
65+
uses: actions/checkout@v4
66+
with:
67+
fetch-depth: 0
68+
69+
- name: Download built docs
70+
uses: actions/download-artifact@v4
71+
with:
72+
name: docs-html
73+
path: docs-publish
74+
75+
- name: Publish docs to gh-pages root
76+
env:
77+
GH_PAGES_DIR: ../gh-pages-worktree
78+
run: |
79+
set -euxo pipefail
80+
81+
git config user.name "github-actions[bot]"
82+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
83+
git fetch origin gh-pages
84+
rm -rf "$GH_PAGES_DIR"
85+
git worktree add "$GH_PAGES_DIR" origin/gh-pages
86+
87+
cd "$GH_PAGES_DIR"
88+
find . -mindepth 1 -maxdepth 1 \
89+
! -name '.git' \
90+
! -name 'CNAME' \
91+
! -name '.nojekyll' \
92+
! -name '.gitignore' \
93+
! -regex './[0-9]+\.[0-9]+\.[0-9]+' \
94+
-exec rm -rf {} +
95+
96+
cp -a "$GITHUB_WORKSPACE/docs-publish/." .
97+
touch .nojekyll
98+
99+
git add -A
100+
if git diff --cached --quiet; then
101+
echo "No docs changes to publish"
102+
exit 0
103+
fi
104+
105+
git commit -m "Publish docs for ${GITHUB_SHA}"
106+
git push origin HEAD:gh-pages

docs/source/_static/versions.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
[
22
{ "name": "dev (main)", "version": "main", "url": "https://microsoft.github.io/Olive/" },
3-
{ "name": "0.12.1 (latest)", "version": "0.12.1", "url": "https://microsoft.github.io/Olive/0.12.1/" },
3+
{
4+
"name": "0.12.1 (latest)",
5+
"version": "0.12.1",
6+
"url": "https://microsoft.github.io/Olive/0.12.1/",
7+
"preferred": true
8+
},
49
{ "name": "0.12.0", "version": "0.12.0", "url": "https://microsoft.github.io/Olive/0.12.0/" },
510
{ "name": "0.10.1", "version": "0.10.1", "url": "https://microsoft.github.io/Olive/0.10.1/" },
611
{ "name": "0.10.0", "version": "0.10.0", "url": "https://microsoft.github.io/Olive/0.10.0/" },

docs/source/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
project = "Olive"
2121
copyright = "2023-2026, Olive Dev team"
22-
version = "0.12.1"
22+
# The docs version is provided by CI. Default to main for local/dev builds.
23+
version = os.getenv("OLIVE_DOCS_VERSION", "main")
2324
release = version
2425

2526
# -- General configuration ---------------------------------------------------

0 commit comments

Comments
 (0)