Skip to content

Commit 393f3c6

Browse files
exo-mvclaude
andauthored
fix(version-dispatch): skip private packages in preview and dispatch (#87)
Private workspace packages (`"private": true` in package.json) are not published, so they should never appear in the preview comment or be sent to the version workflow. Drop them from the bumps map immediately after computation so both the sticky preview comment and the dispatched inputs are clean. If every touched package is private the existing empty-bumps path takes over: stale preview comments get cleared and no workflow dispatch happens. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c54869e commit 393f3c6

4 files changed

Lines changed: 192 additions & 1 deletion

File tree

dist/version-dispatch/index.js

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/version-dispatch/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/version-dispatch.spec.ts

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,53 @@ describe('versionDispatch', () => {
163163
})
164164
})
165165

166+
it('skips private packages when computing the dispatch payload', async () => {
167+
fs = createFsFromJSON({
168+
'lerna.json': lernaConfig,
169+
'libraries/atoms/package.json': JSON.stringify({ name: '@exodus/atoms', private: true }),
170+
'libraries/wallet/package.json': JSON.stringify({ name: '@exodus/wallet' }),
171+
'modules/blockchain-metadata/package.json': JSON.stringify({
172+
name: '@exodus/blockchain-metadata',
173+
}),
174+
'modules/balances/package.json': JSON.stringify({ name: '@exodus/balances' }),
175+
})
176+
177+
github.context.payload = {
178+
pull_request: {
179+
title: 'feat: cool stuff',
180+
number: 123,
181+
merged: true,
182+
user: { login: 'brucewayne' },
183+
base: { ref },
184+
labels: [],
185+
},
186+
}
187+
188+
setupPaginate(
189+
[
190+
{ sha: 'aaa1111', commit: { message: 'feat(atoms)!: drop legacy' } },
191+
{ sha: 'bbb2222', commit: { message: 'fix(balances): tidy' } },
192+
],
193+
{
194+
aaa1111: [{ filename: 'libraries/atoms/index.ts' }],
195+
bbb2222: [{ filename: 'modules/balances/x.ts' }],
196+
}
197+
)
198+
199+
await versionDispatch({ filesystem: fs as never })
200+
201+
expect(client.rest.actions.createWorkflowDispatch).toHaveBeenCalledWith({
202+
...repo,
203+
ref,
204+
workflow_id: workflowId,
205+
inputs: {
206+
assignee: 'brucewayne',
207+
packages: '@exodus/balances',
208+
bumps: JSON.stringify({ '@exodus/balances': 'patch' }),
209+
},
210+
})
211+
})
212+
166213
it('falls back to the PR title when no commit carries a bump', async () => {
167214
github.context.payload = {
168215
pull_request: {
@@ -412,6 +459,108 @@ describe('versionDispatch', () => {
412459
expect(client.rest.issues.createComment).not.toHaveBeenCalled()
413460
})
414461

462+
it('omits private packages from the preview comment', async () => {
463+
fs = createFsFromJSON({
464+
'lerna.json': lernaConfigWithVersions,
465+
'libraries/atoms/package.json': JSON.stringify({
466+
name: '@exodus/atoms',
467+
version: '1.0.0',
468+
private: true,
469+
}),
470+
'libraries/wallet/package.json': JSON.stringify({
471+
name: '@exodus/wallet',
472+
version: '3.4.5',
473+
}),
474+
'modules/blockchain-metadata/package.json': JSON.stringify({
475+
name: '@exodus/blockchain-metadata',
476+
version: '0.1.0',
477+
}),
478+
'modules/balances/package.json': JSON.stringify({
479+
name: '@exodus/balances',
480+
version: '2.7.9',
481+
}),
482+
})
483+
484+
github.context.payload = {
485+
pull_request: {
486+
title: 'feat: pending',
487+
number: 555,
488+
merged: false,
489+
state: 'open',
490+
user: { login: 'brucewayne' },
491+
base: { ref },
492+
labels: [],
493+
},
494+
}
495+
496+
setupPreviewPaginate(
497+
[
498+
{ sha: 'aaa1111', commit: { message: 'feat(atoms)!: drop legacy' } },
499+
{ sha: 'bbb2222', commit: { message: 'fix(balances): tidy' } },
500+
],
501+
{
502+
aaa1111: [{ filename: 'libraries/atoms/index.ts' }],
503+
bbb2222: [{ filename: 'modules/balances/x.ts' }],
504+
}
505+
)
506+
507+
await versionDispatch({ filesystem: fs as never })
508+
509+
expect(client.rest.issues.createComment).toHaveBeenCalledTimes(1)
510+
const [args] = (client.rest.issues.createComment as unknown as jest.Mock).mock.calls[0]
511+
expect(args.body).toContain('@exodus/balances')
512+
expect(args.body).not.toContain('@exodus/atoms')
513+
})
514+
515+
it('clears stale preview comments when every touched package is private', async () => {
516+
fs = createFsFromJSON({
517+
'lerna.json': lernaConfigWithVersions,
518+
'libraries/atoms/package.json': JSON.stringify({
519+
name: '@exodus/atoms',
520+
version: '1.0.0',
521+
private: true,
522+
}),
523+
'libraries/wallet/package.json': JSON.stringify({
524+
name: '@exodus/wallet',
525+
version: '3.4.5',
526+
}),
527+
'modules/blockchain-metadata/package.json': JSON.stringify({
528+
name: '@exodus/blockchain-metadata',
529+
version: '0.1.0',
530+
}),
531+
'modules/balances/package.json': JSON.stringify({
532+
name: '@exodus/balances',
533+
version: '2.7.9',
534+
}),
535+
})
536+
537+
github.context.payload = {
538+
pull_request: {
539+
title: 'feat: pending',
540+
number: 555,
541+
merged: false,
542+
state: 'open',
543+
user: { login: 'brucewayne' },
544+
base: { ref },
545+
labels: [],
546+
},
547+
}
548+
549+
setupPreviewPaginate(
550+
[{ sha: 'aaa1111', commit: { message: 'feat(atoms)!: drop legacy' } }],
551+
{ aaa1111: [{ filename: 'libraries/atoms/index.ts' }] },
552+
[{ id: 9200, body: `${PREVIEW_MARKER}\nstale preview from before private flag was set` }]
553+
)
554+
555+
await versionDispatch({ filesystem: fs as never })
556+
557+
expect(client.rest.issues.deleteComment).toHaveBeenCalledWith({
558+
...repo,
559+
comment_id: 9200,
560+
})
561+
expect(client.rest.issues.createComment).not.toHaveBeenCalled()
562+
})
563+
415564
it('clears stale comments and posts nothing when no commits bump anything', async () => {
416565
github.context.payload = {
417566
pull_request: {

src/version-dispatch.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as path from 'path'
12
import * as core from '@actions/core'
23
import * as github from '@actions/github'
34
import * as fs from 'fs'
@@ -115,6 +116,13 @@ export async function versionDispatch({ filesystem = fs }: Params = {}) {
115116
prTitle: pr.title,
116117
})
117118

119+
for (const name of Object.keys(bumps)) {
120+
if (isPrivatePackage({ filesystem, pkgPath: packagePaths[name] })) {
121+
core.info(`skip ${name}: private package`)
122+
delete bumps[name]
123+
}
124+
}
125+
118126
const packageNames = Object.keys(bumps)
119127
core.setOutput('packages', packageNames.join(','))
120128
core.setOutput('bumps', JSON.stringify(bumps))
@@ -300,3 +308,19 @@ export function aggregateBumps({
300308
function firstLine(message: string): string {
301309
return message.split(/\r?\n/, 1)[0] ?? ''
302310
}
311+
312+
function isPrivatePackage({
313+
filesystem,
314+
pkgPath,
315+
}: {
316+
filesystem: Filesystem
317+
pkgPath: string | undefined
318+
}): boolean {
319+
if (!pkgPath) return false
320+
try {
321+
const raw = filesystem.readFileSync(path.join(pkgPath, 'package.json'), 'utf8') as string
322+
return (JSON.parse(raw) as { private?: unknown }).private === true
323+
} catch {
324+
return false
325+
}
326+
}

0 commit comments

Comments
 (0)