@@ -14,6 +14,7 @@ if (!['patch', 'minor', 'major'].includes(bump)) {
1414}
1515
1616const exec = ( cmd , opts = { } ) => execSync ( cmd , { stdio : 'inherit' , ...opts } )
17+ const read = ( cmd ) => execSync ( cmd , { encoding : 'utf8' } ) . trim ( )
1718
1819// Ensure working tree is clean
1920try {
2324 process . exit ( 1 )
2425}
2526
27+ const branch = read ( 'git branch --show-current' )
28+ if ( branch !== 'main' ) {
29+ console . error ( 'Releases must be tagged from main after the version bump is ready to publish.' )
30+ process . exit ( 1 )
31+ }
32+
33+ exec ( 'git fetch origin main' )
34+ const localHead = read ( 'git rev-parse HEAD' )
35+ const remoteHead = read ( 'git rev-parse origin/main' )
36+ if ( localHead !== remoteHead ) {
37+ console . error ( 'Local main must match origin/main before tagging. Pull or push your changes first.' )
38+ process . exit ( 1 )
39+ }
40+
2641// Bump version in package.json only, no git tag
2742exec ( `npm version ${ bump } --no-git-tag-version` )
2843
@@ -32,15 +47,12 @@ const tag = `v${version}`
3247// Commit the bump locally, then tag that commit
3348exec ( `git add package.json` )
3449exec ( `git commit -m "chore: bump version to ${ tag } "` )
50+ exec ( 'git push origin main' )
3551exec ( `git tag ${ tag } ` )
3652
3753// Push the tag (triggers CI) — tags are not subject to branch rules
3854exec ( `git push origin ${ tag } ` )
3955
4056console . log ( `
4157Tag ${ tag } pushed. CI will build and publish the release.
42-
43- The version bump commit is local. Push it to main:
44- - If you can push directly: git push
45- - Otherwise open a PR from your current branch
4658` )
0 commit comments