aboutsummaryrefslogtreecommitdiff
path: root/.github/scripts
diff options
context:
space:
mode:
authorJohn "Lameguy" Wilbert Villamor <lameguy64@gmail.com>2022-09-26 16:49:56 +0800
committerGitHub <noreply@github.com>2022-09-26 16:49:56 +0800
commitc4a2533d21dfd05cde841ea48c67b05e0e6a853f (patch)
treec7ef61653b157b69fb0956709366996ddbc4ecfa /.github/scripts
parenta8b404b3400c3ebd8e0b923dcaefcc49ea563e36 (diff)
parent86f0064afb8200e60dd80827535cac30d0eab028 (diff)
downloadpsn00bsdk-c4a2533d21dfd05cde841ea48c67b05e0e6a853f.tar.gz
Merge pull request #55 from spicyjpeg/psxmdec
Full MDEC support, C library refactors, cleanups and bugfixes (v0.20)
Diffstat (limited to '.github/scripts')
-rw-r--r--.github/scripts/generate_release_notes.py76
1 files changed, 45 insertions, 31 deletions
diff --git a/.github/scripts/generate_release_notes.py b/.github/scripts/generate_release_notes.py
index e3fbc7f..c706191 100644
--- a/.github/scripts/generate_release_notes.py
+++ b/.github/scripts/generate_release_notes.py
@@ -8,7 +8,8 @@ from argparse import ArgumentParser, FileType
## Helpers
-VERSION_REGEX = re.compile(r"^(?:refs\/tags\/)?(?:v|ver|version|release)? *(.*)")
+VERSION_REGEX = re.compile(r"^(?:refs\/tags\/)?(?:v|ver|version|release)? *(.*)")
+TEXT_WRAP_REGEX = re.compile(r"(?<!\n)[ \t]*?\n[ \t]*(?!\n)", re.MULTILINE)
def parse_date(date):
if isinstance(date, struct_time):
@@ -19,11 +20,27 @@ def parse_date(date):
def normalize_version(version):
return VERSION_REGEX.match(version.lower()).group(1)
+def unwrap_text(text):
+ return TEXT_WRAP_REGEX.sub(" ", text.strip())
+
+def deduplicate_authors(authors):
+ _authors = []
+ folded = []
+
+ for name in authors:
+ if (fold := name.lower()) in folded:
+ continue
+
+ _authors.append(name)
+ folded.append(fold)
+
+ _authors.sort()
+ return _authors
+
## Changelog parser
-BLOCK_REGEX = re.compile(r"^#{2,}[ \t]*([0-9]{4}-[0-9]{2}-[0-9]{2})(?:[:\- \t]+(.+?))?$", re.MULTILINE)
-AUTHOR_REGEX = re.compile(r"^([A-Za-z0-9_].*?)[ \t]*:.*?$", re.MULTILINE)
-FIRST_VERSION = "initial"
+BLOCK_REGEX = re.compile(r"^#{2,}[ \t]*([0-9]{4}-[0-9]{2}-[0-9]{2})(?:[:\- \t]+(.*?))?$", re.MULTILINE)
+AUTHOR_REGEX = re.compile(r"^([A-Za-z0-9_].*?)[ \t]*:.*?$", re.MULTILINE)
def parse_authors(block):
# [ _crap, author, body, author, body, ... ]
@@ -35,13 +52,10 @@ def parse_authors(block):
authors = {}
for i in range(1, len(items), 2):
name, body = items[i:i + 2]
-
- name = name.strip()
- body = body.strip()
- if name not in authors:
+ if (name := name.strip()) not in authors:
authors[name] = ""
- authors[name] += body
+ authors[name] += body.strip()
return authors
@@ -49,21 +63,18 @@ def parse_blocks(changelog):
# [ _crap, date, version, body, date, version, body, ... ]
items = BLOCK_REGEX.split(changelog.strip())
- # Iterate over all blocks from bottom to top (i.e. oldest first).
- last_version = FIRST_VERSION
+ # Iterate over all blocks from bottom to top (i.e. oldest first) and group
+ # them by the version number of the block they precede.
+ blocks = []
for i in range(len(items), 1, -3):
date, version, body = items[i - 3:i]
- # If no version is present in the header, assume it's the same as the
- # previous block's version.
- if version:
- version = normalize_version(version)
- last_version = version
- else:
- version = last_version
+ blocks.append(( parse_date(date), parse_authors(body) ))
- yield parse_date(date), version, parse_authors(body)
+ if version:
+ yield normalize_version(version), tuple(blocks)
+ blocks = []
## Release notes generation
@@ -74,9 +85,8 @@ VERSION_TEMPLATE = """New in version **{version}** (contributed by {authors}):
"""
NOTES_TEMPLATE = """{notes}
--------------------------------------------------------
-_These notes have been generated automatically._
-_See the changelog or commit history for more details._
+------------------------------------------------------------------------------------------------------
+_These notes have been generated automatically. See the changelog or commit history for more details._
"""
NO_VERSIONS_TEMPLATE = "No information available about this release."
@@ -87,8 +97,10 @@ def generate_notes(versions):
notes = ""
for version, ( authors, changes ) in versions.items():
- _authors = list(set(authors))
- _authors.sort()
+ if not changes:
+ continue
+
+ _authors = deduplicate_authors(authors)
_authors = map(AUTHOR_LINK_TEMPLATE.format, _authors)
notes += VERSION_TEMPLATE.format(
@@ -100,7 +112,7 @@ def generate_notes(versions):
if not notes:
notes = NO_VERSIONS_TEMPLATE
- return NOTES_TEMPLATE.format(notes = notes.strip())
+ return NOTES_TEMPLATE.format(notes = unwrap_text(notes))
## Main
@@ -155,19 +167,21 @@ def main():
# merging all changes and authors for each version.
versions = {}
- for date, version, authors in parse_blocks(changelog):
- # Apply version and date filters.
+ for version, blocks in parse_blocks(changelog):
if version_list and (version not in version_list):
continue
- if date < args.from_date or date > args.to_date:
- continue
if version not in versions:
versions[version] = [], []
_authors, _changes = versions[version]
- _authors.extend(authors.keys())
- _changes.extend(authors.values())
+
+ for date, authors in blocks:
+ if date < args.from_date or date > args.to_date:
+ continue
+
+ _authors.extend(authors.keys())
+ _changes.extend(authors.values())
notes = generate_notes(versions)