diff --git a/scripts/release/index.ts b/scripts/release/index.ts index a2b5ecfbb70660..a44fd0f4e66961 100644 --- a/scripts/release/index.ts +++ b/scripts/release/index.ts @@ -3,6 +3,8 @@ import chalk from 'chalk-template'; import esMain from 'es-main'; +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; import { temporaryWriteTask } from 'tempy'; import { getSemverBumpPulls } from './semver-pulls.js'; @@ -90,10 +92,18 @@ const commitAndPR = async ( /** * Perform the release + * @param options The release options + * @param options.dryRun Whether to simulate the release locally */ -const main = async () => { +const main = async ({ dryRun }: { dryRun: boolean }) => { + if (dryRun) { + console.log(chalk`{green Simulating release...}`); + } + requireGitHubCLI(); - requireWriteAccess(); + if (!dryRun) { + requireWriteAccess(); + } console.log(chalk`{blue Fetching main branch...}`); fetchMain(); @@ -132,20 +142,34 @@ const main = async () => { const notes = getNotes(thisVersion, changes, stats, versionBump); await addNotes(notes, versionBump, lastVersion); - const title = `Release ${thisVersion}`; - const body = `(This release was generated by the project's release script.)\n\n${notes}`; - await commitAndPR( - title, - !process.env.GITHUB_ACTIONS && versionBump !== 'patch', - { - branch: 'release', - pr: { title, body }, - }, - ); + if (!dryRun) { + const title = `Release ${thisVersion}`; + const body = `(This release was generated by the project's release script.)\n\n${notes}`; + await commitAndPR( + title, + !process.env.GITHUB_ACTIONS && versionBump !== 'patch', + { + branch: 'release', + pr: { title, body }, + }, + ); + } console.log(chalk`{blue {bold Done!}}`); }; if (esMain(import.meta)) { - await main(); + const { argv }: { argv } = yargs(hideBin(process.argv)).command( + '$0', + 'Prepares a release by determining changes since the last release, and creating/updating a relase PR', + (yargs) => + yargs.option('dry-run', { + alias: 'n', + describe: "Don't commit, push or PR", + type: 'boolean', + default: false, + }), + ); + + await main({ dryRun: argv.dryRun }); }