Improved: Enhance changelog workflow to handle no changes gracefully … #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Install Ruby and Dependencies | |
run: | | |
sudo apt-get update && sudo apt-get install -y ruby-full subversion | |
sudo gem install github_changelog_generator | |
- name: Generate Changelog | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
github_changelog_generator --user ${{ github.repository_owner }} --project ${{ github.event.repository.name }} | |
# Format the changelog for WordPress | |
awk ' | |
BEGIN { print "== Changelog ==" } | |
{ | |
gsub("## \\[(.*)\\] - (.*)", "= \\1 - \\2 ="); | |
gsub("- ", ""); | |
print; | |
} | |
' CHANGELOG.md > formatted_changelog.txt | |
- name: Update readme.txt | |
run: | | |
# Remove old changelog entries in readme.txt before appending new ones | |
sed -i '/== Changelog ==/,$d' 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 -A | |
git status # Optional for debugging | |
git commit -m "Update changelog for version ${{ github.event.pull_request.head.ref }}" || echo "No changes to commit" | |
git push origin development || echo "Nothing to push" |