Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

verify-release-mode.ts

52 lines1.3 KB

1import fs from 'node:fs'
2import path from 'node:path'
3​
4const releaseBranch = process.env.RELEASE_BRANCH
5const prereleaseBranches = new Set(['alpha', 'beta', 'rc'])
6const preStatePath = path.resolve('.changeset/pre.json')
7​
8if (!releaseBranch) {
9 throw new Error('Expected the RELEASE_BRANCH environment variable')
11​
12if (releaseBranch === 'main') {
13 if (fs.existsSync(preStatePath)) {
14 throw new Error(
15 'Refusing to publish main while .changeset/pre.json exists. Exit prerelease mode before releasing from main.',
16 )
17 }
18​
19 console.log('Verified stable release mode for main')
20 process.exit(0)
22​
23if (!prereleaseBranches.has(releaseBranch)) {
24 throw new Error(`Unsupported release branch: ${releaseBranch}`)
26​
27if (!fs.existsSync(preStatePath)) {
28 throw new Error(
29 `Refusing to publish ${releaseBranch} without .changeset/pre.json`,
30 )
32​
33const preState = JSON.parse(fs.readFileSync(preStatePath, 'utf8')) as {
34 mode?: string
35 tag?: string
37​
38if (preState.mode !== 'pre') {
39 throw new Error(
40 `Refusing to publish ${releaseBranch} while prerelease mode is ${String(preState.mode)}`,
41 )
43​
44if (preState.tag !== releaseBranch) {
45 throw new Error(
46 `Refusing to publish ${releaseBranch} with the ${String(preState.tag)} npm dist-tag`,
47 )
49​
50console.log(
51 `Verified prerelease mode for ${releaseBranch} with the ${preState.tag} npm dist-tag`,