-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_version_history.py
79 lines (63 loc) · 2.29 KB
/
create_version_history.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/python3
# Automated VDR repository mirror and wiki page generator
# Copyright © 2024 Manuel Reimer <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import re
import subprocess
repo = sys.argv[1]
# Get list of tags (unsorted)
taglist = subprocess.check_output([
"git", "-C", repo, "tag",
"--format", "%(refname:short) %(creatordate:short)"
]).decode("utf-8").splitlines()
# Split the two fields for all entries
taglist = [line.split(" ") for line in taglist]
# Sort handler
def versionkey(A):
part1, part2, part3 = A[0].split(".")
sort_for = [int(part1), int(part2)]
if part3.isnumeric():
sort_for.extend((int(part3), 0))
elif "-" in part3:
rev, patch = part3.split("-")
sort_for.extend((int(rev), int(patch)))
elif "pre" in part3:
rev, pre = part3.split("pre")
sort_for.extend((int(rev), -10 + int(pre)))
return sort_for
# Try to sort the list
try:
taglist.sort(key=versionkey)
except Exception as e:
print(e, file=sys.stderr)
# Get the API version, build entries
entries = []
for tag, date in taglist:
config_h = subprocess.check_output([
"git", "-C", repo, "show",
f"{tag}:config.h"
]).decode("utf-8")
match = re.search(
r'^#define\s+APIVERSION\s+"([^"]+)',
config_h, flags=re.MULTILINE
)
apiversion = match.group(1) if match else "--"
entries.append((tag, date, apiversion))
# Create Markdown output
print("| Version | Release Date | API Version |")
print("|---------|--------------|-------------|")
for version, date, apiversion in entries:
print(f"| {version} | {date} | {apiversion} |")