Skip to content

Rcskosir add to pr

Rcskosir add to pr #94

name: Update Changelog with new commit
permissions:
pull-requests: write
contents: write
on:
pull_request:
# Inputs the workflow accepts.
types: [closed]
jobs:
pull-commit-message:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
outputs:
message: ${{ steps.pull.outputs.message }}
steps:
- uses: actions/checkout@v4
- name: get merge commit message
id: pull
run: echo message="$(git log --pretty="format:%b")" >> $GITHUB_OUTPUT
# check-for-changelog-entry
changelog-entry:
# if contains to check for bug, enhancement, breaking change, feature
if: ${{ contains(needs.pull-commit-message.outputs.message, '[BUG]') || contains(needs.pull-commit-message.outputs.message, '[ENHANCEMENT]') || contains(needs.pull-commit-message.outputs.message, '[FEATURE]') || contains(needs.pull-commit-message.outputs.message, '[BREAKING]')}}
runs-on: ubuntu-latest
needs: pull-commit-message
outputs:
optIn: ${{ steps.in.outputs.bool }}
entry: ${{ needs.pull-commit-message.outputs.message }}
steps:
- name: changelog entry opt in
id: in
run: echo "opted in to changelog entry" | echo bool="true" >> $GITHUB_OUTPUT
# if there is a changelog entry, check for PR Open
update-changelog:
if: needs.changelog-entry.outputs.optIn
runs-on: ubuntu-latest
needs: changelog-entry
steps:
- name: Check if PR exists
id: check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--json title \
--label "changelog" \
--jq 'length')
if [[ $prs -gt 0 ]]; then
echo "existing=true" >> "$GITHUB_OUTPUT"
fi
- uses: actions/checkout@v4
with:
ref: automated-changelog
- name: Create pull request
#if changelog PR isn't already open, open one
#create a new PR, start with appending the release number and (unreleased)
if: '!steps.check.outputs.existing'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
#new pull request for new release needs the headers all added to the top
echo -e "date (unreleased) header, Bug, Enhancement, Breaking Change, Features headers" >> CHANGELOG.md
git add CHANGELOG.md
git commit -m "Update CHANGELOG.md" -m "${{ needs.changelog-entry.outputs.entry }}"
git push --set-upstream origin automated-changelog
echo "Creating a new pull request"
gh pr create \
--repo "$GITHUB_REPOSITORY" \
--base main \
--head automated-changelog \
-l "changelog" \
-t Changelog
- name: Add commit message to changelog pull request
# at this point a PR is opened for sure, now add entry
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
# place the entry within the correct header
header=$(echo ${{ needs.changelog-entry.outputs.entry }} | sed -n 's/\[\(.*\)\].*/\1/p')
case $header in
BUG)
sed -i "0,^BUG FIXES:$/a\${{ needs.changelog-entry.outputs.entry }}" CHANGELOG.md
;;
ENHANCEMENT)
sed -i "0,^ENHANCEMENTS:$/a\${{ needs.changelog-entry.outputs.entry }}" CHANGELOG.md
;;
BREAKING)
sed -i "0,^BREAKING CHANGES:$/a\${{ needs.changelog-entry.outputs.entry }}" CHANGELOG.md
;;
FEATURE)
sed -i "0,^FEATURES:$/a\${{ needs.changelog-entry.outputs.entry }}" CHANGELOG.md
;;
esac
git add CHANGELOG.md
git commit -m "Update CHANGELOG.md" -m "${{ needs.changelog-entry.outputs.entry }}"
git push --set-upstream origin automated-changelog