Skip to content

Commit

Permalink
feat: check all updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhiljha committed Mar 17, 2024
1 parent 2955507 commit 7e10879
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions transpire/internal/cli/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@
from transpire.internal import helm
from loguru import logger

from transpire.internal.config import ClusterConfig

@click.command(cls=AliasedGroup)
def commands(**_):
"""version management commands"""
pass


@commands.command()
@click.option("-f", "--file")
@click.argument("app_name", required=True)
def update(app_name: str, file: str, **_) -> None:
"""update to the newest version of a given app"""
doc = tomlkit.parse(open(file).read())

def get_latest_version(doc, app_name: str):
if "helm" in doc[app_name]:
helm.add_repo(app_name, doc[app_name]["helm"])
helm.update_repo(app_name)
chart_name = doc[app_name]["chart"] or app_name
chart_name = doc[app_name]["chart"] if "chart" in doc[app_name] else app_name
search_results = helm.search_repo(chart_name)
latest_version_list = list(
x for x in search_results if x["name"] == f"{app_name}/{chart_name}"
Expand All @@ -31,11 +25,34 @@ def update(app_name: str, file: str, **_) -> None:
if len(latest_version_list) != 1:
raise ValueError(f"expected 1 result, got {len(latest_version_list)}")
latest_version = latest_version_list[0]["version"]
return latest_version
return None

@commands.command()
@click.option("-f", "--file")
@click.argument("app_name", required=True)
def update(app_name: str, file: str, **_) -> None:
"""update to the newest version of a given app"""
doc = tomlkit.parse(open(file).read())
latest_version = get_latest_version(doc, app_name)

if latest_version != None and latest_version != doc[app_name]["version"]:
logger.info(f"updating {app_name} from {doc[app_name]['version']} to {latest_version}")
doc[app_name]["version"] = latest_version
with open(file, "w") as f:
f.write(tomlkit.dumps(doc))

@commands.command()
@click.argument("file", required=True)
def all_updates(file: str, **_) -> None:
"""list all available updates"""
doc = tomlkit.parse(open(file).read())

if latest_version != doc[app_name]["version"]:
logger.info(f"updating {app_name} from {doc[app_name]['version']} to {latest_version}")
doc[app_name]["version"] = latest_version
with open(file, "w") as f:
f.write(tomlkit.dumps(doc))
config = ClusterConfig.from_cwd()
for name, _ in config.modules.items():
if name not in doc:
continue
latest_version = get_latest_version(doc, name)

doc[app_name]["version"]
if latest_version != doc[name]["version"]:
logger.info(f"{name} can be updated from {doc[name]['version']} to {latest_version}")

0 comments on commit 7e10879

Please sign in to comment.