Skip to content

Commit 785869e

Browse files
committed
fix: only update changelogs when version is different
1 parent 13faf03 commit 785869e

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

src/core/changelog.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function generateChangelogEntry(options: {
4343
} = options;
4444

4545
// Build compare URL
46-
const compareUrl = previousVersion
46+
const compareUrl = previousVersion && previousVersion !== version
4747
? `https://github.com/${owner}/${repo}/compare/${packageName}@${previousVersion}...${packageName}@${version}`
4848
: undefined;
4949

@@ -92,6 +92,13 @@ export async function updateChangelog(options: {
9292
githubClient,
9393
} = options;
9494

95+
if (previousVersion === version) {
96+
logger.verbose(
97+
`Skipping changelog update for ${workspacePackage.name}: version unchanged (${version})`,
98+
);
99+
return;
100+
}
101+
95102
const changelogPath = join(workspacePackage.path, "CHANGELOG.md");
96103

97104
const changelogRelativePath = relative(

src/workflows/prepare.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ export async function prepareWorkflow(
183183
const changelogPromises = allUpdates
184184
.map((update) => {
185185
return (async () => {
186+
if (update.currentVersion === update.newVersion) {
187+
logger.verbose(
188+
`Skipping changelog for ${update.package.name}: version unchanged (${update.newVersion})`,
189+
);
190+
return;
191+
}
192+
186193
let pkgCommits = groupedPackageCommits.get(update.package.name) || [];
187194
let globalCommits = globalCommitsPerPackage.get(update.package.name) || [];
188195
let previousVersionForChangelog: string | undefined =

test/core/changelog.test.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFile } from "node:fs/promises";
1+
import { readFile, writeFile } from "node:fs/promises";
22
import { join } from "node:path";
33

44
import { generateChangelogEntry, parseChangelog, updateChangelog } from "#core/changelog";
@@ -508,4 +508,44 @@ describe("updateChangelog", () => {
508508
expect(content).toContain("add feature A");
509509
expect(content).toContain("add feature B");
510510
});
511+
512+
it("should not rewrite the changelog when version is unchanged", async () => {
513+
const testdirPath = await testdir({});
514+
const context = createChangelogTestContext(testdirPath);
515+
516+
const existingChangelog = dedent`
517+
# @ucdjs/test
518+
519+
## 0.1.0 (2025-01-15)
520+
521+
### Features
522+
523+
* initial release
524+
`;
525+
526+
await writeFile(join(testdirPath, "CHANGELOG.md"), `${existingChangelog}\n`, "utf-8");
527+
528+
mockExec.mockResolvedValueOnce({ stdout: existingChangelog, stderr: "", exitCode: 0 });
529+
530+
await updateChangelog({
531+
normalizedOptions: context.normalizedOptions,
532+
workspacePackage: context.workspacePackage,
533+
version: "0.1.0",
534+
previousVersion: "0.1.0",
535+
commits: [
536+
createCommit({
537+
type: "feat",
538+
message: "feat: this should not be written",
539+
hash: "def456",
540+
shortHash: "def456",
541+
}),
542+
],
543+
date: "2025-01-16",
544+
githubClient: context.githubClient,
545+
});
546+
547+
const content = await readFile(join(testdirPath, "CHANGELOG.md"), "utf-8");
548+
549+
expect(content).toBe(`${existingChangelog}\n`);
550+
});
511551
});

0 commit comments

Comments
 (0)