diff --git a/scripts/release.ts b/scripts/release.ts index 2625bbb6b..dec4d0887 100755 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -11,11 +11,11 @@ import pLimit from 'p-limit' import path from 'path' import prompts from 'prompts' import semver from 'semver' -import { simpleGit } from 'simple-git' import type { PackageDetails } from './lib/getPackageDetails.js' import { getPackageDetails } from './lib/getPackageDetails.js' +import { getPackageRegistryVersions } from './lib/getPackageRegistryVersions.js' import { packageWhitelist } from './lib/whitelist.js' import { getRecommendedBump } from './utils/getRecommendedBump.js' import { updateChangelog } from './utils/updateChangelog.js' @@ -26,8 +26,6 @@ const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) const cwd = path.resolve(dirname, '..') -const git = simpleGit(cwd) - const execOpts: ExecSyncOptions = { stdio: 'inherit' } const execaOpts: execa.Options = { stdio: 'inherit' } @@ -90,10 +88,10 @@ async function main() { if (bump !== recommendedBump) { console.log( chalk.bold.yellow( - `Recommended bump type is ${recommendedBump} based on commits since last release`, + `Recommended bump type is '${recommendedBump}' based on commits since last release`, ), ) - const confirmBump = await confirm(`Do you want to continue with ${bump}?`) + const confirmBump = await confirm(`Do you want to continue with bump: '${bump}'?`) if (!confirmBump) { abort() } @@ -200,6 +198,9 @@ async function main() { // Commit all staged changes runCmd(`git add CHANGELOG.md packages/**/package.json package.json`, execOpts) + // Wait 500ms to avoid .git/index.lock errors + await new Promise((resolve) => setTimeout(resolve, 500)) + if (gitCommit) { runCmd(`git commit -m "chore(release): v${nextReleaseVersion} [skip ci]"`, execOpts) } @@ -246,6 +247,9 @@ async function main() { header('šŸŽ‰ Done!') console.log(chalk.bold.green(`\n\nRelease URL: ${releaseUrl}`)) + + // Log out all registry versions + await getPackageRegistryVersions() } main().catch((error) => { @@ -276,7 +280,27 @@ async function publishSinglePackage(pkg: PackageDetails, opts?: { dryRun?: boole if (exitCode !== 0) { console.log(chalk.bold.red(`\n\nāŒ ${pkg.name} ERROR: pnpm publish failed\n\n${stderr}`)) - return { name: pkg.name, success: false, details: stderr } + + // Retry publish + console.log(chalk.bold.yellow(`\nRetrying publish for ${pkg.name}...`)) + const { exitCode: retryExitCode, stderr: retryStdError } = await execa('pnpm', cmdArgs, { + cwd, + stdio: 'inherit', // log full output + }) + + if (retryExitCode !== 0) { + console.error( + chalk.bold.red( + `\n\nāŒ ${pkg.name} ERROR: pnpm publish failed on retry\n\n${retryStdError}`, + ), + ) + } + + return { + name: pkg.name, + success: false, + details: `Exit Code: ${retryExitCode}, stderr: ${retryStdError}`, + } } console.log(`${logPrefix} ${chalk.green(`āœ… ${pkg.name} published`)}`) diff --git a/scripts/utils/updateChangelog.ts b/scripts/utils/updateChangelog.ts index c887cc579..2d65715f4 100755 --- a/scripts/utils/updateChangelog.ts +++ b/scripts/utils/updateChangelog.ts @@ -98,8 +98,8 @@ export const updateChangelog = async (args: Args = {}): Promise if (writeChangelog) { const changelogPath = 'CHANGELOG.md' - const changelog = await fse.readFile(changelogPath, 'utf8') - const newChangelog = changelog + '\n\n' + changelog + const existingChangelog = await fse.readFile(changelogPath, 'utf8') + const newChangelog = changelog + '\n\n' + existingChangelog await fse.writeFile(changelogPath, newChangelog) console.log(`Changelog updated at ${changelogPath}`) }