Skip to content

Commit acdf57c

Browse files
theoephraimclaude
andcommitted
Fix check command to only count bump files from current branch
The local `bumpy check` was counting all pending bump files in .bumpy/, so it would pass even if the current branch didn't add one. Now it filters to only bump files added/modified on the branch, matching the CI check behavior. Also extracts shared `filterBranchBumpFiles` helper and fixes empty bump file handling in both local and CI check. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0420415 commit acdf57c

4 files changed

Lines changed: 68 additions & 17 deletions

File tree

.bumpy/fix-check-branch-filter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@varlock/bumpy': patch
3+
---
4+
5+
Fix check command to only count bump files from current branch, and handle empty bump files correctly in both local and CI check

packages/bumpy/src/commands/check.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { relative } from 'node:path';
22
import { log, colorize } from '../utils/logger.ts';
33
import { loadConfig } from '../core/config.ts';
44
import { discoverWorkspace } from '../core/workspace.ts';
5-
import { readBumpFiles } from '../core/bump-file.ts';
5+
import { readBumpFiles, filterBranchBumpFiles } from '../core/bump-file.ts';
66
import { getChangedFiles } from '../core/git.ts';
77
import type { WorkspacePackage } from '../types.ts';
88

@@ -14,17 +14,8 @@ import type { WorkspacePackage } from '../types.ts';
1414
export async function checkCommand(rootDir: string): Promise<void> {
1515
const config = await loadConfig(rootDir);
1616
const { packages } = await discoverWorkspace(rootDir, config);
17-
const bumpFiles = await readBumpFiles(rootDir);
1817

19-
// Find which packages already have bump files
20-
const coveredPackages = new Set<string>();
21-
for (const bf of bumpFiles) {
22-
for (const release of bf.releases) {
23-
coveredPackages.add(release.name);
24-
}
25-
}
26-
27-
// Find which packages have changed on this branch vs base
18+
// Find which files have changed on this branch vs base
2819
const baseBranch = config.baseBranch;
2920
const changedFiles = getChangedFiles(rootDir, baseBranch);
3021

@@ -33,6 +24,25 @@ export async function checkCommand(rootDir: string): Promise<void> {
3324
return;
3425
}
3526

27+
// Filter to only bump files added/modified on this branch
28+
const allBumpFiles = await readBumpFiles(rootDir);
29+
const { branchBumpFiles, branchBumpFileIds } = filterBranchBumpFiles(allBumpFiles, changedFiles);
30+
31+
// If a bump file was changed but didn't parse (empty bump file), the check passes
32+
const hasEmptyBumpFile = branchBumpFileIds.size > branchBumpFiles.length;
33+
if (hasEmptyBumpFile) {
34+
log.success('Empty bump file found — no releases needed.');
35+
return;
36+
}
37+
38+
// Find which packages are covered by bump files on this branch
39+
const coveredPackages = new Set<string>();
40+
for (const bf of branchBumpFiles) {
41+
for (const release of bf.releases) {
42+
coveredPackages.add(release.name);
43+
}
44+
}
45+
3646
const changedPackages = findChangedPackages(changedFiles, packages, rootDir);
3747

3848
if (changedPackages.length === 0) {

packages/bumpy/src/commands/ci.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { log, colorize } from '../utils/logger.ts';
22
import { loadConfig } from '../core/config.ts';
33
import { discoverWorkspace } from '../core/workspace.ts';
44
import { DependencyGraph } from '../core/dep-graph.ts';
5-
import { readBumpFiles } from '../core/bump-file.ts';
5+
import { readBumpFiles, filterBranchBumpFiles } from '../core/bump-file.ts';
66
import { getChangedFiles } from '../core/git.ts';
77
import { assembleReleasePlan } from '../core/release-plan.ts';
88
import { runArgs, runArgsAsync, tryRunArgs } from '../utils/shell.ts';
@@ -107,12 +107,22 @@ export async function ciCheckCommand(rootDir: string, opts: CheckOptions): Promi
107107

108108
// Filter to only bump files added/modified in this PR
109109
const changedFiles = getChangedFiles(rootDir, config.baseBranch);
110-
const prBumpFileIds = new Set(
111-
changedFiles
112-
.filter((f) => /^\.bumpy\/.*\.md$/.test(f) && !f.endsWith('README.md'))
113-
.map((f) => f.replace(/^\.bumpy\//, '').replace(/\.md$/, '')),
110+
const { branchBumpFiles: prBumpFiles, branchBumpFileIds: prBumpFileIds } = filterBranchBumpFiles(
111+
allBumpFiles,
112+
changedFiles,
114113
);
115-
const prBumpFiles = allBumpFiles.filter((bf) => prBumpFileIds.has(bf.id));
114+
115+
// An empty bump file signals intentionally no releases needed
116+
const hasEmptyBumpFile = prBumpFileIds.size > prBumpFiles.length;
117+
118+
if (hasEmptyBumpFile) {
119+
log.success('Empty bump file found — no releases needed.');
120+
if (shouldComment && prNumber) {
121+
const prBranch = detectPrBranch(rootDir);
122+
await postOrUpdatePrComment(prNumber, formatNoBumpFilesComment(prBranch, pm), rootDir, opts.patComments);
123+
}
124+
return;
125+
}
116126

117127
if (prBumpFiles.length === 0) {
118128
const msg = 'No bump files found in this PR.';

packages/bumpy/src/core/bump-file.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,29 @@ function fileToId(filePath: string): string {
172172
const base = filePath.split('/').pop()!;
173173
return base.replace(/\.md$/, '');
174174
}
175+
176+
/**
177+
* Given a list of changed file paths (relative to root), extract the IDs
178+
* of bump files that were added/modified. Shared by `check` and `ci check`.
179+
*/
180+
export function extractBumpFileIdsFromChangedFiles(changedFiles: string[]): Set<string> {
181+
return new Set(
182+
changedFiles
183+
.filter((f) => /^\.bumpy\/.*\.md$/.test(f) && !f.endsWith('README.md'))
184+
.map((f) => f.replace(/^\.bumpy\//, '').replace(/\.md$/, '')),
185+
);
186+
}
187+
188+
/**
189+
* Filter bump files to only those added/modified on the current branch.
190+
* Returns the filtered bump files and whether any changed bump file was
191+
* empty (has no releases — signals intentionally no releases needed).
192+
*/
193+
export function filterBranchBumpFiles(
194+
allBumpFiles: BumpFile[],
195+
changedFiles: string[],
196+
): { branchBumpFiles: BumpFile[]; branchBumpFileIds: Set<string> } {
197+
const branchBumpFileIds = extractBumpFileIdsFromChangedFiles(changedFiles);
198+
const branchBumpFiles = allBumpFiles.filter((bf) => branchBumpFileIds.has(bf.id));
199+
return { branchBumpFiles, branchBumpFileIds };
200+
}

0 commit comments

Comments
 (0)