From 321644f2489cab58a80517d6d1a217cd1a370dd1 Mon Sep 17 00:00:00 2001 From: rettigl Date: Fri, 25 Oct 2024 10:42:24 +0200 Subject: [PATCH] update script to use version from build --- sed/switcher.json | 4 ++-- sed/update_switcher.py | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/sed/switcher.json b/sed/switcher.json index bae5b5e..de2ca12 100644 --- a/sed/switcher.json +++ b/sed/switcher.json @@ -1,7 +1,7 @@ [ { "name": "latest", - "version": "latest", + "version": "0.1.9", "url": "https://opencompes.github.io/docs/sed/latest" }, { @@ -17,7 +17,7 @@ }, { "name": "develop", - "version": "pydata-docs-theme-main", + "version": "v0.1.9", "url": "https://opencompes.github.io/docs/sed/develop" } ] \ No newline at end of file diff --git a/sed/update_switcher.py b/sed/update_switcher.py index dfb3df7..2d72d13 100644 --- a/sed/update_switcher.py +++ b/sed/update_switcher.py @@ -1,38 +1,41 @@ 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) @@ -40,12 +43,12 @@ 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)