8282 echo "EOF" >> $GITHUB_OUTPUT
8383
8484 - name : Bump version and update CHANGELOG.md
85+ env :
86+ VERSION : ${{ steps.version.outputs.version }}
8587 run : |
86- VERSION="${{ steps.version.outputs.version }}"
8788 DATE=$(date +%Y-%m-%d)
8889 git config user.name "github-actions[bot]"
8990 git config user.email "github-actions[bot]@users.noreply.github.com"
9596 # Bump version.php
9697 sed -i "s/'current' => '.*'/'current' => '${VERSION}'/" backend/config/version.php
9798
98- # Update CHANGELOG.md — replace [Unreleased] header with version + date, add new Unreleased
99+ # Update CHANGELOG.md
99100 if [ -f CHANGELOG.md ]; then
100- # Build changelog entry from conventional commits
101101 PREV_TAG=$(git tag --sort=-v:refname | grep -v "^${VERSION}$" | head -1 || echo "")
102102 FEATURES=""
103103 FIXES=""
@@ -106,25 +106,33 @@ jobs:
106106 FIXES=$(git log "${PREV_TAG}..HEAD" --pretty=format:"%s" --no-merges | grep -E "^fix" | sed 's/^fix[^:]*: /- /' || true)
107107 fi
108108
109- # Build the new entry
110- ENTRY="## [${VERSION}] - ${DATE}\n"
109+ # Build entry file
110+ echo "## [${VERSION}] - ${DATE}" > /tmp/changelog_entry.md
111+ echo "" >> /tmp/changelog_entry.md
111112 if [ -n "$FEATURES" ]; then
112- ENTRY="${ENTRY}\n### Added\n${FEATURES}\n"
113+ echo "### Added" >> /tmp/changelog_entry.md
114+ echo "$FEATURES" >> /tmp/changelog_entry.md
115+ echo "" >> /tmp/changelog_entry.md
113116 fi
114117 if [ -n "$FIXES" ]; then
115- ENTRY="${ENTRY}\n### Fixed\n${FIXES}\n"
118+ echo "### Fixed" >> /tmp/changelog_entry.md
119+ echo "$FIXES" >> /tmp/changelog_entry.md
120+ echo "" >> /tmp/changelog_entry.md
116121 fi
117122
118- # Insert after the [Unreleased] section marker
119- sed -i "/^## \[Unreleased\]/,/^## \[/ {
120- /^## \[Unreleased\]/! {
121- /^## \[/ i\\
122- ${ENTRY}
123- }
124- }" CHANGELOG.md
125-
126- # Update comparison links
127- sed -i "s|\[Unreleased\] : .*|[Unreleased]: https://github.com/Mes-Open/OpenMes/compare/${VERSION}...develop|" CHANGELOG.md
123+ # Insert after [Unreleased] section using python for reliability
124+ python3 -c "
125+ import re, sys
126+ entry = open('/tmp/changelog_entry.md').read()
127+ content = open('CHANGELOG.md').read()
128+ # Insert before the first ## [x.y.z] line (after [Unreleased] content)
129+ pattern = r'(## \[Unreleased\].*?\n(?:.*?\n)*?)\n(## \[)'
130+ replacement = r'\1\n' + entry + r'\2'
131+ result = re.sub(pattern, replacement, content, count=1)
132+ # Update unreleased link
133+ result = re.sub(r'\[Unreleased\] : .*', '[Unreleased]: https://github.com/Mes-Open/OpenMes/compare/${VERSION}...develop', result)
134+ open('CHANGELOG.md', 'w').write(result)
135+ " || echo " CHANGELOG update skipped"
128136
129137 git add CHANGELOG.md
130138 fi
0 commit comments