Skip to content

Commit 7d1d623

Browse files
committed
CI: fix changelog builder: add commit message types
And skip version change log when exists
1 parent 3e58f63 commit 7d1d623

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

scripts/build_change_log.py

+25-14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import semantic_version
77
import yaml
88
import re
9+
import os
910
from collections import defaultdict
1011

1112
with open('scripts/change-types.yaml', 'r') as f:
@@ -24,6 +25,7 @@
2425
'fixdoc:': typs['fixdoc'],
2526
'dep:': typs['dep'],
2627
'ci:': typs['ci'],
28+
'CI:': typs['ci'],
2729

2830
# fix typo
2931
'Change:': typs['api-change'],
@@ -37,6 +39,7 @@
3739
'new-features:': typs['new-feature'],
3840
'docs:': typs['doc'],
3941
'fix:': typs['fixbug'],
42+
'Fix:': typs['fixbug'],
4043
'fixup:': typs['fixbug'],
4144

4245
'test:': typs['test'],
@@ -45,9 +48,10 @@
4548
'Update:': typs['other'],
4649
'update:': typs['other'],
4750
'turn:': typs['other'],
48-
'replace:': typs['refactor'],
49-
'use:': typs['refactor'],
50-
'Create:': typs['other'],
51+
'replace:': typs['refactor'],
52+
'use:': typs['refactor'],
53+
'Create:': typs['other'],
54+
'BumpVer:': typs['other'],
5155
}
5256

5357
category_display = {
@@ -62,20 +66,21 @@
6266
replace_subjects = [
6367
(r'^([^: ]+) ', r'\1: '), # add ":" if not
6468
(r'^(\w+:) *', r'\1 '), # 0 or many space to 1 space
65-
(r'^build\(dpes\): ', r'dep: '),
69+
(r'^build\(dpes\): ', r'dep: '),
6670
]
6771

6872
ignores = [
69-
'^Merge pull request',
73+
'^Merge pull request',
74+
'^BumpVer:',
7075
]
7176

7277
to_display = {
73-
'other': False,
78+
'other': False,
7479
'doc': False,
7580
'refactor': False,
7681
'internal': False,
7782
'test': False,
78-
'ci': False,
83+
'ci': False,
7984
}
8085

8186
commit_url_ptn = 'https://github.com/datafuselabs/openraft/commit/{hash}'
@@ -127,13 +132,13 @@ def changes(frm, to):
127132
body = cmd(["git", "log", '-1', '--format=%b', commit])
128133

129134
item = {
130-
'hash': commit,
135+
'hash': commit,
131136
'subject': elts[0],
132137
# 2019-04-18 13:36:42 +0800
133138
'time': elts[1].split()[0],
134139
'author': elts[2],
135140
'email': elts[3],
136-
'body': body,
141+
'body': body,
137142
}
138143

139144
rst.append(item)
@@ -179,12 +184,12 @@ def norm_changes(changes):
179184
bodylines = ch['body'].strip().splitlines()
180185
bodylines = [' ' + x for x in bodylines]
181186
desc = {
182-
'hash': ch['hash'],
187+
'hash': ch['hash'],
183188
"content": cont,
184189
"time": ch['time'],
185190
"author": ch['author'],
186191
'email': ch['email'],
187-
'body': bodylines,
192+
'body': bodylines,
188193
}
189194
c.append(desc)
190195

@@ -196,6 +201,12 @@ def build_ver_changelog(new_ver, commit="HEAD"):
196201
It will find out all commit since the last tag that is less than ``new_ver``
197202
'''
198203

204+
fn = 'change-log/v{new_ver}.md'.format(new_ver=new_ver)
205+
if os.path.exists(fn):
206+
print("--- Version {new_ver} change log exists, skip...".format(new_ver=new_ver))
207+
print("--- To rebuild it, delete {fn} and re-run".format(fn=fn))
208+
return
209+
199210
tags = list_tags()
200211
tags.sort()
201212

@@ -234,7 +245,7 @@ def build_ver_changelog(new_ver, commit="HEAD"):
234245

235246
changelog = '\n'.join(lines)
236247

237-
with open('change-log/v{new_ver}.md'.format(new_ver=new_ver), 'w') as f:
248+
with open(fn, 'w') as f:
238249
f.write(changelog)
239250

240251
def build_changelog():
@@ -256,11 +267,11 @@ def build_changelog():
256267
cont = cont.splitlines()
257268
cont = '\n'.join(cont)
258269

259-
f.write(cont + '\n')
270+
f.write(cont + '\n\n')
260271

261272
if __name__ == "__main__":
262273
# Usage: to build change log from git log
263-
# ./scripts/build_change_log.py v0.5.10
274+
# ./scripts/build_change_log.py 0.5.10
264275
new_ver = sys.argv[1]
265276
if len(sys.argv) > 2:
266277
commit = sys.argv[2]

0 commit comments

Comments
 (0)