Skip to content

Commit 6feb0a9

Browse files
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 <[email protected]> --------- Co-authored-by: Daniel Schmidt <[email protected]>
1 parent 27686c4 commit 6feb0a9

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

.github/workflows/changelog.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# This workflow makes sure contributors don't forget to add a changelog entry or explicitly opt-out of it.
2+
3+
name: Changelog
4+
5+
on:
6+
pull_request_target:
7+
types:
8+
- opened
9+
- ready_for_review
10+
- reopened
11+
- synchronize
12+
- labeled
13+
- unlabeled
14+
15+
# This workflow runs for not-yet-reviewed external contributions and so it
16+
# intentionally has no write access and only limited read access to the
17+
# repository.
18+
19+
permissions:
20+
contents: read
21+
pull-requests: write
22+
23+
jobs:
24+
check-changelog-entry:
25+
name: "Check Changelog Entry"
26+
runs-on: ubuntu-latest
27+
concurrency:
28+
group: changelog-${{ github.head_ref }}
29+
cancel-in-progress: true
30+
31+
steps:
32+
- name: "Changed files"
33+
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
34+
id: changelog
35+
with:
36+
filters: |
37+
changelog:
38+
- 'CHANGELOG.md'
39+
40+
- name: "Check for changelog entry"
41+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
42+
with:
43+
script: |
44+
async function createOrUpdateChangelogComment(commentDetails, deleteComment) {
45+
const commentStart = "## Changelog Warning"
46+
47+
const body = commentStart + "\n\n" + commentDetails;
48+
const { number: issue_number } = context.issue;
49+
const { owner, repo } = context.repo;
50+
51+
// List all comments
52+
const allComments = (await github.rest.issues.listComments({
53+
issue_number,
54+
owner,
55+
repo,
56+
})).data;
57+
58+
const existingComment = allComments.find(c => c.body.startsWith(commentStart));
59+
const comment_id = existingComment?.id;
60+
61+
if (deleteComment) {
62+
if (existingComment) {
63+
await github.rest.issues.deleteComment({
64+
owner,
65+
repo,
66+
comment_id,
67+
});
68+
}
69+
return;
70+
}
71+
72+
core.setFailed(commentDetails);
73+
74+
if (existingComment) {
75+
await github.rest.issues.updateComment({
76+
owner,
77+
repo,
78+
comment_id,
79+
body,
80+
});
81+
} else {
82+
await github.rest.issues.createComment({
83+
owner,
84+
repo,
85+
issue_number,
86+
body,
87+
});
88+
}
89+
}
90+
91+
const changelogChangesPresent = ${{steps.changelog.outputs.changelog}};
92+
93+
const prLabels = await github.rest.issues.listLabelsOnIssue({
94+
issue_number: context.issue.number,
95+
owner: context.repo.owner,
96+
repo: context.repo.repo
97+
});
98+
const noChangelogNeededLabel = prLabels.data.find(label => label.name === 'no-changelog-needed');
99+
100+
if (noChangelogNeededLabel) {
101+
if (changelogChangesPresent) {
102+
await createOrUpdateChangelogComment("Please remove either the 'no-changelog-needed' label or the changelog entry from this PR.");
103+
return;
104+
}
105+
await createOrUpdateChangelogComment("", true);
106+
return;
107+
}
108+
109+
if (!changelogChangesPresent) {
110+
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.");
111+
return;
112+
}
113+
114+
// Nothing to complain about, so delete any existing comment
115+
await createOrUpdateChangelogComment("", true);

0 commit comments

Comments
 (0)