Skip to content

Commit 6760320

Browse files
authored
chore: allow publishing tagged branch versions (#367)
1 parent b42b380 commit 6760320

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

knip.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const baseConfig = {
1212
config: 'tsconfig.tsdoc.json',
1313
},
1414
// Knip doesn't support pnpm version
15-
ignoreBinaries: ['version'],
15+
ignoreBinaries: ['version', 'sed'],
1616
entry: ['package.config.ts', 'vitest.config.mts'],
1717
},
1818
'scripts/*': {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"ts:check": "tsc --noEmit",
3636
"depcheck": "knip",
3737
"test:kitchensink": "turbo run test --filter=@sanity/kitchensink-react",
38-
"release:rc": "tsx scripts/release-rc.mts"
38+
"release:rc": "tsx scripts/release-rc.mts",
39+
"release:current-branch": "tsx scripts/release-branch.mts"
3940
},
4041
"prettier": "@sanity/prettier-config",
4142
"devDependencies": {

scripts/release-branch.mts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env zx
2+
import 'zx/globals'
3+
/* eslint-disable @typescript-eslint/no-unused-expressions */
4+
5+
// Creates a new version based on the current branch name
6+
7+
const {packages} = await fs.readJson('./release-please-config.json')
8+
const workspaces = Object.keys(packages)
9+
10+
echo`found ${chalk.blue(workspaces.length)} workspaces to publish canaries for`
11+
12+
const prev = new Map()
13+
const next = new Map()
14+
15+
// Get current branch name (replace / with _ for valid npm version)
16+
const branch = (await $`git rev-parse --abbrev-ref HEAD | sed 's/\\//\\_/g'`).stdout.trim()
17+
18+
const tag = `${branch === 'main' ? 'next' : branch}`
19+
20+
for (const workspace of workspaces) {
21+
const {name, version, private: isPrivate} = await fs.readJson(`./${workspace}/package.json`)
22+
if (!isPrivate) {
23+
await spinner(`bumping ${chalk.blue(name)} from ${chalk.yellow(version)}`, async () => {
24+
prev.set(name, version)
25+
// Create version with branch name and commit SHA
26+
await $`pnpm --filter="${name}" exec pnpm version --no-commit-hooks --no-git-tag-version --preid ${tag} prerelease`
27+
next.set(name, (await fs.readJson(`./${workspace}/package.json`)).version)
28+
})
29+
echo`bumped ${chalk.blue(name)} from ${chalk.yellow(prev.get(name))} to ${chalk.green(next.get(name))}`
30+
}
31+
}
32+
33+
await $`pnpm build --output-logs=errors-only`.pipe(process.stdout)
34+
35+
for (const name of next.keys()) {
36+
try {
37+
const otp = await question('Enter OTP: ')
38+
await $`pnpm --filter="${name}" publish --tag ${tag} --no-git-checks --otp=${otp}`.pipe(
39+
process.stdout,
40+
)
41+
} catch (error) {
42+
if (error.message.includes('EOTP')) {
43+
// If OTP is invalid or expired, try again
44+
const newOtp = await question('Invalid OTP. Please enter again: ')
45+
await $`pnpm --filter="${name}" publish --tag ${tag} --no-git-checks --otp=${newOtp}`.pipe(
46+
process.stdout,
47+
)
48+
} else {
49+
throw error
50+
}
51+
}
52+
}
53+
54+
echo`published versions for ${chalk.blue(workspaces.length)} workspaces`
55+
56+
// Revert the version bumps, just do git checkout <package>/package.json
57+
for (const name of workspaces) {
58+
await $`git checkout ./${name}/package.json`
59+
}

scripts/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"allowJs": true,
88
"skipLibCheck": true
99
},
10-
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "release-rc.mts"]
10+
"include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.mts"]
1111
}

0 commit comments

Comments
 (0)