File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 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+ cd docs
83+ python docs/_scripts/update_switcher.py ${{ github.event.inputs.target_directory || github.event.release.tag_name }}
84+ git config --local user.email "action@github.com"
85+ git config --local user.name "GitHub Action"
86+ git add docs/_static/version_switcher.json
87+ git commit -m "Update version switcher for release" --allow-empty
88+
7989 - name : Build Docs
8090 uses : aganders3/headless-gui@v2
8191 env :
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments