Skip to content

Commit

Permalink
Properly handle, and display, errors.
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Algarvio <[email protected]>
  • Loading branch information
s0undt3ch committed Feb 13, 2023
1 parent 2b071a8 commit c28a319
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions tools/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import os
import pathlib
import re
import subprocess
import sys
import textwrap

Expand Down Expand Up @@ -150,13 +149,18 @@ def _get_changelog_contents(ctx: Context, version: str):
"""
Return the full changelog generated by towncrier.
"""
return ctx.run(
ret = ctx.run(
"towncrier",
"build",
"--draft",
f"--version={version}",
capture=True,
).stdout.decode()
check=False,
)
if ret.returncode:
ctx.error(ret.stderr.decode())
ctx.exit(1)
return ret.stdout.decode()


def _get_pkg_changelog_contents(ctx: Context, version: str):
Expand Down Expand Up @@ -218,14 +222,12 @@ def _get_pkg_changelog_contents(ctx: Context, version: str):
return changes


def _get_salt_version():
return (
subprocess.run(
["python3", "salt/version.py"], stdout=subprocess.PIPE, check=True
)
.stdout.decode()
.strip()
)
def _get_salt_version(ctx):
ret = ctx.run("python3", "salt/version.py", capture=True, check=False)
if ret.returncode:
ctx.error(ret.stderr.decode())
ctx.exit(1)
return ret.stdout.decode().strip()


@changelog.command(
Expand All @@ -246,7 +248,7 @@ def _get_salt_version():
)
def update_rpm(ctx: Context, salt_version: str, draft: bool = False):
if salt_version is None:
salt_version = _get_salt_version()
salt_version = _get_salt_version(ctx)
changes = _get_pkg_changelog_contents(ctx, salt_version)
ctx.info("Salt version is %s", salt_version)
orig = ctx.run(
Expand Down Expand Up @@ -296,7 +298,7 @@ def update_rpm(ctx: Context, salt_version: str, draft: bool = False):
)
def update_deb(ctx: Context, salt_version: str, draft: bool = False):
if salt_version is None:
salt_version = _get_salt_version()
salt_version = _get_salt_version(ctx)
changes = _get_pkg_changelog_contents(ctx, salt_version)
formated = "\n".join([f" {_.replace('-', '*', 1)}" for _ in changes.split("\n")])
dt = datetime.datetime.utcnow()
Expand Down Expand Up @@ -339,7 +341,7 @@ def update_deb(ctx: Context, salt_version: str, draft: bool = False):
)
def update_release_notes(ctx: Context, salt_version: str, draft: bool = False):
if salt_version is None:
salt_version = _get_salt_version()
salt_version = _get_salt_version(ctx)
if "+" in salt_version:
major_version = salt_version.split("+", 1)[0]
else:
Expand Down Expand Up @@ -385,7 +387,7 @@ def update_release_notes(ctx: Context, salt_version: str, draft: bool = False):
)
def generate_changelog_md(ctx: Context, salt_version: str, draft: bool = False):
if salt_version is None:
salt_version = _get_salt_version()
salt_version = _get_salt_version(ctx)
cmd = ["towncrier", "build", f"--version={salt_version}"]
if draft:
cmd += ["--draft"]
Expand Down

0 comments on commit c28a319

Please sign in to comment.