Skip to content

Commit

Permalink
update script to use version from build
Browse files Browse the repository at this point in the history
  • Loading branch information
rettigl committed Oct 25, 2024
1 parent f18130b commit 321644f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions sed/switcher.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"name": "latest",
"version": "latest",
"version": "0.1.9",
"url": "https://opencompes.github.io/docs/sed/latest"
},
{
Expand All @@ -17,7 +17,7 @@
},
{
"name": "develop",
"version": "pydata-docs-theme-main",
"version": "v0.1.9",
"url": "https://opencompes.github.io/docs/sed/develop"
}
]
25 changes: 14 additions & 11 deletions sed/update_switcher.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
import json
import sys

if len(sys.argv) != 3:
sys.exit("Usage: update_switcher.py json_file GITHUB_REF")
if len(sys.argv) != 4:
sys.exit("Usage: update_switcher.py json_file GITHUB_REF VERSION")

switcher_file = sys.argv[1]
branch = sys.argv[2]
version = sys.argv[3]

present = False
with open(switcher_file, encoding="utf-8") as f:
data = json.load(f)
if branch.startswith("refs/tags"): # add a new version tag
version = branch.split("/")[-1]
version_tag = branch.split("/")[-1]
for item in data:
if version in item.get("name", ""):
if version_tag in item.get("name", ""):
present = True
if "stable" in item.get("name", ""):
item["version"] = version[1:]
item["url"] = "https://opencompes.github.io/docs/sed/" + version
item["version"] = version
item["url"] = "https://opencompes.github.io/docs/sed/" + version_tag
if not present:
new_entry = {}
new_entry["name"] = version
new_entry["version"] = version[1:]
new_entry["url"] = "https://opencompes.github.io/docs/sed/" + version
new_entry["name"] = version_tag
new_entry["version"] = version
new_entry["url"] = "https://opencompes.github.io/docs/sed/" + version_tag
data.append(new_entry)

elif branch == "refs/heads/main": # update latest
for item in data:
if "latest" in item.get("name", ""):
item["version"] = version
present = True
break
if not present:
new_entry = {}
new_entry["name"] = "latest"
new_entry["version"] = version
new_entry["url"] = "https://opencompes.github.io/docs/sed/latest"
data.append(new_entry)

else: # update develop
for item in data:
if "develop" in item.get("name", ""):
present = True
item["version"] = branch.split("/")[-1]
item["version"] = version
break
if not present:
new_entry = {}
new_entry["name"] = "develop"
new_entry["version"] = branch.split("/")[-1]
new_entry["version"] = version
new_entry["url"] = "https://opencompes.github.io/docs/sed/develop"
data.append(new_entry)

Expand Down

0 comments on commit 321644f

Please sign in to comment.