Skip to content

Commit

Permalink
[7.2.0] Update release notes script (bazelbuild#21844)
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 618964109
Change-Id: I79810e2a8c8a9f2174baccb6c8df240d1b927e5d

Commit
bazelbuild@9a333bc

Co-authored-by: Googler <keerthanakumar@google.com>
Co-authored-by: Ian (Hee) Cha <heec@google.com>
  • Loading branch information
3 people authored Mar 28, 2024
1 parent 026ffe4 commit 7e83351
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions scripts/release/relnotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def git(*args):
list(args)).decode("utf-8").strip().split("\n")


def extract_pr_title(commit_message_lines):
def extract_title(commit_message_lines):
"""Extracts first line from commit message (passed in as a list of lines)."""
return re.sub(
r"\[\d+\.\d+\.\d\]\s?", "", commit_message_lines[0].strip()
Expand All @@ -37,26 +37,38 @@ def extract_relnotes(commit_message_lines):
"""Extracts relnotes from a commit message (passed in as a list of lines)."""
relnote_lines = []
in_relnote = False

title = extract_title(commit_message_lines)
issue_id = re.search(r"\(\#[0-9]+\)$", title.strip().split()[-1])

for line in commit_message_lines:
if not line or line.startswith("PiperOrigin-RevId:"):
line = line.strip()
if (
not line
or line.startswith("PiperOrigin-RevId:")
or re.match(r"^\s*(Fixes|Closes)\s+#\d+\.?\s*$", line)
):
in_relnote = False
m = re.match(r"^RELNOTES(?:\[(INC|NEW)\])?:", line)
if m is not None:
in_relnote = True
line = line[len(m[0]):]
line = line[len(m[0]) :]
if line.strip().lower().rstrip(".") in ["n/a", "na", "none"]:
return None
if m[1] == "INC":
line = "**[Incompatible]** " + line.strip()
line = line.strip()
if in_relnote and line:
relnote_lines.append(line)
relnote = " ".join(relnote_lines)
relnote_lower = relnote.strip().lower().rstrip(".")
if relnote_lower == "n/a" or relnote_lower == "none" or not relnote_lower:
return None

if issue_id and relnote:
relnote += " " + issue_id.group(0).strip()

return relnote


def get_relnotes_between(base, head, is_major_release):
def get_relnotes_between(base, head, is_patch_release):
"""Gets all relnotes for commits between `base` and `head`."""
commits = git("rev-list", f"{base}..{head}")
if commits == [""]:
Expand All @@ -75,7 +87,7 @@ def get_relnotes_between(base, head, is_major_release):
# The rollback commit itself is also skipped.
continue
relnote = (
extract_relnotes(lines) if is_major_release else extract_pr_title(lines)
extract_title(lines) if is_patch_release else extract_relnotes(lines)
)
if relnote is not None:
relnotes.append(relnote)
Expand Down Expand Up @@ -166,7 +178,7 @@ def get_external_authors_between(base, head):
print("Error: Not a release branch.")
sys.exit(1)

is_major = bool(re.fullmatch(r"\d+.0.0", current_release))
is_patch = not current_release.endswith(".0")

tags = [tag for tag in git("tag", "--sort=refname") if "pre" not in tag]

Expand All @@ -181,13 +193,14 @@ def get_external_authors_between(base, head):
# base with the last release so that we know which commits to generate notes
# for.
merge_base = git("merge-base", "HEAD", last_release)[0]
print("Baseline: ", merge_base)

# Generate notes for all commits from last branch cut to HEAD, but filter out
# any identical notes from the previous release branch.
cur_release_relnotes = get_relnotes_between(merge_base, "HEAD", is_major)
cur_release_relnotes = get_relnotes_between(
merge_base, "HEAD", is_patch
)
last_release_relnotes = set(
get_relnotes_between(merge_base, last_release, is_major)
get_relnotes_between(merge_base, last_release, is_patch)
)
filtered_relnotes = [
note for note in cur_release_relnotes if note not in last_release_relnotes
Expand All @@ -197,19 +210,14 @@ def get_external_authors_between(base, head):
filtered_relnotes.reverse()
print()
print("Release Notes:")
print()

if len(sys.argv) >= 2 and sys.argv[1] == "sort":
print()
categorized_release_notes = get_categorized_relnotes(filtered_relnotes)
for label in categorized_release_notes:
print(label + ":")
for note in categorized_release_notes[label]:
print("+", note)
print()
else:
print()
for note in filtered_relnotes:
categorized_release_notes = get_categorized_relnotes(filtered_relnotes)
for label in categorized_release_notes:
print(label + ":")
for note in categorized_release_notes[label]:
print("+", note)
print()

print()
print("Acknowledgements:")
Expand Down

0 comments on commit 7e83351

Please sign in to comment.