-
-
Notifications
You must be signed in to change notification settings - Fork 239
ci: Add CI enforcement to prevent manual CHANGELOG.md edits #3075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
szokeasaurusrex
wants to merge
1
commit into
auto-changelog
Choose a base branch
from
szokeasaurusrex/changelog-md-enforcement
base: auto-changelog
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+87
−2
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| name: Changelog Enforcement | ||
|
|
||
| on: | ||
| workflow_call: | ||
|
|
||
| jobs: | ||
| check-changelog: | ||
| name: Check Changelog Changes | ||
| runs-on: ubuntu-24.04 | ||
| if: ${{ github.event_name == 'pull_request' }} | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: Check for CHANGELOG.md modifications | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # 8.0.0 | ||
| with: | ||
| script: | | ||
| const prNumber = context.payload.pull_request.number; | ||
| const prTitle = context.payload.pull_request.title; | ||
| const isChangelogPR = prTitle.startsWith('meta(changelog):'); | ||
|
|
||
| const { data: files } = await github.rest.pulls.listFiles({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: prNumber, | ||
| per_page: 100 | ||
| }); | ||
|
|
||
| const changelogModified = files.some(file => file.filename === 'CHANGELOG.md'); | ||
|
|
||
| console.log(`PR Title: ${prTitle}`); | ||
| console.log(`Is Changelog PR: ${isChangelogPR}`); | ||
| console.log(`CHANGELOG.md Modified: ${changelogModified}`); | ||
|
|
||
| if (changelogModified && !isChangelogPR) { | ||
| const commentBody = `## :warning: Manual Changelog Changes Detected | ||
|
|
||
| This PR modifies \`CHANGELOG.md\`, but the PR title does not start with \`meta(changelog):\`. | ||
|
|
||
| **Changelogs in this repository are generated automatically during releases.** Manual edits to \`CHANGELOG.md\` are not allowed in regular PRs. | ||
|
|
||
| ### What to do: | ||
|
|
||
| 1. **If this change is intentional**: Create a separate PR with a title starting with \`meta(changelog):\` to make changelog edits. | ||
|
|
||
| 2. **If this was unintentional**: Remove the \`CHANGELOG.md\` changes from this PR.`; | ||
|
|
||
| // Avoid posting duplicate comments on re-runs | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing pagination may cause duplicate warning commentsLow Severity The |
||
|
|
||
| const botComment = comments.find(comment => | ||
| comment.user.type === 'Bot' && | ||
| comment.body.includes('Manual Changelog Changes Detected') | ||
| ); | ||
|
|
||
| if (!botComment) { | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| body: commentBody | ||
| }); | ||
| console.log('Posted comment explaining changelog policy'); | ||
| } else { | ||
| console.log('Comment already exists, skipping'); | ||
| } | ||
|
|
||
| core.setFailed('CHANGELOG.md changes are not allowed unless PR title starts with "meta(changelog):"'); | ||
| } else if (changelogModified && isChangelogPR) { | ||
| console.log('CHANGELOG.md changes allowed in meta(changelog): PR'); | ||
| } else { | ||
| console.log('No CHANGELOG.md changes detected'); | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing pagination allows CHANGELOG.md bypass in large PRs
Medium Severity
The
listFilescall only fetches the first 100 files without handling pagination. If a PR modifies more than 100 files andCHANGELOG.mdis not in the first page of results, the enforcement check will fail to detect it and allow the PR to merge without proper validation. This silently bypasses the intended changelog protection mechanism.