Skip to content

Commit

Permalink
Add script to update version switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
melissawm committed Oct 22, 2024
1 parent 7816720 commit dfb87f5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ jobs:
cd docs
make fallback-videos
- name: Update version switcher (on new tag)
if: ((github.event_name == 'release' && !contains(github.event.release.tag_name, 'rc')) || (github.event_name == 'workflow_dispatch' && github.event.inputs.target_directory != 'dev'))
run: |
python docs/_scripts/update_switcher.py ${{ github.event.inputs.target_directory || github.event.release.tag_name }}
- name: Build Docs
uses: aganders3/headless-gui@v2
env:
Expand Down
34 changes: 34 additions & 0 deletions docs/_scripts/update_switcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
import json


def update_version_switcher(new_version):
"""Update version_switcher.json after a new release."""
with open("docs/_static/version_switcher.json", "r") as f:
switcher = json.load(f)
oldstable = switcher[1]

newstable = oldstable.copy()
newstable["version"] = new_version
newstable["name"] = f"stable ({new_version})"

oldstable["name"] = f"{oldstable['version']}"
del oldstable["preferred"]
oldstable["url"] = oldstable["url"].replace("stable", oldstable["version"])

switcher[1] = oldstable
switcher.insert(1, newstable)
with open("docs/_static/version_switcher.json", "w") as f:
json.dump(switcher, f, indent=4)

print(f"Version switcher updated to {new_version}")
print(f"Old stable version: {switcher[2]}")
print(f"New stable version: {switcher[1]}")


if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python update_switcher.py <new_version>")
sys.exit()
new_version = sys.argv[1]
update_version_switcher(new_version)

0 comments on commit dfb87f5

Please sign in to comment.