mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 01:30:20 +00:00
Properly handle, and display, errors.
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
a749ec551a
commit
7552662156
1 changed files with 17 additions and 15 deletions
|
@ -9,7 +9,6 @@ import logging
|
|||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
|
@ -152,13 +151,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):
|
||||
|
@ -220,14 +224,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(
|
||||
|
@ -248,7 +250,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(
|
||||
|
@ -298,7 +300,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()
|
||||
|
@ -341,7 +343,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:
|
||||
|
@ -388,7 +390,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"]
|
||||
|
|
Loading…
Add table
Reference in a new issue