ci: make release script synchronous to ensure consistency

This commit is contained in:
Elliot DeNolf
2024-07-18 14:09:36 -04:00
parent d3131122db
commit 442518dbc9

View File

@@ -7,7 +7,6 @@ import execa from 'execa'
import fse from 'fs-extra' import fse from 'fs-extra'
import minimist from 'minimist' import minimist from 'minimist'
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import pLimit from 'p-limit'
import path from 'path' import path from 'path'
import prompts from 'prompts' import prompts from 'prompts'
import semver from 'semver' import semver from 'semver'
@@ -20,8 +19,6 @@ import { packagePublishList } from './lib/publishList.js'
import { getRecommendedBump } from './utils/getRecommendedBump.js' import { getRecommendedBump } from './utils/getRecommendedBump.js'
import { updateChangelog } from './utils/updateChangelog.js' import { updateChangelog } from './utils/updateChangelog.js'
const npmPublishLimit = pLimit(6)
const filename = fileURLToPath(import.meta.url) const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename) const dirname = path.dirname(filename)
const cwd = path.resolve(dirname, '..') const cwd = path.resolve(dirname, '..')
@@ -37,6 +34,7 @@ const {
'dry-run': dryRun, 'dry-run': dryRun,
'git-tag': gitTag = true, // Whether to run git tag and commit operations 'git-tag': gitTag = true, // Whether to run git tag and commit operations
'git-commit': gitCommit = true, // Whether to run git commit operations 'git-commit': gitCommit = true, // Whether to run git commit operations
versionOverride = undefined,
tag = 'latest', tag = 'latest',
} = args } = args
@@ -117,7 +115,7 @@ async function main() {
// ) // )
// } // }
const nextReleaseVersion = semver.inc(monorepoVersion, bump, undefined, tag) const nextReleaseVersion = versionOverride || semver.inc(monorepoVersion, bump, undefined, tag)
if (!nextReleaseVersion) { if (!nextReleaseVersion) {
abort(`Invalid nextReleaseVersion: ${nextReleaseVersion}`) abort(`Invalid nextReleaseVersion: ${nextReleaseVersion}`)
@@ -213,26 +211,21 @@ async function main() {
packageDetails = packageDetails.filter((p) => p.name !== 'payload') packageDetails = packageDetails.filter((p) => p.name !== 'payload')
runCmd(`pnpm publish -C packages/payload --no-git-checks --json --tag ${tag}`, execOpts) runCmd(`pnpm publish -C packages/payload --no-git-checks --json --tag ${tag}`, execOpts)
const results = await Promise.allSettled( const results: PublishResult[] = []
packageDetails.map((pkg) => publishPackageThrottled(pkg, { dryRun })), for (const pkg of packageDetails) {
) const res = await publishSinglePackage(pkg, { dryRun })
results.push(res)
}
console.log(chalk.bold.green(`\n\nResults:\n`)) console.log(chalk.bold.green(`\n\nResults:\n`))
// New results format
console.log( console.log(
results results
.map((result) => { .map((result) => {
if (result.status === 'rejected') { if (!result.success) {
console.error(result.reason) console.error(result.details)
return `${String(result.reason)}`
} }
const { name, success, details } = result.value return ` ${result.success ? '✅' : '❌'} ${result.name}`
let summary = ` ${success ? '✅' : '❌'} ${name}`
if (details) {
summary += `\n ${details}\n`
}
return summary
}) })
.join('\n') + '\n', .join('\n') + '\n',
) )
@@ -254,12 +247,6 @@ main().catch((error) => {
process.exit(1) process.exit(1)
}) })
/** Publish with promise concurrency throttling */
async function publishPackageThrottled(pkg: PackageDetails, opts?: { dryRun?: boolean }) {
const { dryRun = false } = opts ?? {}
return npmPublishLimit(() => publishSinglePackage(pkg, { dryRun }))
}
async function publishSinglePackage(pkg: PackageDetails, opts?: { dryRun?: boolean }) { async function publishSinglePackage(pkg: PackageDetails, opts?: { dryRun?: boolean }) {
const { dryRun = false } = opts ?? {} const { dryRun = false } = opts ?? {}
console.log(chalk.bold(`🚀 ${pkg.name} publishing...`)) console.log(chalk.bold(`🚀 ${pkg.name} publishing...`))
@@ -361,3 +348,9 @@ function header(message: string, opts?: { enable?: boolean }) {
console.log(chalk.bold.green(`${message}\n`)) console.log(chalk.bold.green(`${message}\n`))
} }
type PublishResult = {
name: string
success: boolean
details?: string
}