Skip to content

Commit 6365fa4

Browse files
authored
Fix change log generation (#1788)
1 parent ea3274a commit 6365fa4

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

.github/workflows/changelog-generation.yml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,37 @@ jobs:
107107
if [ "${{ steps.check_changelog.outputs.exists }}" == "true" ]; then
108108
# Insert new entry after the header
109109
if [ -f "new-changelog-entry.md" ]; then
110-
# Create temp file with header, new entry, and existing content
111-
echo "# Changelog" > temp-changelog.md
112-
echo "" >> temp-changelog.md
113-
cat new-changelog-entry.md >> temp-changelog.md
114-
echo "" >> temp-changelog.md
115-
# Skip the header line and add existing content
116-
tail -n +3 CHANGELOG.md >> temp-changelog.md
110+
# Create a temporary file
111+
touch temp-changelog.md
112+
113+
# Process the file line by line
114+
header_found=false
115+
first_version_found=false
116+
117+
while IFS= read -r line; do
118+
if [[ "$line" =~ ^#[[:space:]]Changelog ]]; then
119+
# Found the header
120+
echo "$line" >> temp-changelog.md
121+
echo "" >> temp-changelog.md
122+
header_found=true
123+
elif [[ "$header_found" == "true" && "$first_version_found" == "false" && "$line" =~ ^##[[:space:]]\[ ]]; then
124+
# Found the first version entry, insert new content before it
125+
cat new-changelog-entry.md >> temp-changelog.md
126+
echo "" >> temp-changelog.md
127+
echo "$line" >> temp-changelog.md
128+
first_version_found=true
129+
else
130+
# Copy all other lines as-is
131+
echo "$line" >> temp-changelog.md
132+
fi
133+
done < CHANGELOG.md
134+
135+
# If no version entries were found (empty changelog), append the new entry
136+
if [[ "$first_version_found" == "false" && "$header_found" == "true" ]]; then
137+
cat new-changelog-entry.md >> temp-changelog.md
138+
fi
139+
140+
# Replace the original file
117141
mv temp-changelog.md CHANGELOG.md
118142
fi
119143
else

.github/workflows/release.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ jobs:
5454
if [ -f "CHANGELOG.md" ]; then
5555
# Extract the changelog section for this version
5656
# Find the start of this version's section and the start of the next version
57+
echo "Looking for version: $VERSION"
5758
START_LINE=$(grep -n "## \[$VERSION\]" CHANGELOG.md | cut -d: -f1 | head -1)
59+
5860
if [ -n "$START_LINE" ]; then
61+
echo "Found version at line: $START_LINE"
5962
# Find the next version section or end of file
6063
NEXT_LINE=$(tail -n +$((START_LINE + 1)) CHANGELOG.md | grep -n "^## \[" | head -1 | cut -d: -f1)
6164
if [ -n "$NEXT_LINE" ]; then
@@ -66,13 +69,17 @@ jobs:
6669
tail -n +$START_LINE CHANGELOG.md > version-changelog.md
6770
fi
6871
69-
echo "RELEASE_NOTES<<EOF" >> $GITHUB_OUTPUT
72+
# Use a unique delimiter that won't appear in changelog content
73+
delimiter="END_OF_RELEASE_NOTES_$(date +%s)"
74+
echo "RELEASE_NOTES<<$delimiter" >> $GITHUB_OUTPUT
7075
cat version-changelog.md >> $GITHUB_OUTPUT
71-
echo "EOF" >> $GITHUB_OUTPUT
76+
echo "$delimiter" >> $GITHUB_OUTPUT
7277
else
78+
echo "Version $VERSION not found in CHANGELOG.md"
7379
echo "RELEASE_NOTES=## Release v$VERSION" >> $GITHUB_OUTPUT
7480
fi
7581
else
82+
echo "CHANGELOG.md not found"
7683
echo "RELEASE_NOTES=## Release v$VERSION" >> $GITHUB_OUTPUT
7784
fi
7885

0 commit comments

Comments
 (0)