Skip to content

Update update_changelog.yml #13

Update update_changelog.yml

Update update_changelog.yml #13

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 }}
fetch-depth: 0
# Prevent later git operations from reusing the same authentication
persist-credentials: false
- 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
- uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.LE_BOT_APP_ID }}
private_key: ${{ secrets.LE_BOT_PRIVATE_KEY }}
- name: Commit updated CHANGELOG.md
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add CHANGELOG.md
git commit -m "Update CHANGELOG.md for PR #${{ github.event.pull_request.number }}"
- name: Push changes
uses: ad-m/github-push-action@v0.8.0
with:
github_token: ${{ steps.generate-token.outputs.token }}
branch: ${{ github.event.pull_request.base.ref }}