11/** It is assumed that this is called only from the default branch. */
22const { execSync } = require ( "child_process" ) ;
33
4+ const BRANCH = process . env . BRANCH ;
5+
46// Apply changesets if any -- e.g., coming from pre-release branches
57try {
68 execSync ( "pnpm changeset pre exit" ) ;
1012try {
1113 execSync ( "pnpm changeset version" ) ;
1214 execSync (
13- `git add . && git commit -m "Apply changesets and update CHANGELOG" && git push origin ${ process . env . BRANCH } ` ,
15+ `git add . && git commit -m "Apply changesets and update CHANGELOG [skip ci] " && git push origin ${ BRANCH } ` ,
1416 ) ;
1517} catch {
1618 // no changesets to be applied
@@ -20,7 +22,7 @@ const { version: VERSION, name } = require("../lib/package.json");
2022let LATEST_VERSION = "0.0.-1" ;
2123
2224try {
23- LATEST_VERSION = execSync ( `npm view ${ name } version` ) . toString ( ) ?? "0.0.-1" ;
25+ LATEST_VERSION = execSync ( `npm view ${ name } version` ) . toString ( ) . trim ( ) ?? "0.0.-1" ;
2426} catch {
2527 // empty
2628}
@@ -31,21 +33,35 @@ const [newMajor, newMinor] = VERSION.split(".");
3133const [ oldMajor , oldMinor ] = LATEST_VERSION . split ( "." ) ;
3234
3335const isPatch = newMajor === oldMajor && newMinor === oldMinor ;
36+ const releaseBranch = `release-${ newMajor } .${ newMinor } ` ;
3437
35- if ( ! isPatch ) {
38+ if ( isPatch ) {
39+ // update release branch
40+ try {
41+ execSync (
42+ `git checkout ${ releaseBranch } && git merge ${ BRANCH } && git push origin ${ releaseBranch } ` ,
43+ ) ;
44+ } catch { }
45+ } else {
3646 require ( "./update-security-md" ) ( `${ newMajor } .${ newMinor } ` , `${ oldMajor } .${ oldMinor } ` ) ;
3747 /** Create new release branch for every Major or Minor release */
38- const releaseBranch = `release-${ newMajor } .${ newMinor } ` ;
3948 execSync ( `git checkout -b ${ releaseBranch } && git push origin ${ releaseBranch } ` ) ;
4049}
4150
51+ const { visibility } = JSON . parse ( execSync ( "gh repo view --json visibility" ) . toString ( ) ) ;
52+ const provenance = visibility . toLowerCase ( ) === "public" ? "--provenance" : "" ;
53+
4254/** Create release */
43- execSync ( " cd lib && pnpm build && npm publish -- provenance --access public" ) ;
55+ execSync ( ` cd lib && pnpm build && npm publish ${ provenance } --access public` ) ;
4456
4557/** Create GitHub release */
46- execSync (
47- `gh release create ${ VERSION } --generate-notes --latest -n "$(sed '1,/^## /d;/^## /,$d' CHANGELOG.md)" --title "Release v${ VERSION } "` ,
48- ) ;
58+ try {
59+ execSync (
60+ `gh release create ${ VERSION } --generate-notes --latest -n "$(sed '1,/^## /d;/^## /,$d' CHANGELOG.md)" --title "Release v${ VERSION } "` ,
61+ ) ;
62+ } catch {
63+ execSync ( `gh release create ${ VERSION } --generate-notes --latest --title "Release v${ VERSION } "` ) ;
64+ }
4965
5066// Publish canonical packages
5167execSync ( "node scripts/publish-canonical.js" ) ;
0 commit comments