Skip to content

Commit 817bc7b

Browse files
committed
enhance(scripts/release): add --dry-run option
1 parent eb495de commit 817bc7b

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

scripts/release/index.ts

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import chalk from 'chalk-template';
55
import esMain from 'es-main';
6+
import yargs from 'yargs';
7+
import { hideBin } from 'yargs/helpers';
68
import { temporaryWriteTask } from 'tempy';
79

810
import { getSemverBumpPulls } from './semver-pulls.js';
@@ -90,10 +92,18 @@ const commitAndPR = async (
9092

9193
/**
9294
* Perform the release
95+
* @param options The release options
96+
* @param options.dryRun Whether to simulate the release locally
9397
*/
94-
const main = async () => {
98+
const main = async ({ dryRun }: { dryRun: boolean }) => {
99+
if (dryRun) {
100+
console.log(chalk`{green Simulating release...}`);
101+
}
102+
95103
requireGitHubCLI();
96-
requireWriteAccess();
104+
if (!dryRun) {
105+
requireWriteAccess();
106+
}
97107

98108
console.log(chalk`{blue Fetching main branch...}`);
99109
fetchMain();
@@ -132,20 +142,34 @@ const main = async () => {
132142
const notes = getNotes(thisVersion, changes, stats, versionBump);
133143
await addNotes(notes, versionBump, lastVersion);
134144

135-
const title = `Release ${thisVersion}`;
136-
const body = `(This release was generated by the project's release script.)\n\n${notes}`;
137-
await commitAndPR(
138-
title,
139-
!process.env.GITHUB_ACTIONS && versionBump !== 'patch',
140-
{
141-
branch: 'release',
142-
pr: { title, body },
143-
},
144-
);
145+
if (!dryRun) {
146+
const title = `Release ${thisVersion}`;
147+
const body = `(This release was generated by the project's release script.)\n\n${notes}`;
148+
await commitAndPR(
149+
title,
150+
!process.env.GITHUB_ACTIONS && versionBump !== 'patch',
151+
{
152+
branch: 'release',
153+
pr: { title, body },
154+
},
155+
);
156+
}
145157

146158
console.log(chalk`{blue {bold Done!}}`);
147159
};
148160

149161
if (esMain(import.meta)) {
150-
await main();
162+
const { argv }: { argv } = yargs(hideBin(process.argv)).command(
163+
'$0',
164+
'Prepares a release by determining changes since the last release, and creating/updating a relase PR',
165+
(yargs) =>
166+
yargs.option('dry-run', {
167+
alias: 'n',
168+
describe: "Don't commit, push or PR",
169+
type: 'boolean',
170+
default: false,
171+
}),
172+
);
173+
174+
await main({ dryRun: argv.dryRun });
151175
}

0 commit comments

Comments
 (0)