From 99c1034cfcaa90415033af289c312fc6bcfabafb Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 12 Dec 2024 16:57:52 +0100 Subject: [PATCH] Improve changelog generation script --- RELEASES.md | 1 + scripts/generate_changelog.py | 40 ++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index b3777a3aedc..677f31fddf9 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -84,6 +84,7 @@ I usually do this all on the `master` branch, but doing it in a release branch i (cd crates/egui_demo_lib && cargo publish --quiet) && echo "✅ egui_demo_lib" (cd crates/egui_glow && cargo publish --quiet) && echo "✅ egui_glow" (cd crates/eframe && cargo publish --quiet) && echo "✅ eframe" +(cd crates/egui_kittest && cargo publish --quiet) && echo "✅ egui_kittest" ``` ## Announcements diff --git a/scripts/generate_changelog.py b/scripts/generate_changelog.py index 551d9c9d29e..1621fd29793 100755 --- a/scripts/generate_changelog.py +++ b/scripts/generate_changelog.py @@ -214,18 +214,42 @@ def add_to_changelog_file(crate: str, content: str, version: str) -> None: file.write(content) +def calc_commit_range(new_version: str) -> str: + parts = new_version.split(".") + assert len(parts) == 3, "Expected version to be on the format X.Y.Z" + major = int(parts[0]) + minor = int(parts[1]) + patch = int(parts[2]) + + if 0 < patch: + # A patch release. + # Include changes since last patch release. + # This assumes we've cherry-picked stuff for this release. + diff_since_version = f"0.{minor}.{patch - 1}" + elif 0 < minor: + # A minor release + # The diff should span everything since the last minor release. + # The script later excludes duplicated automatically, so we don't include stuff that + # was part of intervening patch releases. + diff_since_version = f"{major}.{minor - 1}.0" + else: + # A major release + # The diff should span everything since the last major release. + # The script later excludes duplicated automatically, so we don't include stuff that + # was part of intervening minor/patch releases. + diff_since_version = f"{major - 1}.{minor}.0" + + return f"{diff_since_version}..HEAD" + + def main() -> None: parser = argparse.ArgumentParser(description="Generate a changelog.") - parser.add_argument("--commit-range", help="e.g. 0.24.0..HEAD", required=True) + parser.add_argument("--version", help="What release is this?", required=True) parser.add_argument( "--write", help="Write into the different changelogs?", action="store_true" ) - parser.add_argument("--version", help="What release is this?") args = parser.parse_args() - - if args.write and not args.version: - print("ERROR: --version is required when --write is used") - sys.exit(1) + commit_range = calc_commit_range(args.version) crate_names = [ "ecolor", @@ -251,7 +275,7 @@ def main() -> None: all_changelogs += file.read() repo = Repo(".") - commits = list(repo.iter_commits(args.commit_range)) + commits = list(repo.iter_commits(commit_range)) commits.reverse() # Most recent last commit_infos = list(map(get_commit_info, commits)) @@ -307,7 +331,7 @@ def main() -> None: unsorted_prs.append(pr_summary(pr_info)) print() - print(f"Full diff at https://github.com/emilk/egui/compare/{args.commit_range}") + print(f"Full diff at https://github.com/emilk/egui/compare/{commit_range}") print() for crate in crate_names: if crate in crate_sections: