Skip to content

Commit

Permalink
feat: scripted version bumping
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhiljha committed Mar 17, 2024
1 parent 7794d6b commit 2955507
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
15 changes: 13 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ loguru = "^0.7.2"
pydantic = "^1.9.0"
hvac = "^1.0.2"
requests = "^2.28.2"
tomlkit = "^0.12.4"

[tool.poetry.group.dev.dependencies]
mypy = "^1.2.0"
Expand Down
3 changes: 2 additions & 1 deletion transpire/internal/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import click

from . import bootstrap, dev, image, obj, secrets, utils
from . import bootstrap, dev, image, obj, secrets, utils, versions

@click.command(cls=utils.AliasedGroup)
def cli() -> None:
Expand All @@ -12,3 +12,4 @@ def cli() -> None:
cli.add_command(obj.commands, "object")
cli.add_command(image.commands, "image")
cli.add_command(secrets.commands, "secret")
cli.add_command(versions.commands, "versions")
41 changes: 41 additions & 0 deletions transpire/internal/cli/versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import click
import tomlkit

from transpire.internal.cli.utils import AliasedGroup
from transpire.internal import helm
from loguru import logger


@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())

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
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}"
)

if len(latest_version_list) != 1:
raise ValueError(f"expected 1 result, got {len(latest_version_list)}")
latest_version = latest_version_list[0]["version"]

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))

doc[app_name]["version"]
7 changes: 7 additions & 0 deletions transpire/internal/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ def update_repo(name: str) -> None:
exec_helm(["repo", "update", name], check=False)


def search_repo(query: str) -> list[dict]:
"""search a repository for a chart"""

assert_helm()
stdout, _ = exec_helm(["search", "repo", query, "--output", "yaml"], check=True)
return yaml.safe_load(stdout)

def build_chart(
repo_url: str,
chart_name: str,
Expand Down

0 comments on commit 2955507

Please sign in to comment.