When a new release notes file is created, make sure to run git add <file>

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2023-02-24 13:53:03 +00:00 committed by Pedro Algarvio
parent ff8fa7f9dc
commit b06d28d182

View file

@ -355,9 +355,9 @@ def update_release_notes(
major_version = salt_version 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:])
tmpnotes = f"doc/topics/releases/{salt_version}.md.tmp" release_notes_path = f"doc/topics/releases/{major_version}.md"
try: try:
with open(f"doc/topics/releases/{major_version}.md") as rfp: with open(release_notes_path) as rfp:
existing = rfp.read() existing = rfp.read()
except FileNotFoundError: except FileNotFoundError:
existing = textwrap.dedent( existing = textwrap.dedent(
@ -367,22 +367,26 @@ def update_release_notes(
# 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)
if release is True: if release is True:
existing = existing.replace(" - UNRELEASED", "") existing = existing.replace(" - UNRELEASED", "")
with open(tmpnotes, "w") as wfp:
tmp_release_notes_path = f"{release_notes_path}.tmp"
with open(tmp_release_notes_path, "w") as wfp:
wfp.write(existing) wfp.write(existing)
wfp.write("\n## Changelog\n") wfp.write("\n## Changelog\n")
wfp.write(changes) wfp.write(changes)
try: try:
with open(tmpnotes) as rfp: with open(tmp_release_notes_path) as rfp:
contents = rfp.read().strip() contents = rfp.read().strip()
if draft: if draft:
ctx.print(contents, soft_wrap=True) ctx.print(contents, soft_wrap=True)
else: else:
with open(f"doc/topics/releases/{salt_version}.md", "w") as wfp: with open(release_notes_path, "w") as wfp:
wfp.write(contents) wfp.write(contents)
finally: finally:
os.remove(tmpnotes) os.remove(tmp_release_notes_path)
@changelog.command( @changelog.command(