Skip to content

Commit 0fc9487

Browse files
committed
fix(auto-release-notes.py): fix duplicate blank-line
Signed-off-by: samzong <[email protected]>
1 parent 716e633 commit 0fc9487

File tree

2 files changed

+50
-34
lines changed

2 files changed

+50
-34
lines changed

.github/workflows/auto-release-notes.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ jobs:
2727
- name: Install dependencies
2828
run: pip install requests pandas pyyaml jq
2929

30+
- name: Show auto-release-notes.py
31+
run: |
32+
echo "==== scripts/auto-release-notes.py ===="
33+
cat scripts/auto-release-notes.py
34+
3035
- name: Prepare branch
3136
id: prepare_branch
3237
run: |

scripts/auto-release-notes.py

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ def get_release_info(data, filename="rel-notes.md"):
195195
"无更新类型": "",
196196
}
197197

198-
# 定义模板
199198
header_template = Template(
200199
dedent(
201200
"""\
@@ -217,49 +216,61 @@ def get_release_info(data, filename="rel-notes.md"):
217216
entry_with_baseline_template = Template("- [$primary_func] $baseline")
218217
entry_without_baseline_template = Template("- [$primary_func]")
219218

220-
def ensure_blank_line(lines_list):
221-
if lines_list and lines_list[-1] != "":
219+
def emit(lines_list, line=""):
220+
line = "" if line is None else line
221+
if line == "":
222+
if lines_list and lines_list[-1] == "":
223+
return
222224
lines_list.append("")
225+
else:
226+
lines_list.append(line.rstrip())
223227

224228
lines = header_template.substitute().splitlines()
225-
ensure_blank_line(lines)
226229

227230
for pub_date, modules in result.items():
228-
ensure_blank_line(lines)
229-
lines.append(pub_date_template.substitute(pub_date=pub_date))
230-
ensure_blank_line(lines)
231+
emit(lines, "")
232+
emit(lines, pub_date_template.substitute(pub_date=pub_date))
233+
emit(lines, "")
231234
for module, versions in modules.items():
232235
for version, update_types in versions.items():
233-
lines.append(
234-
module_version_template.substitute(module=module, version=version)
236+
emit(
237+
lines,
238+
module_version_template.substitute(module=module, version=version),
235239
)
236-
ensure_blank_line(lines)
240+
emit(lines, "")
237241
for update_type in ["新功能", "增强优化", "故障修复", "无更新类型"]:
238-
if update_type in update_types:
239-
entries = update_types[update_type]
240-
if update_type != "无更新类型":
241-
lines.append(
242-
update_type_template.substitute(
243-
emoji_title=emoji_map[update_type]
244-
)
242+
if update_type not in update_types:
243+
continue
244+
entries = update_types[update_type]
245+
if not entries:
246+
continue
247+
if update_type != "无更新类型":
248+
emit(
249+
lines,
250+
update_type_template.substitute(
251+
emoji_title=emoji_map[update_type]
252+
),
253+
)
254+
emit(lines, "")
255+
for primary_func, entry in entries:
256+
baseline = entry.get("基线参数", "")
257+
if baseline:
258+
emit(
259+
lines,
260+
entry_with_baseline_template.substitute(
261+
primary_func=primary_func, baseline=baseline
262+
),
245263
)
246-
ensure_blank_line(lines)
247-
for primary_func, entry in entries:
248-
baseline = entry.get("基线参数", "")
249-
if baseline:
250-
lines.append(
251-
entry_with_baseline_template.substitute(
252-
primary_func=primary_func, baseline=baseline
253-
)
254-
)
255-
else:
256-
lines.append(
257-
entry_without_baseline_template.substitute(
258-
primary_func=primary_func
259-
)
260-
)
261-
ensure_blank_line(lines)
262-
if lines and lines[-1] == "":
264+
else:
265+
emit(
266+
lines,
267+
entry_without_baseline_template.substitute(
268+
primary_func=primary_func
269+
),
270+
)
271+
emit(lines, "")
272+
273+
while lines and lines[-1] == "":
263274
lines.pop()
264275

265276
md_content = "\n".join(lines) + "\n"

0 commit comments

Comments
 (0)