From 8869b16c83b6bbd29f95b89727c21c337e34e5d4 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Tue, 11 Jun 2024 16:59:24 +0200 Subject: [PATCH] chore: generate-changelog.py adjustments - add T3T1 to the list of core hardware - add flag for regenerating model-specific changelogs in case the main one is manually edited - generate headings in the same format as currently used in core/CHANGELOG.md --- core/towncrier.toml | 44 ++++++++++++++++++++++++++++++++++++- tools/generate-changelog.py | 35 +++++++++++++++++++---------- tools/towncrier.toml | 3 +++ 3 files changed, 69 insertions(+), 13 deletions(-) mode change 120000 => 100644 core/towncrier.toml diff --git a/core/towncrier.toml b/core/towncrier.toml deleted file mode 120000 index 489bc47ac..000000000 --- a/core/towncrier.toml +++ /dev/null @@ -1 +0,0 @@ -../tools/towncrier.toml \ No newline at end of file diff --git a/core/towncrier.toml b/core/towncrier.toml new file mode 100644 index 000000000..0ab83a577 --- /dev/null +++ b/core/towncrier.toml @@ -0,0 +1,43 @@ +[tool.towncrier] +directory = ".changelog.d" +filename = "CHANGELOG.md" +template = ".towncrier.template.md" +start_string = "The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)." +title_format = "\n## [{version}] ({project_date})" +issue_format = "[#{issue}]" +underlines = ["", ""] + +[[tool.towncrier.type]] +directory = "added" +name = "Added" +showcontent = true + +[[tool.towncrier.type]] +directory = "changed" +name = "Changed" +showcontent = true + +[[tool.towncrier.type]] +directory = "deprecated" +name = "Deprecated" +showcontent = true + +[[tool.towncrier.type]] +directory = "removed" +name = "Removed" +showcontent = true + +[[tool.towncrier.type]] +directory = "fixed" +name = "Fixed" +showcontent = true + +[[tool.towncrier.type]] +directory = "security" +name = "Security" +showcontent = true + +[[tool.towncrier.type]] +directory = "incompatible" +name = "Incompatible changes" +showcontent = true diff --git a/tools/generate-changelog.py b/tools/generate-changelog.py index 4522194c2..4c4d506fb 100755 --- a/tools/generate-changelog.py +++ b/tools/generate-changelog.py @@ -18,7 +18,7 @@ INTERNAL_MODELS = ("T2T1", "T2B1", "T3T1", "D001") INTERNAL_MODELS_SKIP = ("D001",) -def linkify_changelog(changelog_file, only_check=False): +def linkify_changelog(changelog_file: Path, only_check: bool = False) -> bool: links = {} orig_links = {} result_lines = [] @@ -54,7 +54,7 @@ def linkify_changelog(changelog_file, only_check=False): return True -def linkify_gh_diff(changelog_file, tag_prefix): +def linkify_gh_diff(changelog_file: Path, tag_prefix: str): linkified = False versions = [] result_lines = [] @@ -79,7 +79,7 @@ def linkify_gh_diff(changelog_file, tag_prefix): linkified = True -def current_date(project): +def current_date(project: Path) -> str: parts = project.parts today = datetime.datetime.now() @@ -98,8 +98,8 @@ def current_date(project): return today.strftime(f"%-d{daysuffix} %B %Y") -def filter_changelog(changelog_file, internal_name): - def filter_line(line): +def filter_changelog(changelog_file: Path, internal_name: str): + def filter_line(line: str) -> str | None: m = MODELS_RE.search(line) if not m: return line @@ -116,6 +116,16 @@ def filter_changelog(changelog_file, internal_name): destination.write(res) +def generate_filtered(project: Path, changelog: Path): + if project.parts[-1] != "core": + return + + for internal_name in INTERNAL_MODELS: + if internal_name in INTERNAL_MODELS_SKIP: + continue + filter_changelog(changelog, internal_name) + + @click.command() @click.argument( "project", @@ -130,7 +140,8 @@ def filter_changelog(changelog_file, internal_name): @click.option( "--check", is_flag=True, help="Dry run, do not actually create changelog." ) -def cli(project, version, date, check): +@click.option("--only-models", is_flag=True, help="Only regenerate the model-changelogs from the main one.") +def cli(project, version, date, check, only_models): """Generate changelog for given project (core, python, legacy/firmware, legacy/bootloader). @@ -148,13 +159,17 @@ def cli(project, version, date, check): raise click.ClickException(f"{changelog} not found") if version is None: - if not check: + if not check and not only_models: raise click.ClickException("Version argument is required.") version = "unreleased" if date is None: date = current_date(project) + if only_models: + generate_filtered(project, changelog) + return 0 + args = ["towncrier", "build", "--yes", "--version", version, "--date", date] if check: args.append("--draft") @@ -168,11 +183,7 @@ def cli(project, version, date, check): linkify_gh_diff(changelog, tag_prefix="python/v") # core changelog for each model - if project.parts[-1] == "core": - for internal_name in INTERNAL_MODELS: - if internal_name in INTERNAL_MODELS_SKIP: - continue - filter_changelog(changelog, internal_name) + generate_filtered(project, changelog) # towncrier calls git add before we do linkification, stage the changes too subprocess.run(["git", "add", changelog], check=True) diff --git a/tools/towncrier.toml b/tools/towncrier.toml index f7172a51b..00860deef 100644 --- a/tools/towncrier.toml +++ b/tools/towncrier.toml @@ -1,3 +1,6 @@ +# This is the default configuration that is used by subprojects via symlink. +# Some subprojects have their own configuration which is not a symlink. + [tool.towncrier] directory = ".changelog.d" filename = "CHANGELOG.md"