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
10 changes: 9 additions & 1 deletion 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.

29 changes: 25 additions & 4 deletions dist/version/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/index.js.map

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions src/version-dispatch/preview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PREVIEW_MARKER,
renderPreviewComment,
} from './preview'
import { BUMP_MAJOR, BUMP_MINOR, BUMP_PATCH } from './bumps'
import { BUMP_MAJOR, BUMP_MINOR, BUMP_PATCH, type Bump } from './bumps'

jest.mock('@actions/core', () => ({
info: jest.fn(),
Expand Down Expand Up @@ -48,8 +48,15 @@ describe('nextVersion', () => {
expect(nextVersion('1.2.3', BUMP_PATCH)).toBe('1.2.4')
})

it('releases a pre-release to its base version on a patch bump', () => {
expect(nextVersion('1.2.3-rc.4', BUMP_PATCH)).toBe('1.2.3')
it.each<[string, Bump, string]>([
['1.2.3-rc.4', BUMP_MAJOR, '1.2.3-rc.5'],
['1.2.3-rc.4', BUMP_MINOR, '1.2.3-rc.5'],
['1.2.3-rc.4', BUMP_PATCH, '1.2.3-rc.5'],
['5.0.0-rc.96', BUMP_MAJOR, '5.0.0-rc.97'],
['5.0.0-rc.96', BUMP_PATCH, '5.0.0-rc.97'],
['1.0.0-alpha.0', BUMP_MAJOR, '1.0.0-alpha.1'],
])('keeps prerelease bumps in the rc cycle: %s + %s → %s', (current, bump, expected) => {
expect(nextVersion(current, bump)).toBe(expected)
})

it('returns input when the version is unparseable', () => {
Expand Down
11 changes: 10 additions & 1 deletion src/version-dispatch/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,16 @@ function readVersion({
}

export function nextVersion(current: string, bump: Bump): string {
return semverInc(current, bump as ReleaseType) ?? current
// While a package is in a prerelease cycle (`5.0.0-rc.96`), bump the
// prerelease counter rather than dropping the rc — a `feat!:` commit
// shouldn't accidentally promote a long-lived rc to a stable release.
// The caller can promote to stable via a separate workflow when ready.
const effectiveBump = isPrerelease(current) ? 'prerelease' : (bump as ReleaseType)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: dedupe

return semverInc(current, effectiveBump) ?? current
}

function isPrerelease(version: string): boolean {
return version.includes('-')
}

export function renderPreviewComment(rows: PreviewRow[]): string {
Expand Down
60 changes: 60 additions & 0 deletions src/version/version-packages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,66 @@ describe('versionPackagesExplicit', () => {
).rejects.toThrow(/not present in `packages`/)
})

describe('prerelease handling', () => {
it.each([
['5.0.0-rc.96', 'major', '5.0.0-rc.97'],
['5.0.0-rc.96', 'minor', '5.0.0-rc.97'],
['5.0.0-rc.96', 'patch', '5.0.0-rc.97'],
['1.0.0-alpha.0', 'major', '1.0.0-alpha.1'],
['2.0.0-beta.3', 'patch', '2.0.0-beta.4'],
])(
'bumps the rc counter on %s + %s → %s instead of dropping the prerelease',
async (current, bump, expected) => {
const pkgDir = writePackageJson('headless', { name: '@exodus/headless', version: current })

await versionPackagesExplicit({
bumps: { '@exodus/headless': bump },
packages: [pkgDir],
})

const after = JSON.parse(fs.readFileSync(path.join(pkgDir, 'package.json'), 'utf8'))
expect(after.version).toBe(expected)
}
)

it('does not walk consumer pins when bumping a prerelease (the rc counter bump is not a major change)', async () => {
const headlessDir = writePackageJson('sdks/headless', {
name: '@exodus/headless',
version: '5.0.0-rc.96',
})
const consumerDir = writePackageJson('apps/wallet', {
name: '@exodus/wallet-app',
version: '1.0.0',
dependencies: { '@exodus/headless': '^5.0.0-rc.0' },
})

mockGetPaths.mockResolvedValue({
'@exodus/headless': headlessDir,
'@exodus/wallet-app': consumerDir,
})

await versionPackagesExplicit({
bumps: { '@exodus/headless': 'major' },
packages: [headlessDir],
})

const consumer = JSON.parse(fs.readFileSync(path.join(consumerDir, 'package.json'), 'utf8'))
expect(consumer.dependencies['@exodus/headless']).toBe('^5.0.0-rc.0')
})

it('uses the regular semver.inc path for stable versions (5.0.0 + major → 6.0.0)', async () => {
const pkgDir = writePackageJson('headless', { name: '@exodus/headless', version: '5.0.0' })

await versionPackagesExplicit({
bumps: { '@exodus/headless': 'major' },
packages: [pkgDir],
})

const after = JSON.parse(fs.readFileSync(path.join(pkgDir, 'package.json'), 'utf8'))
expect(after.version).toBe('6.0.0')
})
})

it('throws when semver.inc rejects the bump level', async () => {
const pkgDir = writePackageJson('mab', { name: '@exodus/mab', version: '1.0.0' })

Expand Down
33 changes: 29 additions & 4 deletions src/version/version-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ type ExplicitParams = {
* package.json from the supplied `packages` list,
* 2. compute the next version via `semver.inc(current, bump)` and rewrite
* the `"version"` field in package.json in place (preserving every
* other byte — formatting, trailing newlines, key order),
* other byte — formatting, trailing newlines, key order). When the
* current version is itself a prerelease (`5.0.0-rc.96`), the bump
* is downgraded to `prerelease` so the rc counter advances
* (`5.0.0-rc.97`) — a commit-driven `major` bump shouldn't promote
* a long-lived rc to a stable release; the team must do that via
* a separate workflow.
* 3. on major bumps only, rewrite the bumped package's pin in every
* workspace package.json that uses a semver range. Minor and patch
* bumps don't need a rewrite — the existing caret/tilde range
Expand Down Expand Up @@ -107,14 +112,30 @@ export async function versionPackagesExplicit({
throw new Error(`Cannot read version from package.json for ${pkgName}`)
}

const next = semverInc(before.version, bump as ReleaseType)
// While a package is in a prerelease cycle (`5.0.0-rc.96`), any
// commit-driven bump (`major`/`minor`/`patch`) should bump the rc
// counter rather than drop the prerelease. A `feat!:` on a long-lived
// rc shouldn't accidentally promote it to a stable release — the team
// must promote via a separate workflow when they're ready.
const effectiveBump: ReleaseType = isPrerelease(before.version)
? 'prerelease'
: (bump as ReleaseType)

const next = semverInc(before.version, effectiveBump)
if (!next) {
throw new Error(
`semver.inc rejected bump for ${pkgName}: ${before.version} + "${bump}". Valid bumps: major, minor, patch, premajor, preminor, prepatch, prerelease.`
`semver.inc rejected bump for ${pkgName}: ${before.version} + "${effectiveBump}". Valid bumps: major, minor, patch, premajor, preminor, prepatch, prerelease.`
)
}

if (effectiveBump === bump) {
core.info(`Bumping ${pkgName}: ${before.version} → ${next} (${bump}) in ${pkgDir}`)
} else {
core.info(
`Bumping ${pkgName}: ${before.version} → ${next} (requested ${bump}; downgraded to ${effectiveBump} because current is a prerelease) in ${pkgDir}`
)
}

core.info(`Bumping ${pkgName}: ${before.version} → ${next} (${bump}) in ${pkgDir}`)
writeVersionField({ pkgDir, next })

const updatedConsumers = isMajorBump(before.version, next)
Expand Down Expand Up @@ -237,6 +258,10 @@ function isMajorBump(oldVersion: string, newVersion: string): boolean {
return oldVersion.split('.')[0] !== newVersion.split('.')[0]
}

function isPrerelease(version: string): boolean {
return version.includes('-')
}

const NON_SEMVER_PREFIXES = ['workspace:', 'npm:', 'file:', 'link:', 'portal:']

function shouldRewriteRange(value: string): boolean {
Expand Down
Loading