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
18 changes: 18 additions & 0 deletions dist/version-dispatch/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/version-dispatch/index.js.map

Large diffs are not rendered by default.

149 changes: 149 additions & 0 deletions src/version-dispatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,53 @@ describe('versionDispatch', () => {
})
})

it('skips private packages when computing the dispatch payload', async () => {
fs = createFsFromJSON({
'lerna.json': lernaConfig,
'libraries/atoms/package.json': JSON.stringify({ name: '@exodus/atoms', private: true }),
'libraries/wallet/package.json': JSON.stringify({ name: '@exodus/wallet' }),
'modules/blockchain-metadata/package.json': JSON.stringify({
name: '@exodus/blockchain-metadata',
}),
'modules/balances/package.json': JSON.stringify({ name: '@exodus/balances' }),
})

github.context.payload = {
pull_request: {
title: 'feat: cool stuff',
number: 123,
merged: true,
user: { login: 'brucewayne' },
base: { ref },
labels: [],
},
}

setupPaginate(
[
{ sha: 'aaa1111', commit: { message: 'feat(atoms)!: drop legacy' } },
{ sha: 'bbb2222', commit: { message: 'fix(balances): tidy' } },
],
{
aaa1111: [{ filename: 'libraries/atoms/index.ts' }],
bbb2222: [{ filename: 'modules/balances/x.ts' }],
}
)

await versionDispatch({ filesystem: fs as never })

expect(client.rest.actions.createWorkflowDispatch).toHaveBeenCalledWith({
...repo,
ref,
workflow_id: workflowId,
inputs: {
assignee: 'brucewayne',
packages: '@exodus/balances',
bumps: JSON.stringify({ '@exodus/balances': 'patch' }),
},
})
})

it('falls back to the PR title when no commit carries a bump', async () => {
github.context.payload = {
pull_request: {
Expand Down Expand Up @@ -412,6 +459,108 @@ describe('versionDispatch', () => {
expect(client.rest.issues.createComment).not.toHaveBeenCalled()
})

it('omits private packages from the preview comment', async () => {
fs = createFsFromJSON({
'lerna.json': lernaConfigWithVersions,
'libraries/atoms/package.json': JSON.stringify({
name: '@exodus/atoms',
version: '1.0.0',
private: true,
}),
'libraries/wallet/package.json': JSON.stringify({
name: '@exodus/wallet',
version: '3.4.5',
}),
'modules/blockchain-metadata/package.json': JSON.stringify({
name: '@exodus/blockchain-metadata',
version: '0.1.0',
}),
'modules/balances/package.json': JSON.stringify({
name: '@exodus/balances',
version: '2.7.9',
}),
})

github.context.payload = {
pull_request: {
title: 'feat: pending',
number: 555,
merged: false,
state: 'open',
user: { login: 'brucewayne' },
base: { ref },
labels: [],
},
}

setupPreviewPaginate(
[
{ sha: 'aaa1111', commit: { message: 'feat(atoms)!: drop legacy' } },
{ sha: 'bbb2222', commit: { message: 'fix(balances): tidy' } },
],
{
aaa1111: [{ filename: 'libraries/atoms/index.ts' }],
bbb2222: [{ filename: 'modules/balances/x.ts' }],
}
)

await versionDispatch({ filesystem: fs as never })

expect(client.rest.issues.createComment).toHaveBeenCalledTimes(1)
const [args] = (client.rest.issues.createComment as unknown as jest.Mock).mock.calls[0]
expect(args.body).toContain('@exodus/balances')
expect(args.body).not.toContain('@exodus/atoms')
})

it('clears stale preview comments when every touched package is private', async () => {
fs = createFsFromJSON({
'lerna.json': lernaConfigWithVersions,
'libraries/atoms/package.json': JSON.stringify({
name: '@exodus/atoms',
version: '1.0.0',
private: true,
}),
'libraries/wallet/package.json': JSON.stringify({
name: '@exodus/wallet',
version: '3.4.5',
}),
'modules/blockchain-metadata/package.json': JSON.stringify({
name: '@exodus/blockchain-metadata',
version: '0.1.0',
}),
'modules/balances/package.json': JSON.stringify({
name: '@exodus/balances',
version: '2.7.9',
}),
})

github.context.payload = {
pull_request: {
title: 'feat: pending',
number: 555,
merged: false,
state: 'open',
user: { login: 'brucewayne' },
base: { ref },
labels: [],
},
}

setupPreviewPaginate(
[{ sha: 'aaa1111', commit: { message: 'feat(atoms)!: drop legacy' } }],
{ aaa1111: [{ filename: 'libraries/atoms/index.ts' }] },
[{ id: 9200, body: `${PREVIEW_MARKER}\nstale preview from before private flag was set` }]
)

await versionDispatch({ filesystem: fs as never })

expect(client.rest.issues.deleteComment).toHaveBeenCalledWith({
...repo,
comment_id: 9200,
})
expect(client.rest.issues.createComment).not.toHaveBeenCalled()
})

it('clears stale comments and posts nothing when no commits bump anything', async () => {
github.context.payload = {
pull_request: {
Expand Down
24 changes: 24 additions & 0 deletions src/version-dispatch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as path from 'path'
import * as core from '@actions/core'
import * as github from '@actions/github'
import * as fs from 'fs'
Expand Down Expand Up @@ -115,6 +116,13 @@ export async function versionDispatch({ filesystem = fs }: Params = {}) {
prTitle: pr.title,
})

for (const name of Object.keys(bumps)) {
if (isPrivatePackage({ filesystem, pkgPath: packagePaths[name] })) {
core.info(`skip ${name}: private package`)
delete bumps[name]
}
}

const packageNames = Object.keys(bumps)
core.setOutput('packages', packageNames.join(','))
core.setOutput('bumps', JSON.stringify(bumps))
Expand Down Expand Up @@ -300,3 +308,19 @@ export function aggregateBumps({
function firstLine(message: string): string {
return message.split(/\r?\n/, 1)[0] ?? ''
}

function isPrivatePackage({
filesystem,
pkgPath,
}: {
filesystem: Filesystem
pkgPath: string | undefined
}): boolean {
if (!pkgPath) return false
try {
const raw = filesystem.readFileSync(path.join(pkgPath, 'package.json'), 'utf8') as string
return (JSON.parse(raw) as { private?: unknown }).private === true
} catch {
return false
}
}
Loading