Skip to content

Commit 3fc7d17

Browse files
devjiwonchoiijjkeps1lon
authored
[release] create empty changeset for next when no changeset found during canary release (vercel#79049)
### Why? When there are no changesets for `next`, the canary release won't be published even if there are new commits. If this is the case, add an empty changeset for `next` to let the canary release proceed. Note that this will result in an empty Changelog and GitHub Release, but this PR does not cover handling that part. ### Testing Plan Set env `RELEASE_TYPE=canary` and run `ci:version` locally to see the result. --------- Co-authored-by: JJ Kasper <jj@jjsweb.site> Co-authored-by: Sebastian "Sebbie" Silbermann <sebastian.silbermann@vercel.com>
1 parent 85c6b3a commit 3fc7d17

File tree

1 file changed

+65
-4
lines changed

1 file changed

+65
-4
lines changed

scripts/release/version-packages.ts

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
import execa from 'execa'
2-
import { existsSync } from 'node:fs'
3-
import { join } from 'node:path'
2+
import { existsSync } from 'fs'
3+
import { writeFile, readFile, unlink } from 'fs/promises'
4+
import { join } from 'path'
5+
6+
// NOTE: This type may change over time.
7+
type ChangesetStatusJson = {
8+
changesets: {
9+
releases: {
10+
name: string
11+
type: string
12+
summary: string
13+
id: string
14+
}[]
15+
}[]
16+
releases: {
17+
name: string
18+
type: string
19+
oldVersion: string
20+
changesets: string[]
21+
newVersion: string
22+
}[]
23+
}
424

525
async function versionPackages() {
626
const preConfigPath = join(process.cwd(), '.changeset', 'pre.json')
@@ -23,13 +43,54 @@ async function versionPackages() {
2343
await execa('pnpm', ['changeset', 'pre', 'enter', 'canary'], {
2444
stdio: 'inherit',
2545
})
26-
// TODO: Create empty changeset for `next` to bump canary version
27-
// even if there is no changeset.
46+
47+
console.log(
48+
'▲ Preparing to bump the canary version, checking if there are any changesets.'
49+
)
50+
51+
// Create an empty changeset for `next` to bump the canary version
52+
// even if there are no changesets for `next`.
53+
await execa('pnpm', [
54+
'changeset',
55+
'status',
56+
'--output',
57+
'./changeset-status.json',
58+
])
59+
60+
let hasNextChangeset = false
61+
if (existsSync('./changeset-status.json')) {
62+
const changesetStatus: ChangesetStatusJson = JSON.parse(
63+
await readFile('./changeset-status.json', 'utf8')
64+
)
65+
66+
console.log('▲ Changeset Status:')
67+
console.log(changesetStatus)
68+
69+
hasNextChangeset =
70+
changesetStatus.releases.find((release) => release.name === 'next') !==
71+
undefined
72+
73+
await unlink('./changeset-status.json')
74+
}
75+
76+
if (!hasNextChangeset) {
77+
console.log(
78+
'▲ No changesets found for `next`, creating an empty changeset.'
79+
)
80+
// TODO: Since this is temporary until we hard-require a changeset, we will
81+
// need to remove this in the future to prevent publishing empty releases.
82+
await writeFile(
83+
join(process.cwd(), '.changeset', `next-canary-${Date.now()}.md`),
84+
`---\n'next': patch\n---`
85+
)
86+
}
2887
}
2988

3089
await execa('pnpm', ['changeset', 'version'], {
3190
stdio: 'inherit',
3291
})
92+
// TODO: Update the pnpm-lock.yaml since the packages' depend on
93+
// each other. Remove this once they use `workspace:` protocol.
3394
await execa('pnpm', ['install', '--no-frozen-lockfile'], {
3495
stdio: 'inherit',
3596
})

0 commit comments

Comments
 (0)