Skip to content

Refactor changelog workflow to simplify formatting and update push ta… #12

Refactor changelog workflow to simplify formatting and update push ta…

Refactor changelog workflow to simplify formatting and update push ta… #12

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 Formatted Changelog
run: |
# Check if CHANGELOG.md exists
if [ ! -f "CHANGELOG.md" ]; then
echo "CHANGELOG.md file not found"
exit 1
fi
# Extract changelog starting 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
tail -n +$((START_LINE + 1)) CHANGELOG.md > formatted_changelog.txt
echo "Generated 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
echo "== Changelog ==" >> readme.txt
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 formatted_changelog.txt file
if [ -f "formatted_changelog.txt" ]; then
rm formatted_changelog.txt
fi