Skip to content

Commit 4f70d14

Browse files
authored
Reverse and format the archived changelogs (astral-sh#12099)
I think it's important for the breaking changes to be at the _top_ of the file instead of the bottom. Now that it's not being rendered by GitHub's Releases markdown, we can remove the prettier ignores.
1 parent 7fc4e07 commit 4f70d14

File tree

6 files changed

+4996
-3378
lines changed

6 files changed

+4996
-3378
lines changed

changelogs/0.1.x.md

+1,072-808
Large diffs are not rendered by default.

changelogs/0.2.x.md

+1,301-905
Large diffs are not rendered by default.

changelogs/0.3.x.md

+276-186
Large diffs are not rendered by default.

changelogs/0.4.x.md

+1,013-654
Large diffs are not rendered by default.

changelogs/0.5.x.md

+1,278-825
Large diffs are not rendered by default.

scripts/reverse-changelog.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
Reverse the ordering of versions in a changelog file, i.e., when archiving a changelog.
3+
"""
4+
5+
import re
6+
import sys
7+
8+
9+
def parse_changelog(content):
10+
"""Parse the changelog content into individual version blocks."""
11+
# Use regex to split the content by version headers
12+
version_pattern = r"(?=## \d+\.\d+\.\d+)"
13+
version_blocks = re.split(version_pattern, content)
14+
15+
# First item in the list is the header, which we want to preserve
16+
header = version_blocks[0]
17+
version_blocks = version_blocks[1:]
18+
19+
return header, version_blocks
20+
21+
22+
def reverse_changelog(content):
23+
"""Reverse the order of version blocks in the changelog."""
24+
header, version_blocks = parse_changelog(content)
25+
26+
# Reverse the version blocks
27+
reversed_blocks = version_blocks[::-1]
28+
29+
# Combine the header and reversed blocks
30+
reversed_content = header + "".join(reversed_blocks)
31+
32+
return reversed_content
33+
34+
35+
def main():
36+
if len(sys.argv) < 2:
37+
print("Usage: reverse-changelog.py <changelog-file>")
38+
sys.exit(1)
39+
40+
# Read the input file
41+
name = sys.argv[1]
42+
with open(name, "r") as file:
43+
content = file.read()
44+
45+
# Reverse the changelog
46+
reversed_content = reverse_changelog(content)
47+
48+
# Write the output to a new file
49+
with open(name, "w") as file:
50+
file.write(reversed_content)
51+
52+
print(f"Updated {name}")
53+
54+
55+
if __name__ == "__main__":
56+
main()

0 commit comments

Comments
 (0)