Files
AnyPS5/tools/prepare_release_notes.py
T
javierUDP 02c7da7677 fix: keep the Python tools and tests on Python 3.9
`Path.write_text(newline=...)` and `zip(strict=True)` were added in
Python 3.10. macOS ships 3.9.6 as /usr/bin/python3, the interpreter CMake
finds when no newer one is installed, so `prepare_release_notes` raised
TypeError when the release workflow wrote its notes and the
`pr_overlap_tools`, `release_package` and `linux_fixed_base` tests failed
on a stock macOS host. Writing the encoded text keeps the newline
translation off on every host, and the dynamic tag counts are compared
before the pairs are walked.
2026-10-17 10:31:10 -03:00

46 lines
1.4 KiB
Python

import argparse
import json
import re
from pathlib import Path
BODY_LIMIT = 125000
def release_body(notes):
if len(notes) <= BODY_LIMIT:
return notes
return re.sub(
r"^## What's Changed[^\S\r\n]*\r?\n.*?(?=^#{1,2} |^\*\*Full Changelog\*\*:|\Z)",
"",
notes,
count=1,
flags=re.MULTILINE | re.DOTALL,
)
def prepare_notes(source, body, full):
paths = (source, body, full)
for index, first in enumerate(paths):
for second in paths[index + 1:]:
if first.resolve() == second.resolve() or (first.exists() and second.exists() and first.samefile(second)):
raise ValueError("Release note input and outputs must be distinct files")
notes = json.loads(source.read_text(encoding="utf-8"))["body"]
if not isinstance(notes, str):
raise ValueError("Generated release notes body must be a string")
full.parent.mkdir(parents=True, exist_ok=True)
full.write_bytes(notes.encode("utf-8"))
body.write_bytes(release_body(notes).encode("utf-8"))
def main():
parser = argparse.ArgumentParser(description="Prepare size-safe GitHub release notes")
parser.add_argument("--input", type=Path, required=True)
parser.add_argument("--body", type=Path, required=True)
parser.add_argument("--full", type=Path, required=True)
args = parser.parse_args()
prepare_notes(args.input, args.body, args.full)
if __name__ == "__main__":
main()