mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 01:30:20 +00:00
Additional fixes to tools/changelog.py
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
d5ac32b6f2
commit
84797fe353
1 changed files with 32 additions and 30 deletions
|
@ -14,9 +14,8 @@ import textwrap
|
||||||
|
|
||||||
from ptscripts import Context, command_group
|
from ptscripts import Context, command_group
|
||||||
|
|
||||||
import tools.utils
|
from tools.utils import REPO_ROOT, Version
|
||||||
|
|
||||||
REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent
|
|
||||||
CHANGELOG_LIKE_RE = re.compile(r"([\d]+)\.([a-z]+)$")
|
CHANGELOG_LIKE_RE = re.compile(r"([\d]+)\.([a-z]+)$")
|
||||||
CHANGELOG_TYPES = (
|
CHANGELOG_TYPES = (
|
||||||
"removed",
|
"removed",
|
||||||
|
@ -39,7 +38,7 @@ changelog = command_group(
|
||||||
description=__doc__,
|
description=__doc__,
|
||||||
venv_config={
|
venv_config={
|
||||||
"requirements_files": [
|
"requirements_files": [
|
||||||
tools.utils.REPO_ROOT
|
REPO_ROOT
|
||||||
/ "requirements"
|
/ "requirements"
|
||||||
/ "static"
|
/ "static"
|
||||||
/ "ci"
|
/ "ci"
|
||||||
|
@ -147,7 +146,7 @@ def check_changelog_entries(ctx: Context, files: list[pathlib.Path]):
|
||||||
ctx.exit(exitcode)
|
ctx.exit(exitcode)
|
||||||
|
|
||||||
|
|
||||||
def _get_changelog_contents(ctx: Context, version: str):
|
def _get_changelog_contents(ctx: Context, version: Version):
|
||||||
"""
|
"""
|
||||||
Return the full changelog generated by towncrier.
|
Return the full changelog generated by towncrier.
|
||||||
"""
|
"""
|
||||||
|
@ -165,7 +164,7 @@ def _get_changelog_contents(ctx: Context, version: str):
|
||||||
return ret.stdout.decode()
|
return ret.stdout.decode()
|
||||||
|
|
||||||
|
|
||||||
def _get_pkg_changelog_contents(ctx: Context, version: str):
|
def _get_pkg_changelog_contents(ctx: Context, version: Version):
|
||||||
"""
|
"""
|
||||||
Return a version of the changelog entries suitable for packaged changelogs.
|
Return a version of the changelog entries suitable for packaged changelogs.
|
||||||
"""
|
"""
|
||||||
|
@ -180,7 +179,7 @@ def _get_salt_version(ctx):
|
||||||
if ret.returncode:
|
if ret.returncode:
|
||||||
ctx.error(ret.stderr.decode())
|
ctx.error(ret.stderr.decode())
|
||||||
ctx.exit(1)
|
ctx.exit(1)
|
||||||
return ret.stdout.decode().strip()
|
return Version(ret.stdout.decode().strip())
|
||||||
|
|
||||||
|
|
||||||
@changelog.command(
|
@changelog.command(
|
||||||
|
@ -199,7 +198,7 @@ def _get_salt_version(ctx):
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
def update_rpm(ctx: Context, salt_version: str, draft: bool = False):
|
def update_rpm(ctx: Context, salt_version: Version, draft: bool = False):
|
||||||
if salt_version is None:
|
if salt_version is None:
|
||||||
salt_version = _get_salt_version(ctx)
|
salt_version = _get_salt_version(ctx)
|
||||||
changes = _get_pkg_changelog_contents(ctx, salt_version)
|
changes = _get_pkg_changelog_contents(ctx, salt_version)
|
||||||
|
@ -249,7 +248,7 @@ def update_rpm(ctx: Context, salt_version: str, draft: bool = False):
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
def update_deb(ctx: Context, salt_version: str, draft: bool = False):
|
def update_deb(ctx: Context, salt_version: Version, draft: bool = False):
|
||||||
if salt_version is None:
|
if salt_version is None:
|
||||||
salt_version = _get_salt_version(ctx)
|
salt_version = _get_salt_version(ctx)
|
||||||
changes = _get_pkg_changelog_contents(ctx, salt_version)
|
changes = _get_pkg_changelog_contents(ctx, salt_version)
|
||||||
|
@ -257,23 +256,25 @@ def update_deb(ctx: Context, salt_version: str, draft: bool = False):
|
||||||
dt = datetime.datetime.utcnow()
|
dt = datetime.datetime.utcnow()
|
||||||
date = dt.strftime("%a, %d %b %Y %H:%M:%S +0000")
|
date = dt.strftime("%a, %d %b %Y %H:%M:%S +0000")
|
||||||
tmpchanges = "pkg/rpm/salt.spec.1"
|
tmpchanges = "pkg/rpm/salt.spec.1"
|
||||||
with open(tmpchanges, "w") as wfp:
|
debian_changelog_path = "pkg/debian/changelog"
|
||||||
|
tmp_debian_changelog_path = f"{debian_changelog_path}.1"
|
||||||
|
with open(tmp_debian_changelog_path, "w") as wfp:
|
||||||
wfp.write(f"salt ({salt_version}) stable; urgency=medium\n\n")
|
wfp.write(f"salt ({salt_version}) stable; urgency=medium\n\n")
|
||||||
wfp.write(formated)
|
wfp.write(formated)
|
||||||
wfp.write(
|
wfp.write(
|
||||||
f"\n -- Salt Project Packaging <saltproject-packaging@vmware.com> {date}\n\n"
|
f"\n -- Salt Project Packaging <saltproject-packaging@vmware.com> {date}\n\n"
|
||||||
)
|
)
|
||||||
with open("pkg/debian/changelog") as rfp:
|
with open(debian_changelog_path) as rfp:
|
||||||
wfp.write(rfp.read())
|
wfp.write(rfp.read())
|
||||||
try:
|
try:
|
||||||
with open(tmpchanges) as rfp:
|
with open(tmp_debian_changelog_path) as rfp:
|
||||||
if draft:
|
if draft:
|
||||||
ctx.info(rfp.read())
|
ctx.info(rfp.read())
|
||||||
else:
|
else:
|
||||||
with open("pkg/debian/changelog", "w") as wfp:
|
with open(debian_changelog_path, "w") as wfp:
|
||||||
wfp.write(rfp.read())
|
wfp.write(rfp.read())
|
||||||
finally:
|
finally:
|
||||||
os.remove(tmpchanges)
|
os.remove(tmp_debian_changelog_path)
|
||||||
|
|
||||||
|
|
||||||
@changelog.command(
|
@changelog.command(
|
||||||
|
@ -296,30 +297,31 @@ def update_deb(ctx: Context, salt_version: str, draft: bool = False):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
def update_release_notes(
|
def update_release_notes(
|
||||||
ctx: Context, salt_version: str, draft: bool = False, release: bool = False
|
ctx: Context, salt_version: Version, draft: bool = False, release: bool = False
|
||||||
):
|
):
|
||||||
if salt_version is None:
|
if salt_version is None:
|
||||||
salt_version = _get_salt_version(ctx)
|
salt_version = _get_salt_version(ctx)
|
||||||
if "+" in salt_version:
|
|
||||||
major_version = salt_version.split("+", 1)[0]
|
|
||||||
else:
|
|
||||||
major_version = salt_version
|
|
||||||
changes = _get_changelog_contents(ctx, salt_version)
|
changes = _get_changelog_contents(ctx, salt_version)
|
||||||
changes = "\n".join(changes.split("\n")[2:])
|
changes = "\n".join(changes.split("\n")[2:])
|
||||||
release_notes_path = f"doc/topics/releases/{major_version}.md"
|
release_notes_path = "doc/topics/releases/{}.md".format(
|
||||||
try:
|
".".join(str(part) for part in salt_version.release)
|
||||||
with open(release_notes_path) as rfp:
|
)
|
||||||
existing = rfp.read()
|
if not os.path.exists(release_notes_path):
|
||||||
except FileNotFoundError:
|
pathlib.Path(release_notes_path).write_text(
|
||||||
existing = textwrap.dedent(
|
textwrap.dedent(
|
||||||
f"""\
|
f"""\
|
||||||
[](#release-{salt_version})
|
[](#release-{salt_version})
|
||||||
|
|
||||||
# Salt {salt_version} release notes - UNRELEASED
|
# Salt {salt_version} release notes - UNRELEASED
|
||||||
"""
|
"""
|
||||||
|
)
|
||||||
)
|
)
|
||||||
pathlib.Path(release_notes_path).touch()
|
|
||||||
ctx.run("git", "add", release_notes_path)
|
ctx.run("git", "add", release_notes_path)
|
||||||
|
ctx.info(f"Created bare {release_notes_path} release notes file")
|
||||||
|
|
||||||
|
with open(release_notes_path) as rfp:
|
||||||
|
existing = rfp.read()
|
||||||
|
|
||||||
if release is True:
|
if release is True:
|
||||||
existing = existing.replace(" - UNRELEASED", "")
|
existing = existing.replace(" - UNRELEASED", "")
|
||||||
|
|
||||||
|
@ -356,7 +358,7 @@ def update_release_notes(
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
def generate_changelog_md(ctx: Context, salt_version: str, draft: bool = False):
|
def generate_changelog_md(ctx: Context, salt_version: Version, draft: bool = False):
|
||||||
if salt_version is None:
|
if salt_version is None:
|
||||||
salt_version = _get_salt_version(ctx)
|
salt_version = _get_salt_version(ctx)
|
||||||
cmd = ["towncrier", "build", f"--version={salt_version}"]
|
cmd = ["towncrier", "build", f"--version={salt_version}"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue