| | import re |
| | import sys |
| | import argparse |
| |
|
| | from readme_api import get_versions, create_new_unstable |
| |
|
| |
|
| | VERSION_VALIDATOR = re.compile(r"^[0-9]+\.[0-9]+$") |
| |
|
| |
|
| | def calculate_new_unstable(version: str): |
| | |
| | major, minor = version.split(".") |
| | return f"{major}.{int(minor) + 1}-unstable" |
| |
|
| |
|
| | if __name__ == "__main__": |
| | parser = argparse.ArgumentParser() |
| | parser.add_argument( |
| | "-v", "--new-version", help="The new unstable version that is being created (e.g. 1.9).", required=True |
| | ) |
| | args = parser.parse_args() |
| |
|
| | if VERSION_VALIDATOR.match(args.new_version) is None: |
| | sys.exit("Version must be formatted like so <major>.<minor>") |
| |
|
| | |
| | new_stable = f"{args.new_version}" |
| | new_unstable = calculate_new_unstable(args.new_version) |
| |
|
| | versions = get_versions() |
| | new_stable_is_published = new_stable in versions |
| | new_unstable_is_published = new_unstable in versions |
| |
|
| | if new_stable_is_published and new_unstable_is_published: |
| | |
| | |
| | print(f"Both new version {new_stable} and {new_unstable} are already published.") |
| | sys.exit(0) |
| | elif new_stable_is_published or new_unstable_is_published: |
| | |
| | |
| | sys.exit(f"Either version {new_stable} or {new_unstable} are already published. Too risky to proceed.") |
| |
|
| | |
| | |
| | current_unstable = f"{new_stable}-unstable" |
| |
|
| | if current_unstable not in versions: |
| | sys.exit(f"Can't find version {current_unstable} to promote to {new_stable}") |
| |
|
| | |
| | |
| | create_new_unstable(current_unstable, new_unstable) |
| |
|