Browse Source

the command 'sg_mbp_build' now creates and copies a release message for dev builds

master
Holger Frey 2 years ago
parent
commit
d28e5ab7e3
  1. 67
      work_helpers/sg_mbp_build.py

67
work_helpers/sg_mbp_build.py

@ -1,5 +1,6 @@
import click import click
import shutil import shutil
import pyperclip
from pathlib import Path from pathlib import Path
from datetime import datetime from datetime import datetime
@ -104,10 +105,12 @@ def create_changelog_entry(new_version, parent=PATH_ISSUES):
with changelog.open("w") as fh: with changelog.open("w") as fh:
fh.write(CRLF.join(content)) fh.write(CRLF.join(content))
def get_changelog_path():
textfiles = _files_in_folder(PATH_ISSUES, ".txt")
return next(f for f in textfiles if f.stem.lower().startswith("change"))
def copy_changelog(destination, build_version): def copy_changelog(destination, build_version):
textfiles = _files_in_folder(PATH_ISSUES, ".txt") changelog = get_changelog_path()
changelog = next(f for f in textfiles if f.stem.lower().startswith("change"))
new_path = destination / f"CHANGELOG {build_version}.txt" new_path = destination / f"CHANGELOG {build_version}.txt"
print(changelog.name, "->", new_path) print(changelog.name, "->", new_path)
shutil.copyfile(changelog, new_path) shutil.copyfile(changelog, new_path)
@ -134,16 +137,70 @@ def copy_workbooks(destination, build_version):
shutil.copyfile(excel_file, new_path) shutil.copyfile(excel_file, new_path)
def collect_current_frms(build_version):
all_folders = (f for f in PATH_WORKBOOKS.iterdir() if f.is_dir())
all_frms = (f for f in all_folders if "frm" in f.name.lower())
return [f for f in all_frms if f.name.endswith(build_version)]
def copy_frms(destination, build_version): def copy_frms(destination, build_version):
all_folders = (f for f in PATH_WORKBOOKS.iterdir() if f.is_dir()) all_folders = (f for f in PATH_WORKBOOKS.iterdir() if f.is_dir())
all_frms = (f for f in all_folders if "frm" in f.name.lower()) all_frms = (f for f in all_folders if "frm" in f.name.lower())
current_frms = (f for f in all_frms if f.name.endswith(build_version)) current_frms = collect_current_frms(build_version)
for folder in current_frms: for folder in current_frms:
new_path = destination / folder.name new_path = destination / folder.name
print(folder.name, "->", new_path) print(folder.name, "->", new_path)
shutil.copytree(folder, new_path) shutil.copytree(folder, new_path)
def get_issue_numbers(build_version):
for path in collect_current_frms(build_version):
rest, issue_info = path.name.lower().split("issue")
issue, *rest = issue_info.strip().split()
yield issue.strip(" ,")
def extract_changes_from_log(build_version):
issue_numbers = set(get_issue_numbers(build_version))
changelog = get_changelog_path()
for line in changelog.read_text().splitlines():
for issue in issue_numbers:
if issue in line:
yield line
def get_announcement_text(dev_version, build_version, new_folder_name):
if not dev_version:
return "This is an official release, the message must be hand crafted"
latest = get_latest_version()
changes = list(extract_changes_from_log(build_version))
if len(changes) == 1:
change_msg = "Only one change was introduced:"
else:
change_msg = "The changes made:"
text = [
f"# New MBP Workbook Version {build_version}",
"Good News Everyone,",
f"there is a new workbook version available: {build_version}",
(
f"As indicated by the letter '{dev_version}' at the end,"
" this version is intended for Freiburg only."
),
change_msg,
"\n".join(changes),
"You can find this version at our Freiburg Shared Drive:",
(
"Google Drive / Shared drives / Freiburg / Workbooks / MBP Workbooks /"
f" {latest} /"
f" {new_folder_name}"
),
"Cheers,\nHolgi"
]
return "\n\n".join(text)
@click.command() @click.command()
@click.option( @click.option(
"-v", "-v",
@ -199,3 +256,7 @@ def sg_mbp_build(dev_version):
copy_workbook_changelogs(new_folder_path, latest, build_version) copy_workbook_changelogs(new_folder_path, latest, build_version)
copy_changelog(new_folder_path, build_version) copy_changelog(new_folder_path, build_version)
copy_frms(new_folder_path, build_version) copy_frms(new_folder_path, build_version)
announcement = get_announcement_text(dev_version, build_version, new_folder_name)
pyperclip.copy(announcement)
print(announcement)
Loading…
Cancel
Save