@@ -51,6 +51,13 @@ const { values: args, positionals } = parseArgs({
51
51
skipPrompts : {
52
52
type : 'boolean' ,
53
53
} ,
54
+ publish : {
55
+ type : 'boolean' ,
56
+ default : false ,
57
+ } ,
58
+ publishOnly : {
59
+ type : 'boolean' ,
60
+ } ,
54
61
} ,
55
62
} )
56
63
@@ -247,41 +254,7 @@ async function main() {
247
254
}
248
255
}
249
256
250
- if ( ! skipTests ) {
251
- step ( 'Checking CI status for HEAD...' )
252
- let isCIPassed = await getCIResult ( )
253
- skipTests ||= isCIPassed
254
-
255
- if ( isCIPassed ) {
256
- if ( ! skipPrompts ) {
257
- /** @type {{ yes: boolean } } */
258
- const { yes : promptSkipTests } = await prompt ( {
259
- type : 'confirm' ,
260
- name : 'yes' ,
261
- message : `CI for this commit passed. Skip local tests?` ,
262
- } )
263
- skipTests = promptSkipTests
264
- } else {
265
- skipTests = true
266
- }
267
- } else if ( skipPrompts ) {
268
- throw new Error (
269
- 'CI for the latest commit has not passed yet. ' +
270
- 'Only run the release workflow after the CI has passed.' ,
271
- )
272
- }
273
- }
274
-
275
- if ( ! skipTests ) {
276
- step ( '\nRunning tests...' )
277
- if ( ! isDryRun ) {
278
- await run ( 'pnpm' , [ 'run' , 'test' , '--run' ] )
279
- } else {
280
- console . log ( `Skipped (dry run)` )
281
- }
282
- } else {
283
- step ( 'Tests skipped.' )
284
- }
257
+ await runTestsIfNeeded ( )
285
258
286
259
// update all package versions and inter-dependencies
287
260
step ( '\nUpdating cross dependencies...' )
@@ -291,16 +264,6 @@ async function main() {
291
264
)
292
265
versionUpdated = true
293
266
294
- // build all packages with types
295
- step ( '\nBuilding all packages...' )
296
- if ( ! skipBuild && ! isDryRun ) {
297
- await run ( 'pnpm' , [ 'run' , 'build' , '--withTypes' ] )
298
- step ( '\nTesting built types...' )
299
- await run ( 'pnpm' , [ 'test-dts-only' ] )
300
- } else {
301
- console . log ( `(skipped)` )
302
- }
303
-
304
267
// generate changelog
305
268
step ( '\nGenerating changelog...' )
306
269
await run ( `pnpm` , [ 'run' , 'changelog' ] )
@@ -337,29 +300,15 @@ async function main() {
337
300
}
338
301
339
302
// publish packages
340
- step ( '\nPublishing packages...' )
341
-
342
- const additionalPublishFlags = [ ]
343
- if ( isDryRun ) {
344
- additionalPublishFlags . push ( '--dry-run' )
345
- }
346
- if ( isDryRun || skipGit ) {
347
- additionalPublishFlags . push ( '--no-git-checks' )
348
- }
349
- // bypass the pnpm --publish-branch restriction which isn't too useful to us
350
- // otherwise it leads to a prompt and blocks the release script
351
- const branch = await getBranch ( )
352
- if ( branch !== 'main' ) {
353
- additionalPublishFlags . push ( '--publish-branch' , branch )
354
- }
355
- // add provenance metadata when releasing from CI
356
- // canary release commits are not pushed therefore we don't need to add provenance
357
- if ( process . env . CI && ! isCanary ) {
358
- additionalPublishFlags . push ( '--provenance' )
359
- }
360
-
361
- for ( const pkg of packages ) {
362
- await publishPackage ( pkg , targetVersion , additionalPublishFlags )
303
+ if ( args . publish ) {
304
+ await buildPackages ( )
305
+ await publishPackages ( targetVersion )
306
+ } else {
307
+ console . log (
308
+ pico . yellow (
309
+ '\nPublish step skipped (will be done in GitHub actions on successful push)' ,
310
+ ) ,
311
+ )
363
312
}
364
313
365
314
// push to GitHub
@@ -386,6 +335,44 @@ async function main() {
386
335
console . log ( )
387
336
}
388
337
338
+ async function runTestsIfNeeded ( ) {
339
+ if ( ! skipTests ) {
340
+ step ( 'Checking CI status for HEAD...' )
341
+ let isCIPassed = await getCIResult ( )
342
+ skipTests ||= isCIPassed
343
+
344
+ if ( isCIPassed ) {
345
+ if ( ! skipPrompts ) {
346
+ /** @type {{ yes: boolean } } */
347
+ const { yes : promptSkipTests } = await prompt ( {
348
+ type : 'confirm' ,
349
+ name : 'yes' ,
350
+ message : `CI for this commit passed. Skip local tests?` ,
351
+ } )
352
+ skipTests = promptSkipTests
353
+ } else {
354
+ skipTests = true
355
+ }
356
+ } else if ( skipPrompts ) {
357
+ throw new Error (
358
+ 'CI for the latest commit has not passed yet. ' +
359
+ 'Only run the release workflow after the CI has passed.' ,
360
+ )
361
+ }
362
+ }
363
+
364
+ if ( ! skipTests ) {
365
+ step ( '\nRunning tests...' )
366
+ if ( ! isDryRun ) {
367
+ await run ( 'pnpm' , [ 'run' , 'test' , '--run' ] )
368
+ } else {
369
+ console . log ( `Skipped (dry run)` )
370
+ }
371
+ } else {
372
+ step ( 'Tests skipped.' )
373
+ }
374
+ }
375
+
389
376
async function getCIResult ( ) {
390
377
try {
391
378
const sha = await getSha ( )
@@ -492,6 +479,46 @@ function updateDeps(pkg, depType, version, getNewPackageName) {
492
479
} )
493
480
}
494
481
482
+ async function buildPackages ( ) {
483
+ step ( '\nBuilding all packages...' )
484
+ if ( ! skipBuild ) {
485
+ await run ( 'pnpm' , [ 'run' , 'build' , '--withTypes' ] )
486
+ } else {
487
+ console . log ( `(skipped)` )
488
+ }
489
+ }
490
+
491
+ /**
492
+ * @param {string } version
493
+ */
494
+ async function publishPackages ( version ) {
495
+ // publish packages
496
+ step ( '\nPublishing packages...' )
497
+
498
+ const additionalPublishFlags = [ ]
499
+ if ( isDryRun ) {
500
+ additionalPublishFlags . push ( '--dry-run' )
501
+ }
502
+ if ( isDryRun || skipGit ) {
503
+ additionalPublishFlags . push ( '--no-git-checks' )
504
+ }
505
+ // bypass the pnpm --publish-branch restriction which isn't too useful to us
506
+ // otherwise it leads to a prompt and blocks the release script
507
+ const branch = await getBranch ( )
508
+ if ( branch !== 'main' ) {
509
+ additionalPublishFlags . push ( '--publish-branch' , branch )
510
+ }
511
+ // add provenance metadata when releasing from CI
512
+ // canary release commits are not pushed therefore we don't need to add provenance
513
+ if ( process . env . CI && ! isCanary ) {
514
+ additionalPublishFlags . push ( '--provenance' )
515
+ }
516
+
517
+ for ( const pkg of packages ) {
518
+ await publishPackage ( pkg , version , additionalPublishFlags )
519
+ }
520
+ }
521
+
495
522
/**
496
523
* @param {string } pkgName
497
524
* @param {string } version
@@ -541,7 +568,14 @@ async function publishPackage(pkgName, version, additionalFlags) {
541
568
}
542
569
}
543
570
544
- main ( ) . catch ( err => {
571
+ async function publishOnly ( ) {
572
+ await buildPackages ( )
573
+ await publishPackages ( currentVersion )
574
+ }
575
+
576
+ const fnToRun = args . publishOnly ? publishOnly : main
577
+
578
+ fnToRun ( ) . catch ( err => {
545
579
if ( versionUpdated ) {
546
580
// revert to current version on failed releases
547
581
updateVersions ( currentVersion )
0 commit comments