-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
build github action to verify changelog entries have been added #36344
Merged
Merged
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 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,155 @@ | ||
# This workflow makes sure contributors don't forget to add a changelog entry or explicitly opt-out of it. | ||
|
||
name: Changelog | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- ready_for_review | ||
- reopened | ||
- synchronize | ||
- labeled | ||
- unlabeled | ||
|
||
# This workflow runs for not-yet-reviewed external contributions and so it | ||
# intentionally has no write access and only limited read access to the | ||
# repository. | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
check-changelog-entry: | ||
name: "Check Changelog Entry" | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: "Changed files" | ||
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 | ||
id: changelog | ||
with: | ||
filters: | | ||
unreleased: | ||
- '.changes/unreleased/*.yaml' | ||
backported: | ||
- '.changes/backported/*.yaml' | ||
changelog: | ||
- 'CHANGELOG.md' | ||
version: | ||
- 'version/VERSION' | ||
|
||
- name: "Check for changelog entry" | ||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
with: | ||
script: | | ||
async function createOrUpdateChangelogComment(commentDetails, deleteComment) { | ||
const commentStart = "## Changelog Warning" | ||
|
||
const body = commentStart + "\n\n" + commentDetails; | ||
const { number: issue_number } = context.issue; | ||
const { owner, repo } = context.repo; | ||
|
||
// List all comments | ||
const allComments = (await github.rest.issues.listComments({ | ||
issue_number, | ||
owner, | ||
repo, | ||
})).data; | ||
|
||
const existingComment = allComments.find(c => c.body.startsWith(commentStart)); | ||
const comment_id = existingComment?.id; | ||
|
||
if (deleteComment) { | ||
if (existingComment) { | ||
await github.rest.issues.deleteComment({ | ||
owner, | ||
repo, | ||
comment_id, | ||
}); | ||
} | ||
return; | ||
} | ||
|
||
core.setFailed(commentDetails); | ||
|
||
if (existingComment) { | ||
await github.rest.issues.updateComment({ | ||
owner, | ||
repo, | ||
comment_id, | ||
body, | ||
}); | ||
} else { | ||
await github.rest.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number, | ||
body, | ||
}); | ||
} | ||
} | ||
|
||
const unreleasedChangesPresent = ${{steps.changelog.outputs.unreleased}}; | ||
const backportedChangesPresent = ${{steps.changelog.outputs.backported}}; | ||
const changelogChangesPresent = ${{steps.changelog.outputs.changelog}}; | ||
const versionChangesPresent = ${{steps.changelog.outputs.version}}; | ||
|
||
const prLabels = await github.rest.issues.listLabelsOnIssue({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo | ||
}); | ||
const backportLabel = prLabels.data.find(label => label.name.includes('-backport')); | ||
const noChangelogNeededLabel = prLabels.data.find(label => label.name === 'no-changelog-needed'); | ||
const dependenciesLabel = prLabels.data.find(label => label.name === 'dependencies'); | ||
|
||
// We want to prohibit contributors from directly changing the CHANGELOG.md, it's | ||
// generated so all changes will be lost during the release process. | ||
// Therefore we only allow the changelog to change together with the version. | ||
// In very rare cases where we generate changes in the changelog without changing the | ||
// version we will just ignore this failing check. | ||
if (changelogChangesPresent && !versionChangesPresent) { | ||
await createOrUpdateChangelogComment("Please don't edit the CHANGELOG.md manually. We use changie to control the Changelog generation, please use `npx changie new` to create a new changelog entry."); | ||
return; | ||
} | ||
|
||
if (dependenciesLabel) { | ||
return; | ||
} | ||
|
||
if (noChangelogNeededLabel) { | ||
if (unreleasedChangesPresent || backportedChangesPresent) { | ||
await createOrUpdateChangelogComment("Please remove either the 'no-changelog-needed' label or the changelog entry from this PR."); | ||
return; | ||
} | ||
|
||
// Nothing to complain about, so delete any existing comment | ||
await createOrUpdateChangelogComment("", true); | ||
return; | ||
} | ||
|
||
if (backportLabel) { | ||
if (unreleasedChangesPresent) { | ||
await createOrUpdateChangelogComment("Please move the changelog entry from `./.changes/unreleased` to `./.changes/backported` for this change. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label."); | ||
return; | ||
} | ||
|
||
if (!backportedChangesPresent) { | ||
await createOrUpdateChangelogComment("Please add a changelog entry to `./.changes/backported` for this change. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label."); | ||
return; | ||
} | ||
} else { | ||
if (backportedChangesPresent) { | ||
await createOrUpdateChangelogComment("Please move the changelog entry from `./.changes/backported` to `./.changes/unreleased` for this change. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label."); | ||
return; | ||
} | ||
|
||
if (!unreleasedChangesPresent) { | ||
await createOrUpdateChangelogComment("Please add a changelog entry to `./.changes/unreleased` for this change. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label."); | ||
return; | ||
} | ||
} | ||
|
||
// Nothing to complain about, so delete any existing comment | ||
await createOrUpdateChangelogComment("", true); |
Oops, something went wrong.
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.
if you wanted to be double sure, the response should also contain the user who made the comment. You could check that is the same user we're executing as now. We can always come back and add this if we find people do start writing comments that start with
## Changelog Warning
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.
Yeah, let's fix this if the need arises 👍 We will probably need to touch this script at some point again when new needs surface :)