Skip to content

Refactor changelog workflow to enhance changelog generation #14

Refactor changelog workflow to enhance changelog generation

Refactor changelog workflow to enhance changelog generation #14

Workflow file for this run

name: Update Plugin Changelog
on:
pull_request:
types:
- closed
jobs:
update-changelog:
if: github.event.pull_request.merged == true
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Generate and Format Changelog
run: |
# Check if CHANGELOG.md exists
if [ ! -f "CHANGELOG.md" ]; then
echo "CHANGELOG.md file not found"
exit 1
fi
# Extract the changelog section from '# Changelog'
START_LINE=$(grep -n "^# Changelog" CHANGELOG.md | cut -d':' -f1)
if [ -z "$START_LINE" ]; then
echo "No '# Changelog' section found in CHANGELOG.md"
exit 1
fi
# Get the changelog content from after the '# Changelog' header
tail -n +$((START_LINE + 1)) CHANGELOG.md > changelog_temp.txt
# Format the changelog using awk
awk '
BEGIN { print "== Changelog ==" }
{
gsub("## \\[(.*)\\] - (.*)", "= \\1 - \\2 =");
gsub("- ", "");
print;
}
' changelog_temp.txt > formatted_changelog.txt
echo "Generated and formatted changelog:"
cat formatted_changelog.txt
- name: Update readme.txt
run: |
# Check if readme.txt exists
if [ ! -f "readme.txt" ]; then
echo "readme.txt file not found"
exit 1
fi
# Remove existing '== Changelog ==' and everything below it
sed -i '/== Changelog ==/,$d' readme.txt
# Add the new changelog content
cat formatted_changelog.txt >> readme.txt
- name: Commit and Push Changes to GitHub
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "github-actions@github.com"
git add readme.txt
git commit -m "Update changelog after merging PR #${{ github.event.pull_request.number }}" || echo "No changes to commit"
git push origin development || echo "Nothing to push"
- name: Cleanup formatted changelog
run: |
# Delete the temporary changelog files
if [ -f "formatted_changelog.txt" ]; then
rm formatted_changelog.txt
fi
if [ -f "changelog_temp.txt" ]; then
rm changelog_temp.txt
fi