Skip to content

Commit 1ee986a

Browse files
committed
Add script to update version switcher
1 parent 7816720 commit 1ee986a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

.github/workflows/build_and_deploy.yml

+12
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ jobs:
7676
cd docs
7777
make fallback-videos
7878
79+
- name: Update version switcher (on new release)
80+
if: ((github.event_name == 'release' && !contains(github.event.release.tag_name, 'rc')) || (github.event_name == 'workflow_dispatch' && github.event.inputs.target_directory != 'dev'))
81+
run: |
82+
python docs/_scripts/update_switcher.py ${{ github.event.inputs.target_directory || github.event.release.tag_name }}
83+
84+
- name: Commit new version switcher
85+
run: |
86+
git config --local user.email "[email protected]"
87+
git config --local user.name "GitHub Action"
88+
git add docs/_static/version_switcher.json
89+
git commit -m "Update version switcher for release" --allow-empty
90+
7991
- name: Build Docs
8092
uses: aganders3/headless-gui@v2
8193
env:

docs/_scripts/update_switcher.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import sys
2+
import json
3+
4+
5+
def update_version_switcher(new_version):
6+
"""Update version_switcher.json after a new release."""
7+
with open("docs/_static/version_switcher.json", "r") as f:
8+
switcher = json.load(f)
9+
oldstable = switcher[1]
10+
11+
newstable = oldstable.copy()
12+
newstable["version"] = new_version
13+
newstable["name"] = f"stable ({new_version})"
14+
15+
oldstable["name"] = f"{oldstable['version']}"
16+
del oldstable["preferred"]
17+
oldstable["url"] = oldstable["url"].replace("stable", oldstable["version"])
18+
19+
switcher[1] = oldstable
20+
switcher.insert(1, newstable)
21+
with open("docs/_static/version_switcher.json", "w") as f:
22+
json.dump(switcher, f, indent=4)
23+
24+
print(f"Version switcher updated to {new_version}")
25+
print(f"Old stable version: {switcher[2]}")
26+
print(f"New stable version: {switcher[1]}")
27+
28+
29+
if __name__ == "__main__":
30+
if len(sys.argv) != 2:
31+
print("Usage: python update_switcher.py <new_version>")
32+
sys.exit()
33+
new_version = sys.argv[1]
34+
update_version_switcher(new_version)

0 commit comments

Comments
 (0)