...
1import fileinput
2import sys
3from lib import git_add
4import re
5
6def update_changelog_date(next_ver):
7 changelog_ver_pattern = re.compile(r"^## \[([0-9]+\.[0-9]+\.[0-9]+(-ea)?)\]")
8 in_notes = False
9 buf = ""
10 for line in fileinput.FileInput("CHANGELOG.md", inplace=True):
11 if not in_notes:
12 sys.stdout.write(line)
13 if line.startswith("## Next Release"):
14 in_notes = True
15 continue
16
17 match = changelog_ver_pattern.match(line)
18 if not match:
19 buf += line
20 elif line.startswith(f"## [{next_ver}]"):
21 # Don't do anything, this changelog already has an entry for the next version
22 sys.stdout.write(buf)
23 sys.stdout.write(line)
24 in_notes = False
25 else:
26 prev_ver = match[1]
27 # dope let's get the last version first
28 # this is the beginning of the last version line
29 sys.stdout.write("\n")
30 sys.stdout.write("### Emissary Ingress\n")
31 sys.stdout.write("\n")
32 sys.stdout.write("(no changes yet)\n")
33 sys.stdout.write("\n")
34 sys.stdout.write(f"## [{next_ver}] (TBD)\n")
35 sys.stdout.write(
36 f"[{next_ver}]: https://github.com/emissary-ingress/emissary/compare/v{prev_ver}...v{next_ver}\n")
37 sys.stdout.write(buf)
38 sys.stdout.write(line)
39 in_notes = False
40
41 git_add("CHANGELOG.md")
View as plain text