Skip to content

Commit

Permalink
enhance(scripts/release): add --dry-run option
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Nov 6, 2024
1 parent eb495de commit 817bc7b
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions scripts/release/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 });
}

0 comments on commit 817bc7b

Please sign in to comment.