Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 11 additions & 3 deletions src/core/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ export async function generateChangelogEntry(options: {
} = options;

// Build compare URL
const compareUrl = previousVersion
? `https://github.com/${owner}/${repo}/compare/${packageName}@${previousVersion}...${packageName}@${version}`
: undefined;
const compareUrl =
previousVersion && previousVersion !== version
? `https://github.com/${owner}/${repo}/compare/${packageName}@${previousVersion}...${packageName}@${version}`
: undefined;

const commitAuthors = await resolveCommitAuthors(commits, githubClient);
const templateGroups = buildTemplateGroups({
Expand Down Expand Up @@ -92,6 +93,13 @@ export async function updateChangelog(options: {
githubClient,
} = options;

if (previousVersion === version) {
logger.verbose(
`Skipping changelog update for ${workspacePackage.name}: version unchanged (${version})`,
);
return;
}

const changelogPath = join(workspacePackage.path, "CHANGELOG.md");

const changelogRelativePath = relative(
Expand Down
7 changes: 7 additions & 0 deletions src/workflows/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ export async function prepareWorkflow(
const changelogPromises = allUpdates
.map((update) => {
return (async () => {
if (update.currentVersion === update.newVersion) {
logger.verbose(
`Skipping changelog for ${update.package.name}: version unchanged (${update.newVersion})`,
);
return;
}

let pkgCommits = groupedPackageCommits.get(update.package.name) || [];
let globalCommits = globalCommitsPerPackage.get(update.package.name) || [];
let previousVersionForChangelog: string | undefined =
Expand Down
42 changes: 41 additions & 1 deletion test/core/changelog.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFile } from "node:fs/promises";
import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";

import { generateChangelogEntry, parseChangelog, updateChangelog } from "#core/changelog";
Expand Down Expand Up @@ -508,4 +508,44 @@ describe("updateChangelog", () => {
expect(content).toContain("add feature A");
expect(content).toContain("add feature B");
});

it("should not rewrite the changelog when version is unchanged", async () => {
const testdirPath = await testdir({});
const context = createChangelogTestContext(testdirPath);

const existingChangelog = dedent`
# @ucdjs/test

## 0.1.0 (2025-01-15)

### Features

* initial release
`;

await writeFile(join(testdirPath, "CHANGELOG.md"), `${existingChangelog}\n`, "utf-8");

mockExec.mockResolvedValueOnce({ stdout: existingChangelog, stderr: "", exitCode: 0 });

await updateChangelog({
normalizedOptions: context.normalizedOptions,
workspacePackage: context.workspacePackage,
version: "0.1.0",
previousVersion: "0.1.0",
commits: [
createCommit({
type: "feat",
message: "feat: this should not be written",
hash: "def456",
shortHash: "def456",
}),
],
date: "2025-01-16",
githubClient: context.githubClient,
});

const content = await readFile(join(testdirPath, "CHANGELOG.md"), "utf-8");

expect(content).toBe(`${existingChangelog}\n`);
});
});