-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_release_notes.py
executable file
·79 lines (50 loc) · 2.85 KB
/
generate_release_notes.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
# lintrans - The linear transformation visualizer
# Copyright (C) 2021-2022 D. Dyson (DoctorDalek1963)
# This program is licensed under GNU GPLv3, available here:
# <https://www.gnu.org/licenses/gpl-3.0.html>
"""A very simple script to generate release notes."""
import re
import sys
TEXT = '''DESCRIPTION
---
I *highly* recommend reading the tutorial, available [here](https://lintrans.readthedocs.io/en/VERSION_RTD/tutorial/).
---
The recommended way to use `lintrans` is to install it with the relevant installer for your platform. This will allow lintrans to update itself whenever a new version is available. This is configurable.
The Windows installer is completely safe, but you might get a warning that it might not be. This is expected and it's safe to ignore the warning. The only way to get rid of it would be to pay Microsoft. On macOS, I would need to pay Apple to allow other people to run any of my code at all.
If this warning bothers you or if you want to use `lintrans` on macOS, then you can compile the program from its source code. This is a relatively simple process and the tutorial for doing that is available [here](https://lintrans.readthedocs.io/en/VERSION_RTD/compilation/).
---
If you don't want to install `lintrans`, then you can download and run the standalone executable for your platform (the Windows one has another warning which is safe to ignore), or you can compile it from source. See the tutorial above.
The Linux binary is a dynamically linked ELF compiled on Ubuntu 20.04 and may or may not work on other distros. Compiling is also an option for Linux. See the tutorial above.
---
CHANGELOG
'''
# This RegEx is complicated because of the newlines
# It requires the current tag to have a header like
# ## [0.2.1] - 2022-03-22
# And all other tags to have similar headers
# It also won't work on the first tag, but that's fine
RE_PATTERN = r'''(?<=## \[TAG_NAME\] - \d{4}-\d{2}-\d{2}
).*?(?=
## \[\d+\.\d+\.\d+(-[\S]+)?\] - \d{4}-\d{2}-\d{2})'''
def main(args: list[str]) -> None:
"""Generate the release notes for this release and write them to `release_notes.md`."""
if len(args) < 1:
raise ValueError('Tag name is required to generate release notes')
tag_name = args[0]
print(f'Generating release notes for tag {tag_name}')
with open('CHANGELOG.md', 'r', encoding='utf-8') as f:
changelog_text = f.read()
if (m := re.search(
RE_PATTERN.replace('TAG_NAME', re.escape(tag_name[1:])),
changelog_text,
flags=re.S
)) is not None:
text = TEXT.replace('CHANGELOG', m.group(0))
text = text.replace('VERSION_RTD', tag_name)
else:
raise ValueError('Error in searching for changelog notes. Bad format')
with open('release_notes.md', 'w', encoding='utf-8') as f:
f.write(text)
if __name__ == '__main__':
main(sys.argv[1:])