|
|
@@ -51,6 +51,13 @@ const { values: args, positionals } = parseArgs({
|
|
|
skipPrompts: {
|
|
|
type: 'boolean',
|
|
|
},
|
|
|
+ publish: {
|
|
|
+ type: 'boolean',
|
|
|
+ default: false,
|
|
|
+ },
|
|
|
+ publishOnly: {
|
|
|
+ type: 'boolean',
|
|
|
+ },
|
|
|
},
|
|
|
})
|
|
|
|
|
|
@@ -247,41 +254,7 @@ async function main() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!skipTests) {
|
|
|
- step('Checking CI status for HEAD...')
|
|
|
- let isCIPassed = await getCIResult()
|
|
|
- skipTests ||= isCIPassed
|
|
|
-
|
|
|
- if (isCIPassed) {
|
|
|
- if (!skipPrompts) {
|
|
|
- /** @type {{ yes: boolean }} */
|
|
|
- const { yes: promptSkipTests } = await prompt({
|
|
|
- type: 'confirm',
|
|
|
- name: 'yes',
|
|
|
- message: `CI for this commit passed. Skip local tests?`,
|
|
|
- })
|
|
|
- skipTests = promptSkipTests
|
|
|
- } else {
|
|
|
- skipTests = true
|
|
|
- }
|
|
|
- } else if (skipPrompts) {
|
|
|
- throw new Error(
|
|
|
- 'CI for the latest commit has not passed yet. ' +
|
|
|
- 'Only run the release workflow after the CI has passed.',
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!skipTests) {
|
|
|
- step('\nRunning tests...')
|
|
|
- if (!isDryRun) {
|
|
|
- await run('pnpm', ['run', 'test', '--run'])
|
|
|
- } else {
|
|
|
- console.log(`Skipped (dry run)`)
|
|
|
- }
|
|
|
- } else {
|
|
|
- step('Tests skipped.')
|
|
|
- }
|
|
|
+ await runTestsIfNeeded()
|
|
|
|
|
|
// update all package versions and inter-dependencies
|
|
|
step('\nUpdating cross dependencies...')
|
|
|
@@ -291,16 +264,6 @@ async function main() {
|
|
|
)
|
|
|
versionUpdated = true
|
|
|
|
|
|
- // build all packages with types
|
|
|
- step('\nBuilding all packages...')
|
|
|
- if (!skipBuild && !isDryRun) {
|
|
|
- await run('pnpm', ['run', 'build', '--withTypes'])
|
|
|
- step('\nTesting built types...')
|
|
|
- await run('pnpm', ['test-dts-only'])
|
|
|
- } else {
|
|
|
- console.log(`(skipped)`)
|
|
|
- }
|
|
|
-
|
|
|
// generate changelog
|
|
|
step('\nGenerating changelog...')
|
|
|
await run(`pnpm`, ['run', 'changelog'])
|
|
|
@@ -337,29 +300,15 @@ async function main() {
|
|
|
}
|
|
|
|
|
|
// publish packages
|
|
|
- step('\nPublishing packages...')
|
|
|
-
|
|
|
- const additionalPublishFlags = []
|
|
|
- if (isDryRun) {
|
|
|
- additionalPublishFlags.push('--dry-run')
|
|
|
- }
|
|
|
- if (isDryRun || skipGit) {
|
|
|
- additionalPublishFlags.push('--no-git-checks')
|
|
|
- }
|
|
|
- // bypass the pnpm --publish-branch restriction which isn't too useful to us
|
|
|
- // otherwise it leads to a prompt and blocks the release script
|
|
|
- const branch = await getBranch()
|
|
|
- if (branch !== 'main') {
|
|
|
- additionalPublishFlags.push('--publish-branch', branch)
|
|
|
- }
|
|
|
- // add provenance metadata when releasing from CI
|
|
|
- // canary release commits are not pushed therefore we don't need to add provenance
|
|
|
- if (process.env.CI && !isCanary) {
|
|
|
- additionalPublishFlags.push('--provenance')
|
|
|
- }
|
|
|
-
|
|
|
- for (const pkg of packages) {
|
|
|
- await publishPackage(pkg, targetVersion, additionalPublishFlags)
|
|
|
+ if (args.publish) {
|
|
|
+ await buildPackages()
|
|
|
+ await publishPackages(targetVersion)
|
|
|
+ } else {
|
|
|
+ console.log(
|
|
|
+ pico.yellow(
|
|
|
+ '\nPublish step skipped (will be done in GitHub actions on successful push)',
|
|
|
+ ),
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
// push to GitHub
|
|
|
@@ -386,6 +335,44 @@ async function main() {
|
|
|
console.log()
|
|
|
}
|
|
|
|
|
|
+async function runTestsIfNeeded() {
|
|
|
+ if (!skipTests) {
|
|
|
+ step('Checking CI status for HEAD...')
|
|
|
+ let isCIPassed = await getCIResult()
|
|
|
+ skipTests ||= isCIPassed
|
|
|
+
|
|
|
+ if (isCIPassed) {
|
|
|
+ if (!skipPrompts) {
|
|
|
+ /** @type {{ yes: boolean }} */
|
|
|
+ const { yes: promptSkipTests } = await prompt({
|
|
|
+ type: 'confirm',
|
|
|
+ name: 'yes',
|
|
|
+ message: `CI for this commit passed. Skip local tests?`,
|
|
|
+ })
|
|
|
+ skipTests = promptSkipTests
|
|
|
+ } else {
|
|
|
+ skipTests = true
|
|
|
+ }
|
|
|
+ } else if (skipPrompts) {
|
|
|
+ throw new Error(
|
|
|
+ 'CI for the latest commit has not passed yet. ' +
|
|
|
+ 'Only run the release workflow after the CI has passed.',
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!skipTests) {
|
|
|
+ step('\nRunning tests...')
|
|
|
+ if (!isDryRun) {
|
|
|
+ await run('pnpm', ['run', 'test', '--run'])
|
|
|
+ } else {
|
|
|
+ console.log(`Skipped (dry run)`)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ step('Tests skipped.')
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
async function getCIResult() {
|
|
|
try {
|
|
|
const sha = await getSha()
|
|
|
@@ -492,6 +479,46 @@ function updateDeps(pkg, depType, version, getNewPackageName) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+async function buildPackages() {
|
|
|
+ step('\nBuilding all packages...')
|
|
|
+ if (!skipBuild) {
|
|
|
+ await run('pnpm', ['run', 'build', '--withTypes'])
|
|
|
+ } else {
|
|
|
+ console.log(`(skipped)`)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @param {string} version
|
|
|
+ */
|
|
|
+async function publishPackages(version) {
|
|
|
+ // publish packages
|
|
|
+ step('\nPublishing packages...')
|
|
|
+
|
|
|
+ const additionalPublishFlags = []
|
|
|
+ if (isDryRun) {
|
|
|
+ additionalPublishFlags.push('--dry-run')
|
|
|
+ }
|
|
|
+ if (isDryRun || skipGit) {
|
|
|
+ additionalPublishFlags.push('--no-git-checks')
|
|
|
+ }
|
|
|
+ // bypass the pnpm --publish-branch restriction which isn't too useful to us
|
|
|
+ // otherwise it leads to a prompt and blocks the release script
|
|
|
+ const branch = await getBranch()
|
|
|
+ if (branch !== 'main') {
|
|
|
+ additionalPublishFlags.push('--publish-branch', branch)
|
|
|
+ }
|
|
|
+ // add provenance metadata when releasing from CI
|
|
|
+ // canary release commits are not pushed therefore we don't need to add provenance
|
|
|
+ if (process.env.CI && !isCanary) {
|
|
|
+ additionalPublishFlags.push('--provenance')
|
|
|
+ }
|
|
|
+
|
|
|
+ for (const pkg of packages) {
|
|
|
+ await publishPackage(pkg, version, additionalPublishFlags)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* @param {string} pkgName
|
|
|
* @param {string} version
|
|
|
@@ -541,7 +568,14 @@ async function publishPackage(pkgName, version, additionalFlags) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-main().catch(err => {
|
|
|
+async function publishOnly() {
|
|
|
+ await buildPackages()
|
|
|
+ await publishPackages(currentVersion)
|
|
|
+}
|
|
|
+
|
|
|
+const fnToRun = args.publishOnly ? publishOnly : main
|
|
|
+
|
|
|
+fnToRun().catch(err => {
|
|
|
if (versionUpdated) {
|
|
|
// revert to current version on failed releases
|
|
|
updateVersions(currentVersion)
|