-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically create docs PR on release (#1965)
* Adding auto switcher bump, sending main branch docs to dev * Use auto commit action to push switcher.json updates * Adding switcher update script * Using custom commit message * Point latest to actually latest version * Use PR instead of directly pushing to main * Refine comment * Use auto-commits * Remove unused permissions * Remove obsolete token * Setup permission, only run on release * Create PR with updated switcher.json * Format with stock black * Update .github/workflows/deploy-docs.yml * Update .github/workflows/deploy-docs.yml --------- Co-authored-by: Frank Anema <33519926+Conengmo@users.noreply.github.com>
- Loading branch information
1 parent
2921126
commit 68f119c
Showing
4 changed files
with
87 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
This script is used to update switcher.json on docs releases. It adds the new version to | ||
the list of versions and sets the latest version to the new version. | ||
""" | ||
|
||
import argparse | ||
import json | ||
import os | ||
|
||
|
||
def main(): | ||
# Define CLI arguments | ||
parser = argparse.ArgumentParser(description="Update switcher.json") | ||
parser.add_argument( | ||
"--version", "-v", required=True, type=str, help="The new version to add" | ||
) | ||
args = parser.parse_args() | ||
|
||
# Setup path to switcher.json (relative to this script) and load it | ||
switcher_path = os.path.join(os.path.dirname(__file__), "_static", "switcher.json") | ||
with open(switcher_path) as f: | ||
switcher = json.load(f) | ||
|
||
# Find index of 'latest' entry | ||
latest_index = None | ||
for i, version in enumerate(switcher): | ||
if version["version"] == "latest": | ||
latest_index = i | ||
break | ||
if latest_index is None: | ||
raise ValueError("'latest' version not found in switcher.json") | ||
|
||
# Add the new version to the list of versions (we always insert it after latest) | ||
new_version = { | ||
"version": args.version, | ||
"url": f"https://python-visualization.github.io/folium/{args.version}/", | ||
} | ||
|
||
# Update the latest version | ||
switcher[latest_index]["url"] = new_version["url"] | ||
|
||
# Make sure version is unique | ||
if any(version["version"] == args.version for version in switcher): | ||
print( | ||
f"Version {args.version} already exists in switcher.json. Not adding it again." | ||
) | ||
else: | ||
switcher.insert(latest_index + 1, new_version) | ||
|
||
# Write the updated switcher.json | ||
with open(switcher_path, "w") as f: | ||
json.dump(switcher, f, indent=2) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |