Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/changelog-pr-guard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Changelog PR Guard

on:
pull_request_target:
branches: [ "main" ]
types: [ opened, synchronize, reopened, ready_for_review ]

permissions:
contents: read
issues: write
pull-requests: read

jobs:
check-changelog:
if: github.event.pull_request.user.login != 'release-please-token-provider[bot]'
runs-on: ubuntu-latest
steps:
- name: Check for changelog changes
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPOSITORY: ${{ github.repository }}
run: |
changed_changelog_files="$(
gh api --paginate "repos/${REPOSITORY}/pulls/${PR_NUMBER}/files" \
--jq '.[] | select(.filename | test("(^|/)CHANGELOG\\.md$"; "i")) | .filename'
)"

if [ -z "${changed_changelog_files}" ]; then
echo "No changelog changes found."
exit 0
fi

comment_body="$(cat <<'EOF'
<!-- changelog-pr-guard -->
The changelog is automatically generated through conventional commits, so this change must be reverted.
EOF
)"

existing_comment_id="$(
gh api --paginate "repos/${REPOSITORY}/issues/${PR_NUMBER}/comments" \
--jq '.[] | select(.user.login == "github-actions[bot]" and (.body | contains("<!-- changelog-pr-guard -->"))) | .id' \
| head -n 1
)"

if [ -n "${existing_comment_id}" ]; then
gh api \
--method PATCH \
"repos/${REPOSITORY}/issues/comments/${existing_comment_id}" \
--field body="${comment_body}" > /dev/null
else
gh api \
--method POST \
"repos/${REPOSITORY}/issues/${PR_NUMBER}/comments" \
--field body="${comment_body}" > /dev/null
fi

echo "Changelog changes must be reverted:"
echo "${changed_changelog_files}"
exit 1
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ If major functionality is being added, or there will need to be gestation time f

Revisions of this nature will result in a 0.X.X change of the version number.

## Changelog updates

The changelog is generated automatically as part of the release process. Do not update `CHANGELOG.md` in pull requests.

## Commit message format

To support our automated release process, pull requests are required to follow the [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/)
Expand Down
Loading