Skip to content

Update update_changelog.yml #6

Update update_changelog.yml

Update update_changelog.yml #6

name: Update Changelog.md
on:
pull_request_target:
types:
- closed
jobs:
update-changelog:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Extract and update Changelog
id: modify-changelog
run: |
if [ "${{ github.event.pull_request.user.login }}" == "dependabot[bot]" ]; then
changelog="- **Description:** ${{ github.event.pull_request.title }}\n - **Products impact:** Dev Dependency upgrade\n - **Addresses:** -\n - **Components:** -\n - **Breaking:** -\n - **Impacts a11y:** -\n - **Guidance:** -"
else
description=$(jq -r ".pull_request.body" "$GITHUB_EVENT_PATH")
changelog_section=$(echo "$description" | awk '/<!-- \[DO NOT REMOVE-USED BY GH ACTION\] CHANGELOG START -->/{flag=1; next} /<!-- \[DO NOT REMOVE-USED BY GH ACTION\] CHANGELOG END -->/{flag=0} flag' | sed '/<!--/,/-->/d')
changelog="${changelog_section}"
fi
pr_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
pr_link="[#${pr_number}]"
pr_link_ref="[#${pr_number}]: ${{ github.event.pull_request.html_url }}"
while IFS= read -r entry; do
if [[ $entry == *"- **Description:"* ]]; then
echo -e "- ${pr_link}\n"
fi
echo -e "\t${entry}"
if [[ $entry == *"- **Guidance:"* ]]; then
echo -e "\n${pr_link_ref}\n"
fi
done <<< "$changelog_section" > pr_info.txt
awk '/<!-- \[DO NOT REMOVE-USED BY GH ACTION\] PASTE CHANGELOG -->/{print; system("cat pr_info.txt"); next} 1' CHANGELOG.md > tmpfile && mv tmpfile CHANGELOG.md
- name: Commit updated CHANGELOG.md
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: ${{ github.event.pull_request.base.ref }}
commit_message: "Update CHANGELOG.md for PR #${{ github.event.pull_request.number }}"
file_pattern: CHANGELOG.md