Skip to content

Commit d6ed2c2

Browse files
gregghclaude
andcommitted
Fix: Improve changelog extraction in release workflow
This commit: - Replaces awk-based changelog extraction with more reliable sed approach - Adds debug information to show extracted sections - Uses a temporary file to avoid overwriting the original CHANGELOG.md - Handles cases where the changelog section is at the end of the file 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 52069ac commit d6ed2c2

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

.github/workflows/release.yml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,29 @@ jobs:
6262
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref_type }}" == "tag" ]]; then
6363
# For tag pushes, extract from CHANGELOG.md if it exists
6464
VERSION="${{ steps.get_version.outputs.VERSION }}"
65+
66+
echo "Checking for changelog entry: ## [${VERSION}]"
67+
grep -n "## \[${VERSION}\]" CHANGELOG.md || echo "No exact match found"
68+
6569
if grep -q "## \[${VERSION}\]" CHANGELOG.md; then
6670
echo "Extracting changelog for v${VERSION} from CHANGELOG.md"
67-
CHANGELOG_CONTENT=$(awk -v ver="## [${VERSION}]" '
68-
BEGIN { printing = 0; content = ""; }
69-
$0 ~ ver { printing = 1; next; }
70-
/^## \[/ { if (printing == 1) { printing = 0; } }
71-
{ if (printing == 1) content = content $0 "\n"; }
72-
END { print content; }
73-
' CHANGELOG.md)
71+
72+
# Use sed to extract the changelog section
73+
SECTION_START=$(grep -n "## \[${VERSION}\]" CHANGELOG.md | cut -d: -f1)
74+
NEXT_SECTION=$(tail -n +$((SECTION_START+1)) CHANGELOG.md | grep -n "## \[" | head -1 | cut -d: -f1)
75+
76+
if [ -n "$NEXT_SECTION" ]; then
77+
# Calculate end line
78+
END_LINE=$((SECTION_START + NEXT_SECTION - 1))
79+
# Extract content
80+
CHANGELOG_CONTENT=$(sed -n "$((SECTION_START+1)),$END_LINE p" CHANGELOG.md)
81+
else
82+
# Extract from start to end of file if no next section
83+
CHANGELOG_CONTENT=$(tail -n +$((SECTION_START+1)) CHANGELOG.md)
84+
fi
85+
86+
echo "Extracted changelog content:"
87+
echo "$CHANGELOG_CONTENT"
7488
else
7589
# Fallback to git log if not in CHANGELOG.md
7690
echo "No entry found in CHANGELOG.md, generating from git log"
@@ -87,11 +101,11 @@ jobs:
87101
echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT
88102
echo "EOF" >> $GITHUB_OUTPUT
89103
90-
- name: Create changelog file
104+
- name: Create temporary changelog file for release
91105
run: |
92-
echo "# Changelog for v${{ steps.get_version.outputs.VERSION }}" > CHANGELOG.md
93-
echo "" >> CHANGELOG.md
94-
echo "${{ steps.changelog.outputs.changelog }}" >> CHANGELOG.md
106+
echo "# Changelog for v${{ steps.get_version.outputs.VERSION }}" > TEMP_CHANGELOG.md
107+
echo "" >> TEMP_CHANGELOG.md
108+
echo "${{ steps.changelog.outputs.changelog }}" >> TEMP_CHANGELOG.md
95109
96110
- name: Determine if prerelease
97111
id: prerelease
@@ -112,6 +126,6 @@ jobs:
112126
with:
113127
tag_name: ${{ github.event_name == 'push' && github.ref_type == 'tag' && github.ref_name || format('v{0}', steps.get_version.outputs.VERSION) }}
114128
name: v${{ steps.get_version.outputs.VERSION }}
115-
body_path: CHANGELOG.md
129+
body_path: TEMP_CHANGELOG.md
116130
prerelease: ${{ steps.prerelease.outputs.IS_PRERELEASE }}
117131
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)