From bd901853f19e37b0a30887eabf944e4fa8d79882 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Wed, 6 Nov 2024 16:04:30 +0100 Subject: [PATCH] enhance(scripts/release): add --simulate option --- scripts/release/index.ts | 50 +++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/scripts/release/index.ts b/scripts/release/index.ts index a2b5ecfbb70660..d911b65dd082d7 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.simulate Whether to simulate the release locally */ -const main = async () => { +const main = async ({ simulate }: { simulate: boolean }) => { + if (simulate) { + console.log(chalk`{green Simulating release...}`); + } + requireGitHubCLI(); - requireWriteAccess(); + if (!simulate) { + 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 (!simulate) { + 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('simulate', { + alias: 'n', + describe: 'Simulate without commit, push, and PR', + type: 'boolean', + default: false, + }), + ); + + await main({ simulate: argv.simulate }); }