Skip to content

Commit 09b36f2

Browse files
authored
Merge duplicate breaking change headings in release notes (#2776)
1 parent 287900c commit 09b36f2

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

.github/workflows/release-draft.yaml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,39 @@ jobs:
249249
fi
250250
251251
# Build final release body using printf to avoid YAML parsing issues
252+
# Merge breaking changes sections with same headings
252253
FINAL_BC=""
253254
if [ -n "$BC_CONTENT" ] && [ -n "$EXISTING_BC" ]; then
254-
FINAL_BC=$(printf '## Breaking Changes\n\n%s\n\n%s' "$EXISTING_BC" "$BC_CONTENT")
255+
# Merge sections with same ### headings to avoid duplicates
256+
# Preserves blank lines inside fenced code blocks
257+
MERGED_BC=$(printf '%s\n\n%s' "$EXISTING_BC" "$BC_CONTENT" | awk '
258+
BEGIN { current_section = ""; in_fence = 0; }
259+
/^```/ || /^~~~/ { in_fence = !in_fence; }
260+
/^### / && !in_fence {
261+
current_section = $0;
262+
if (!(current_section in sections)) {
263+
order[++order_count] = current_section;
264+
}
265+
next;
266+
}
267+
/^[[:space:]]*$/ && !in_fence { next; }
268+
current_section != "" {
269+
if (sections[current_section] != "") {
270+
sections[current_section] = sections[current_section] "\n" $0;
271+
} else {
272+
sections[current_section] = $0;
273+
}
274+
}
275+
END {
276+
for (i = 1; i <= order_count; i++) {
277+
section = order[i];
278+
if (i > 1) print "";
279+
print section;
280+
print sections[section];
281+
}
282+
}
283+
')
284+
FINAL_BC=$(printf '## Breaking Changes\n\n%s' "$MERGED_BC")
255285
elif [ -n "$BC_CONTENT" ]; then
256286
FINAL_BC=$(printf '## Breaking Changes\n\n%s' "$BC_CONTENT")
257287
elif [ -n "$EXISTING_BC" ]; then

0 commit comments

Comments
 (0)