Skip to content

Commit e9b90bb

Browse files
Merge pull request #28 from lucaromagnoli/fix/pipeline-merge
fix: improve release notes generation and changelog handling
2 parents b6f4cec + bd5bf8b commit e9b90bb

File tree

3 files changed

+82
-18
lines changed

3 files changed

+82
-18
lines changed

.github/workflows/code-quality.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Code Quality
22

33
on:
4-
push:
5-
branches: [ main, develop ]
64
pull_request:
75
branches: [ main, develop ]
86

.github/workflows/release.yml

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,54 @@ jobs:
228228
run: |
229229
VERSION="${{ needs.validate-version.outputs.version }}"
230230
231+
echo "Looking for version $VERSION in changelog..."
232+
233+
# Debug: show what we're looking for
234+
echo "Searching for pattern: ## [$VERSION]"
235+
231236
# Extract release notes from CHANGELOG.md
232237
if grep -q "## \[$VERSION\]" CHANGELOG.md; then
238+
echo "Found version $VERSION in changelog, extracting content..."
239+
233240
# Get the content between the version header and the next version or end
241+
# Use a more robust awk script that handles the format better
234242
RELEASE_NOTES=$(awk -v version="$VERSION" '
235-
/^## \[' version '\]/ { in_version=1; next }
236-
/^## \[/ && in_version { exit }
237-
in_version { print }
238-
' CHANGELOG.md | sed '1d') # Remove the first line (date)
243+
BEGIN { in_version = 0; content = "" }
244+
/^## \[' version '\]/ {
245+
in_version = 1
246+
next
247+
}
248+
/^## \[/ && in_version {
249+
exit
250+
}
251+
in_version && /^###/ {
252+
content = content "\n" $0
253+
}
254+
in_version && /^[[:space:]]*-/ {
255+
content = content "\n" $0
256+
}
257+
in_version && /^[[:space:]]*$/ && content != "" {
258+
content = content "\n"
259+
}
260+
END {
261+
if (content != "") {
262+
print content
263+
} else {
264+
print "No detailed changes found for this version."
265+
}
266+
}
267+
' CHANGELOG.md)
268+
269+
# Clean up the content
270+
RELEASE_NOTES=$(echo "$RELEASE_NOTES" | sed '/^[[:space:]]*$/d' | head -20)
239271
240272
# Add header
241273
RELEASE_NOTES="## 🚀 What's Changed\n\n$RELEASE_NOTES"
274+
275+
echo "Extracted release notes:"
276+
echo "$RELEASE_NOTES"
242277
else
278+
echo "Version $VERSION not found in changelog, using fallback..."
243279
# Fallback if changelog section not found
244280
RELEASE_NOTES="## 🚀 Release $VERSION\n\nThis release includes various improvements and bug fixes.\n\n**Full Changelog**: https://github.com/${{ github.repository }}/releases/tag/v$VERSION"
245281
fi

scripts/update-changelog.py

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,52 @@ def update_changelog(self) -> None:
164164

165165
# Update or create changelog file
166166
if Path(self.changelog_file).exists():
167-
# Insert new content after header
167+
# Read existing content
168168
with open(self.changelog_file, 'r') as f:
169169
lines = f.readlines()
170170

171-
# Find where to insert (after header)
172-
insert_pos = 0
173-
for i, line in enumerate(lines):
174-
if line.startswith('# Changelog'):
175-
insert_pos = i + 1
176-
break
177-
178-
# Insert new content
179-
new_lines = lines[:insert_pos] + ['\n'] + [new_content] + ['\n'] + lines[insert_pos:]
171+
# Check if [Unreleased] section already exists
172+
unreleased_exists = any('## [Unreleased]' in line for line in lines)
180173

181-
with open(self.changelog_file, 'w') as f:
182-
f.writelines(new_lines)
174+
if unreleased_exists:
175+
# Find and replace the existing [Unreleased] section
176+
new_lines = []
177+
in_unreleased = False
178+
skip_until_next_section = False
179+
180+
for line in lines:
181+
if line.startswith('## [Unreleased]'):
182+
in_unreleased = True
183+
skip_until_next_section = True
184+
# Replace with new content
185+
new_lines.append(new_content)
186+
continue
187+
188+
if in_unreleased and line.startswith('## ['):
189+
in_unreleased = False
190+
skip_until_next_section = False
191+
new_lines.append(line)
192+
continue
193+
194+
if not skip_until_next_section:
195+
new_lines.append(line)
196+
197+
# Write back the updated content
198+
with open(self.changelog_file, 'w') as f:
199+
f.writelines(new_lines)
200+
else:
201+
# Insert new content after header
202+
insert_pos = 0
203+
for i, line in enumerate(lines):
204+
if line.startswith('# Changelog'):
205+
insert_pos = i + 1
206+
break
207+
208+
# Insert new content
209+
new_lines = lines[:insert_pos] + ['\n'] + [new_content] + ['\n'] + lines[insert_pos:]
210+
211+
with open(self.changelog_file, 'w') as f:
212+
f.writelines(new_lines)
183213
else:
184214
# Create new changelog file
185215
header = """# Changelog

0 commit comments

Comments
 (0)