You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
modified = {l for l in open('modified_files.txt').read().splitlines() if l}
52
+
pr_body = open('pr_body.txt').read()
53
+
54
+
# Parse NO_CHANGELOG directive from the PR body.
55
+
# NO_CHANGELOG=true -> skip every package.
56
+
# NO_CHANGELOG=<pkg1>,<pkg2>,... -> skip only the listed packages.
57
+
skip_all = False
58
+
skip_packages = set()
59
+
m = re.search(r'NO_CHANGELOG=(\S+)', pr_body)
60
+
if m:
61
+
val = m.group(1).strip()
62
+
if val == 'true':
63
+
skip_all = True
64
+
else:
65
+
skip_packages = {p.strip().rstrip('/') for p in val.split(',') if p.strip()}
66
+
67
+
if skip_all:
68
+
print("NO_CHANGELOG=true found in PR body. Skipping check.")
69
+
sys.exit(0)
70
+
71
+
# Discover packages the same way tagging.py does: any directory that
72
+
# contains a .package.json is a release unit with its own changelog.
73
+
packages = []
74
+
for dirpath, dirnames, filenames in os.walk('.'):
75
+
dirnames[:] = [d for d in dirnames if d not in ('.git', 'node_modules', 'dist')]
76
+
if '.package.json' in filenames:
77
+
rel = os.path.relpath(dirpath, '.')
78
+
packages.append('' if rel == '.' else rel)
79
+
80
+
# Sub-package prefixes so a root-level package doesn't double-count
81
+
# files that live under a nested package.
82
+
sub_prefixes = tuple(p + '/' for p in packages if p)
69
83
70
-
- name: Comment on PR with instructions if needed
71
-
if: failure() # This step will only run if the previous step fails (i.e., if NEXT_CHANGELOG.md was not modified and NO_CHANGELOG=true was not in the PR message)
84
+
# For each package with modified files (excluding its own bookkeeping
85
+
# files), require that its NEXT_CHANGELOG.md was also modified.
86
+
missing = []
87
+
for pkg in packages:
88
+
prefix = pkg + '/' if pkg else ''
89
+
next_changelog = prefix + 'NEXT_CHANGELOG.md'
90
+
changelog = prefix + 'CHANGELOG.md'
91
+
package_file = prefix + '.package.json'
92
+
in_pkg = [
93
+
f for f in modified
94
+
if (not pkg or f.startswith(prefix))
95
+
and f not in (changelog, package_file)
96
+
]
97
+
if not pkg:
98
+
in_pkg = [f for f in in_pkg if not f.startswith(sub_prefixes)]
99
+
if not in_pkg:
100
+
continue
101
+
if next_changelog not in modified:
102
+
missing.append((pkg or '.', next_changelog))
103
+
104
+
# Honor per-package NO_CHANGELOG overrides.
105
+
missing = [(pkg, chg) for pkg, chg in missing if pkg not in skip_packages]
106
+
107
+
if missing:
108
+
# Build the PR comment body and also emit it to the workflow log
109
+
# so failures are debuggable without clicking into the PR.
110
+
lines = [
111
+
"<!-- NEXT_CHANGELOG_INSTRUCTIONS -->",
112
+
"One or more packages were modified without updating their `NEXT_CHANGELOG.md`:",
113
+
"",
114
+
]
115
+
for pkg, chg in missing:
116
+
lines.append(f"- `{pkg}` — expected a change to `{chg}`")
117
+
lines.append("")
118
+
lines.append("If this is intentional, add one of the following to the PR description and rerun this job:")
119
+
lines.append("")
120
+
lines.append("- `NO_CHANGELOG=true` — skip the check for every package.")
121
+
suggested = ",".join(pkg for pkg, _ in missing)
122
+
lines.append(f"- `NO_CHANGELOG={suggested}` — skip only the packages listed above.")
123
+
body = "\n".join(lines) + "\n"
124
+
with open('pr_comment.md', 'w') as f:
125
+
f.write(body)
126
+
sys.stdout.write(body)
127
+
sys.exit(1)
128
+
129
+
print("All modified packages have NEXT_CHANGELOG.md entries.")
130
+
PYEOF
131
+
132
+
- name: Comment on PR with the list of missing packages
133
+
if: failure() # Only runs if the verify step failed.
72
134
env:
73
135
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74
136
run: |
75
-
# Check if a comment exists with the instructions
137
+
# Replace any previous instructions comment so the list reflects the
138
+
# current PR state instead of accumulating stale entries.
76
139
previous_comment_ids=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
if: success() #This step will only run if the previous check passed (i.e., if NEXT_CHANGELOG.md was modified or NO_CHANGELOG=true is in the PR message)
148
+
if: success() #Only runs if the verify step passed.
93
149
env:
94
150
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95
151
run: |
96
-
# Check if there is a previous instructions comment
152
+
# Clean up any previous instructions comment now that the check is
153
+
# green.
97
154
previous_comment_ids=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
0 commit comments