Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/scripts/native-changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
"""Print the CHANGELOG.md sections of a native Superwall SDK between two versions.

Usage: native-changelog.py <changelog-path> <old-version> <new-version>

Prints every "## <version>" section with old < version <= new, newest first,
headings included. A wrapper can lag several native releases behind, so the
whole range matters, not just the newest entry.

Only "## <semver>" lines count as section boundaries: Superwall-Android also
uses "## Fixes" / "## Enhancements" as sub-headings inside a version.
"""
import re
import sys

HEADING = re.compile(r"^##\s+v?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)\s*$")


def key(version):
core, _, pre = version.partition("-")
# A release sorts after its own prereleases (2.9.0-beta.1 < 2.9.0).
return tuple(int(p) for p in core.split(".")), pre == "", pre


def main():
path, old, new = sys.argv[1:4]
lo, hi = key(old), key(new)
out, keep = [], False
with open(path, encoding="utf-8") as f:
for line in f:
m = HEADING.match(line.rstrip("\n"))
if m:
keep = lo < key(m.group(1)) <= hi
if keep:
out.append(line)
sys.stdout.write("".join(out).strip() + "\n" if out else "")


if __name__ == "__main__":
main()
66 changes: 66 additions & 0 deletions .github/scripts/unreleased-entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
"""Add a bullet to a subheading of the CHANGELOG.md "## [Unreleased]" section.

Usage: unreleased-entry.py <changelog-path> <subheading> <bullet> [replace-prefix]

Bullets use the "* " marker this changelog already uses. A second bump of the
same platform replaces the bullet that starts with replace-prefix instead of
adding another one. package.json is left alone: cutting a version out of
[Unreleased] is a separate release.
"""
import sys

UNRELEASED = "## [Unreleased]"


def main():
path, subheading, bullet = sys.argv[1:4]
replace_prefix = sys.argv[4] if len(sys.argv) > 4 else None
with open(path, encoding="utf-8") as f:
lines = f.read().split("\n")
bullet_line = bullet if bullet.startswith("* ") else f"* {bullet}"

start = next((i for i, line in enumerate(lines) if line.strip() == UNRELEASED), None)
if start is None:
insert_at = next((i for i, line in enumerate(lines) if line.startswith("## ")), len(lines))
lines[insert_at:insert_at] = [UNRELEASED, "", subheading, bullet_line, ""]
return write(path, lines)

end = next((i for i in range(start + 1, len(lines)) if lines[i].startswith("## ")), len(lines))

if replace_prefix:
stale = next(
(i for i in range(start + 1, end) if lines[i].startswith(f"* {replace_prefix}")),
None,
)
if stale is not None:
lines[stale] = bullet_line
return write(path, lines)

sub = next((i for i in range(start + 1, end) if lines[i].strip() == subheading), None)
if sub is None:
# Sit above the next version heading, after whatever is already unreleased.
block = [subheading, bullet_line, ""]
at = end
if at > start + 1 and lines[at - 1] != "":
block.insert(0, "")
lines[at:at] = block
else:
j = sub + 1
while j < end and (lines[j].startswith("* ") or lines[j].startswith(" ")):
j += 1
lines.insert(j, bullet_line)

write(path, lines)


def write(path, lines):
text = "\n".join(lines)
if not text.endswith("\n"):
text += "\n"
with open(path, "w", encoding="utf-8") as f:
f.write(text)


if __name__ == "__main__":
main()
Loading
Loading