-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Github action and automated changelog using changie (#1055)
* add changie file * add script and github action * remove changie * Delete header.tpl.md * Delete .gitkeep * Update changelog.yml * Update changelog.yml * Update .github/workflows/changelog.yml Co-authored-by: Daniel Schmidt <danielmschmidt92@gmail.com> --------- Co-authored-by: Daniel Schmidt <danielmschmidt92@gmail.com>
- Loading branch information
1 parent
27686c4
commit 6feb0a9
Showing
1 changed file
with
115 additions
and
0 deletions.
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,115 @@ | ||
# This workflow makes sure contributors don't forget to add a changelog entry or explicitly opt-out of it. | ||
|
||
name: Changelog | ||
|
||
on: | ||
pull_request_target: | ||
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 | ||
concurrency: | ||
group: changelog-${{ github.head_ref }} | ||
cancel-in-progress: true | ||
|
||
steps: | ||
- name: "Changed files" | ||
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 | ||
id: changelog | ||
with: | ||
filters: | | ||
changelog: | ||
- 'CHANGELOG.md' | ||
- 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 changelogChangesPresent = ${{steps.changelog.outputs.changelog}}; | ||
const prLabels = await github.rest.issues.listLabelsOnIssue({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo | ||
}); | ||
const noChangelogNeededLabel = prLabels.data.find(label => label.name === 'no-changelog-needed'); | ||
if (noChangelogNeededLabel) { | ||
if (changelogChangesPresent) { | ||
await createOrUpdateChangelogComment("Please remove either the 'no-changelog-needed' label or the changelog entry from this PR."); | ||
return; | ||
} | ||
await createOrUpdateChangelogComment("", true); | ||
return; | ||
} | ||
if (!changelogChangesPresent) { | ||
await createOrUpdateChangelogComment("Please add a changelog entry to `CHANGELOG.md` 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); |