Skip to content

Refactor changelog workflow to improve formatting #13

Refactor changelog workflow to improve formatting

Refactor changelog workflow to improve formatting #13

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 from after the '# Changelog' header
tail -n +$((START_LINE + 1)) CHANGELOG.md > formatted_changelog.txt
# Format the changelog to match the required format
echo "== Changelog ==" > formatted_changelog.txt
# Process each version and format it
while IFS= read -r line; do
# Check if it's a version block
if [[ "$line" =~ ^##\ ([0-9]+\.[0-9]+\.[0-9]+)\ -\ (.*) ]]; then
version="${BASH_REMATCH[1]}"
date="${BASH_REMATCH[2]}"
echo "= $version - $date =" >> formatted_changelog.txt
# Check if it's a changelog item
elif [[ "$line" =~ ^- (.*) ]]; then
echo "- ${BASH_REMATCH[1]}" >> formatted_changelog.txt
fi
done < formatted_changelog.txt
# Show the 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 formatted_changelog.txt file
if [ -f "formatted_changelog.txt" ]; then
rm formatted_changelog.txt
fi