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
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@
},
"dependencies": {
"@conventional-changelog/git-client": "^3.0.1",
"@conventional-changelog/template": "^1.2.0",
"@simple-libs/child-process-utils": "^2.0.0",
"@simple-libs/hosted-git-info": "^2.0.0",
"@simple-libs/stream-utils": "^2.0.0",
"conventional-changelog": "^8.0.0",
"conventional-changelog-conventionalcommits": "^10.0.0",
"conventional-changelog-conventionalcommits": "^10.2.0",
"conventional-changelog-preset-loader": "^6.0.0",
"conventional-recommended-bump": "^12.0.0",
"semver": "^7.5.2"
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/change-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {
createWriteStream
} from 'fs'
import fs from 'fs/promises'
import {
type FinalTemplateContext,
segments
} from '@conventional-changelog/template'
import {
tmpfile,
isFileExists
Expand All @@ -19,6 +23,19 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline

`

export function preamblePartial(
{
preamble,
commitGroups,
noteGroups
}: FinalTemplateContext
) {
return segments(
preamble,
!commitGroups?.length && !noteGroups?.length && 'Version bump without any changes.'
)
Comment thread
Copilot marked this conversation as resolved.
}

/**
* Add release notes to a changelog file.
* @param changelogPath - The path to the changelog file.
Expand Down
32 changes: 32 additions & 0 deletions packages/core/src/project/packageJson.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,38 @@ describe('core', () => {
expect(await fs.readFile(join(cwd, 'CHANGELOG.md'), 'utf8')).toMatch(/## \[2\.(0\.1|1\.0)\]/)
})

it('should add placeholder when generated release notes are empty', async () => {
const { cwd } = await forkProject(
'bump-empty-notes',
packageJsonProject({}, {
postReleaseCommits: false
})
)
const project = new PackageJsonProject({
path: join(cwd, 'package.json')
})
const result = await project.bump({
as: 'patch'
})

expect(result).toBe(true)
expect(project.versionUpdates[0].notes).toContain('Version bump without any changes.')
expect(await fs.readFile(join(cwd, 'CHANGELOG.md'), 'utf8')).toContain('Version bump without any changes.')
})

it('should not add placeholder when generated release notes are not empty', async () => {
const { cwd } = await packageJsonProject()
const project = new PackageJsonProject({
path: join(cwd, 'package.json')
})
const result = await project.bump({
dryRun: true
})

expect(result).toBe(true)
expect(project.versionUpdates[0].notes).not.toContain('Version bump without any changes.')
})

it('should get commit message after bump', async () => {
const { cwd } = await packageJsonProject()
const project = new PackageJsonProject({
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import type { ReleaseData } from '../hosting/index.js'
import {
addReleaseNotes,
extractLastRelease,
extractLastReleaseFromFile
extractLastReleaseFromFile,
preamblePartial
} from '../change-log.js'
import { getReleaseType } from '../utils.js'
import type {
Expand Down Expand Up @@ -298,6 +299,9 @@ export abstract class Project {
.context({
version: nextVersion
})
.writer({
preamblePartial
})
.write()

versionUpdate.notes = dryRun
Expand Down
26 changes: 21 additions & 5 deletions packages/test/src/project.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ export async function forkProject(id: string, srcCtxPromise: ProjectContext | Pr
return ctx
}

export async function packageJsonProject(pkg: Record<string, unknown> = {}) {
export interface PackageJsonProjectOptions {
postReleaseCommits?: boolean
}

export async function packageJsonProject(
pkg: Record<string, unknown> = {},
options: PackageJsonProjectOptions = {}
) {
const { postReleaseCommits = true } = options
const json = JSON.stringify({
name: 'package-json-project',
version: '2.0.0',
Expand All @@ -89,7 +97,10 @@ export async function packageJsonProject(pkg: Record<string, unknown> = {}) {

return createCachedProject(
'package-json-project',
json,
JSON.stringify({
json,
postReleaseCommits
}),
async ({
cwd,
run
Expand All @@ -109,10 +120,15 @@ export async function packageJsonProject(pkg: Record<string, unknown> = {}) {
ctx => dummyCommit(ctx, 'feat'),
({ git }) => git.tag({
name: 'v2.0.0'
}),
ctx => dummyCommit(ctx, 'feat'),
ctx => dummyCommit(ctx, 'fix')
})
])

if (postReleaseCommits) {
await run([
ctx => dummyCommit(ctx, 'feat'),
ctx => dummyCommit(ctx, 'fix')
])
}
}
)
}
Expand Down
Loading