-
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathadd_latest_release_date.py
More file actions
40 lines (28 loc) · 1010 Bytes
/
add_latest_release_date.py
File metadata and controls
40 lines (28 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Check release-notes.md and add today's date to the latest release header if missing."""
import re
import sys
from datetime import date
RELEASE_NOTES_FILE = "release-notes.md"
RELEASE_HEADER_PATTERN = re.compile(r"^## (\d+\.\d+\.\d+)\s*(\(.*\))?\s*$")
def main() -> None:
with open(RELEASE_NOTES_FILE) as f:
lines = f.readlines()
for i, line in enumerate(lines):
match = RELEASE_HEADER_PATTERN.match(line)
if not match:
continue
version = match.group(1)
date_part = match.group(2)
if date_part:
print(f"Latest release {version} already has a date: {date_part}")
sys.exit(0)
today = date.today().isoformat()
lines[i] = f"## {version} ({today})\n"
print(f"Added date: {version} ({today})")
with open(RELEASE_NOTES_FILE, "w") as f:
f.writelines(lines)
sys.exit(0)
print("No release header found")
sys.exit(1)
if __name__ == "__main__":
main()