Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions .github/workflows/changelog-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
- name: Validate changelog entry
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
set -euo pipefail

Expand Down Expand Up @@ -60,25 +59,17 @@ jobs:
exit 1
fi

pr_pattern="(#${PR_NUMBER})"
if ! printf '%s\n' "${added_lines}" | grep -Fq "${pr_pattern}"; then
echo "CHANGELOG.md entry must reference this PR as ${pr_pattern}."
exit 1
fi

node <<'NODE'
const { execSync } = require("node:child_process");
const fs = require("node:fs");

const base = process.env.BASE_REF;
const pr = process.env.PR_NUMBER;
const diff = execSync(`git diff --unified=0 origin/${base}...HEAD -- CHANGELOG.md`, {
encoding: "utf8",
});
const changelog = fs.readFileSync("CHANGELOG.md", "utf8").split(/\r?\n/);
const prToken = `(#${pr})`;
let currentLine = 0;
const addedPrLines = [];
const addedLines = [];

for (const line of diff.split(/\r?\n/)) {
if (line.startsWith("@@ ")) {
Expand All @@ -91,9 +82,7 @@ jobs:
}
if (line.startsWith("+")) {
const text = line.slice(1);
if (text.includes(prToken)) {
addedPrLines.push({ line: currentLine, text });
}
addedLines.push({ line: currentLine, text });
Comment on lines 83 to +85
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Exclude subsection headers from changelog entry validation

This change now records every added CHANGELOG.md line and validates each as if it were an entry line. In an empty ## Unreleased block (a common post-release state), adding the first subsection header like ### Features will fail because that header has no preceding ### to satisfy the subsection lookup, triggering Changelog PR entry must be inside a ### subsection. As a result, valid PRs can be blocked even when they add a properly formatted entry under ## Unreleased.

Useful? React with 👍 / 👎.

if (currentLine > 0) currentLine += 1;
continue;
}
Expand All @@ -103,12 +92,12 @@ jobs:
if (currentLine > 0) currentLine += 1;
}

if (addedPrLines.length === 0) {
console.error(`No added CHANGELOG.md line references ${prToken}.`);
if (addedLines.length === 0) {
console.error("No added CHANGELOG.md lines found.");
process.exit(1);
}

for (const entry of addedPrLines) {
for (const entry of addedLines) {
let release = "";
let subsection = "";
for (let i = entry.line - 1; i >= 0; i -= 1) {
Expand Down
Loading