Skip to content

Commit 701b1f7

Browse files
committed
fix: incorrect branches were compared
1 parent d376dbf commit 701b1f7

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

automation/utils/bin/rui-check-changelogs.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ function compareChangelogContent(change: ChangelogChange): boolean {
4141
const releasedVersionsMatch = compareReleasedVersions(oldReleased, newReleased);
4242

4343
if (!releasedVersionsMatch) {
44-
console.error(` ❌ Released versions have been modified!`);
4544
return false;
4645
}
4746

@@ -58,12 +57,34 @@ function compareChangelogContent(change: ChangelogChange): boolean {
5857
return true;
5958
}
6059

60+
function formatVersion(entry: any): string {
61+
const v = entry.version;
62+
if (!v) {
63+
return entry.type ?? "unknown";
64+
}
65+
return typeof v.format === "function" ? v.format() : String(v);
66+
}
67+
6168
function compareReleasedVersions(oldReleased: any[], newReleased: any[]): boolean {
62-
return JSON.stringify(oldReleased) === JSON.stringify(newReleased);
69+
const newByKey = new Map(newReleased.map(e => [formatVersion(e), JSON.stringify(e)]));
70+
71+
let allMatch = true;
72+
for (const oldEntry of oldReleased) {
73+
const key = formatVersion(oldEntry);
74+
const newStr = newByKey.get(key);
75+
if (newStr === undefined) {
76+
console.error(` ❌ Released version [${key}] was removed.`);
77+
allMatch = false;
78+
} else if (newStr !== JSON.stringify(oldEntry)) {
79+
console.error(` ❌ Released version [${key}] was modified.`);
80+
allMatch = false;
81+
}
82+
}
83+
return allMatch;
6384
}
6485

65-
async function getChangedFiles(headSha: string, mergedTreeSha: string): Promise<string[]> {
66-
const result = await exec(`git diff --name-only ${headSha} ${mergedTreeSha}`, { stdio: "pipe" });
86+
async function getChangedFiles(baseSha: string, mergedTreeSha: string): Promise<string[]> {
87+
const result = await exec(`git diff --name-only ${baseSha} ${mergedTreeSha}`, { stdio: "pipe" });
6788
return result.stdout.trim().split("\n").filter(Boolean);
6889
}
6990

@@ -139,10 +160,9 @@ async function main(): Promise<void> {
139160
}
140161
console.log(`Merged tree SHA: ${mergedTreeSha}`);
141162

142-
// Diff HEAD against the merged tree: only files where both sides had changes
143-
// (requiring a 3-way merge) will appear here. Files exclusively changed in
144-
// the PR branch or exclusively in BASE are not included.
145-
const mergeChangedFiles = await getChangedFiles(head, mergedTreeSha);
163+
// Diff BASE against the merged tree: all files modified by the merge relative
164+
// to main, including files only changed in the PR branch.
165+
const mergeChangedFiles = await getChangedFiles(base, mergedTreeSha);
146166
console.log(`\nFound ${mergeChangedFiles.length} file(s) modified by the merge`);
147167

148168
const changelogFiles = mergeChangedFiles.filter(file => file.endsWith("CHANGELOG.md"));

0 commit comments

Comments
 (0)