File: get_release_description.py

package info (click to toggle)
libtcod 1.24.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,728 kB
  • sloc: ansic: 46,186; cpp: 13,523; python: 4,814; makefile: 44; sh: 25
file content (26 lines) | stat: -rwxr-xr-x 656 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python3
"""Print the description used for GitHub Releases."""
from __future__ import annotations

import re
from pathlib import Path

TAG_BANNER = r"## \[\d+\.\d+\.\d+\S*\] - \d+-\d+-\d+\n"

RE_BODY = re.compile(rf".*?{TAG_BANNER}(.*?){TAG_BANNER}", re.DOTALL)
RE_SECTION = re.compile(r"^### (\w+)$", re.MULTILINE)


def main() -> None:
    # Get the most recent tag.
    match = RE_BODY.match(Path("CHANGELOG.md").read_text(encoding="utf-8"))
    assert match
    body = match.groups()[0].strip()

    # Add Markdown formatting to sections.
    body = RE_SECTION.sub(r"### \1", body)
    print(body)


if __name__ == "__main__":
    main()