feat: add release notes to the upgrade command

This commit is contained in:
2024-05-22 10:18:56 +02:00
parent 4caa51b32e
commit 01dbe2221d

View File

@ -328,8 +328,10 @@ def abra(*args: str, machine_output: bool = False, ignore_error: bool = False) -
command.append("-m")
logging.debug(f"run command: {' '.join(command)}")
process = subprocess.run(command, capture_output=True)
if process.stderr:
if process.stderr and not ignore_error:
logging.warning(process.stderr.decode())
elif process.stderr:
logging.debug(process.stderr.decode())
if process.stdout:
logging.debug(process.stdout.decode())
if process.returncode and not ignore_error:
@ -902,6 +904,7 @@ def upgrade(apps: List[str], run_cmds: bool, dry_run: bool) -> None:
"""
deployed_instance_apps = get_apps_by_deployment(apps, deployed=True)
upgrade_cmds = []
release_notes = {}
for instance, deployed_apps in deployed_instance_apps.items():
upgrade_apps = []
for app_details in deployed_apps:
@ -928,8 +931,17 @@ def upgrade(apps: List[str], run_cmds: bool, dry_run: bool) -> None:
upgrade_apps.append(app_details)
logging.info(f'upgrade {app}: {domain} from version {deployed_version} to version "{upgrade_version}"')
upgrade_cmds.append((app_config, cmd))
release_note_cmd = cmd.copy()
release_note_cmd.insert(1, '-r')
release_note = abra("app", *release_note_cmd, ignore_error=True)
if (note:= release_notes.get(app)) and len(note) <= len(release_note):
release_notes[app] = release_note
deployed_instance_apps[instance] = upgrade_apps
print_all_apps(deployed_instance_apps)
input("Press any key to show release notes.")
for app, note in release_notes.items():
print(app)
print(note)
if not dry_run and input(f"Do you really want to upgrade these apps? Type YES: ") == "YES":
for app_config, cmd in upgrade_cmds:
print(abra("app", *cmd))
@ -1131,11 +1143,12 @@ def get_latest_version(app: str) -> str:
Args:
app (str): Name of the application.
Returns:
str: The newest version of the application as a string.
str: The latest version of the application as a string.
"""
versions = abra('recipe', 'versions', app, machine_output=True)
newest = str(sorted([version.parse(v['version']) for v in versions])[-1])
return newest
latest = sorted([(version.parse(v['version']), v['version']) for v in versions])[-1][1]
logging.debug(f'latest version of {app}: {latest}')
return latest
@cli.command()
@click.option('-a', '--apps', multiple=True)