generate_changelog.py: add option to write it to the changelogs
This commit is contained in:
parent
74f00f9017
commit
579e84ec93
|
|
@ -9,8 +9,10 @@ though it often needs some manual editing too.
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
from datetime import date
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, List, Optional
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
|
|
@ -109,19 +111,46 @@ def print_section(crate: str, items: List[str]) -> None:
|
||||||
if 0 < len(items):
|
if 0 < len(items):
|
||||||
print(f"#### {crate}")
|
print(f"#### {crate}")
|
||||||
for line in items:
|
for line in items:
|
||||||
line = remove_prefix(line, f"[{crate}] ")
|
|
||||||
line = remove_prefix(line, f"{crate}: ")
|
|
||||||
line = remove_prefix(line, f"`{crate}`: ")
|
|
||||||
line = line[0].upper() + line[1:] # Upper-case first letter
|
|
||||||
print(f"* {line}")
|
print(f"* {line}")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
def add_to_changelog_file(crate: str, items: List[str], version: str) -> None:
|
||||||
|
insert_text = f"\n## {version} - {date.today()}\n"
|
||||||
|
for item in items:
|
||||||
|
insert_text += f"* {item}\n"
|
||||||
|
insert_text += "\n"
|
||||||
|
|
||||||
|
scripts_dirpath = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
if crate == "egui":
|
||||||
|
file_path = f"{scripts_dirpath}/../CHANGELOG.md"
|
||||||
|
else:
|
||||||
|
file_path = f"{scripts_dirpath}/../crates/{crate}/CHANGELOG.md"
|
||||||
|
file_path = os.path.normpath(file_path)
|
||||||
|
|
||||||
|
with open(file_path, 'r') as file:
|
||||||
|
content = file.read()
|
||||||
|
|
||||||
|
position = content.find('\n##')
|
||||||
|
assert position != -1
|
||||||
|
|
||||||
|
content = content[:position] + insert_text + content[position:]
|
||||||
|
|
||||||
|
with open(file_path, 'w') as file:
|
||||||
|
file.write(content)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
parser = argparse.ArgumentParser(description="Generate a changelog.")
|
parser = argparse.ArgumentParser(description="Generate a changelog.")
|
||||||
parser.add_argument("--commit-range", help="e.g. 0.24.0..HEAD")
|
parser.add_argument("--commit-range", help="e.g. 0.24.0..HEAD", 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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.write and not args.version:
|
||||||
|
print("ERROR: --version is required when --write is used")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
repo = Repo(".")
|
repo = Repo(".")
|
||||||
commits = list(repo.iter_commits(args.commit_range))
|
commits = list(repo.iter_commits(args.commit_range))
|
||||||
commits.reverse() # Most recent last
|
commits.reverse() # Most recent last
|
||||||
|
|
@ -195,16 +224,35 @@ def main() -> None:
|
||||||
if not any(label in labels for label in ignore_labels):
|
if not any(label in labels for label in ignore_labels):
|
||||||
unsorted_prs.append(summary)
|
unsorted_prs.append(summary)
|
||||||
|
|
||||||
|
# Clean up:
|
||||||
|
for crate in crate_names:
|
||||||
|
if crate in sections:
|
||||||
|
items = sections[crate]
|
||||||
|
for i in range(len(items)):
|
||||||
|
line = items[i]
|
||||||
|
line = remove_prefix(line, f"[{crate}] ")
|
||||||
|
line = remove_prefix(line, f"{crate}: ")
|
||||||
|
line = remove_prefix(line, f"`{crate}`: ")
|
||||||
|
line = line[0].upper() + line[1:] # Upper-case first letter
|
||||||
|
items[i] = line
|
||||||
|
|
||||||
|
|
||||||
print()
|
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/{args.commit_range}")
|
||||||
print()
|
print()
|
||||||
for crate in crate_names:
|
for crate in crate_names:
|
||||||
if crate in sections:
|
if crate in sections:
|
||||||
summary = sections[crate]
|
items = sections[crate]
|
||||||
print_section(crate, summary)
|
print_section(crate, items)
|
||||||
print_section("Unsorted PRs", unsorted_prs)
|
print_section("Unsorted PRs", unsorted_prs)
|
||||||
print_section("Unsorted commits", unsorted_commits)
|
print_section("Unsorted commits", unsorted_commits)
|
||||||
|
|
||||||
|
if args.write:
|
||||||
|
for crate in crate_names:
|
||||||
|
items = sections[crate] if crate in sections else []
|
||||||
|
add_to_changelog_file(crate, items, args.version)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue