-
Notifications
You must be signed in to change notification settings - Fork 11
95 lines (84 loc) · 2.85 KB
/
changelog.yml
File metadata and controls
95 lines (84 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: changelog
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
- edited
- labeled
- unlabeled
permissions:
contents: read
pull-requests: read
jobs:
require-changelog:
runs-on: ubuntu-latest
steps:
- name: Enforce changelog policy
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
if (!pr) {
core.info("No pull request payload found.");
return;
}
if (pr.draft) {
core.notice("Draft PR: changelog enforcement will run again when the PR is marked ready for review.");
return;
}
const labels = new Set((pr.labels || []).map((label) => label.name));
if (labels.has("skip-changelog")) {
core.notice("Skipping changelog check because the PR has the skip-changelog label.");
return;
}
const files = await github.paginate(github.rest.pulls.listFiles, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
per_page: 100,
});
const changedFiles = files.map((file) => file.filename);
if (changedFiles.includes("CHANGELOG.md")) {
core.notice("CHANGELOG.md was updated in this PR.");
return;
}
const exemptFiles = new Set([
"README.md",
"CHANGELOG.md",
"LICENSE",
"mkdocs.yml",
"uv.lock",
".gitignore",
".pre-commit-config.yaml",
]);
const exemptPrefixes = [
".github/",
"docs/",
"tests/",
];
const requiresChangelog = changedFiles.filter((file) => {
if (exemptFiles.has(file)) {
return false;
}
if (exemptPrefixes.some((prefix) => file.startsWith(prefix))) {
return false;
}
return true;
});
if (requiresChangelog.length === 0) {
core.notice("Only docs/tests/CI/internal files changed, so no changelog entry is required.");
return;
}
const details = requiresChangelog.slice(0, 20).map((file) => `- ${file}`).join("\n");
core.setFailed(
[
"This PR changes user-facing or package-relevant files but does not update CHANGELOG.md.",
"Add a changelog entry, or apply the skip-changelog label if the change is intentionally internal.",
"",
"Files that triggered this check:",
details,
].join("\n"),
);