|
3 | 3 |
|
4 | 4 | import chalk from 'chalk-template'; |
5 | 5 | import esMain from 'es-main'; |
| 6 | +import yargs from 'yargs'; |
| 7 | +import { hideBin } from 'yargs/helpers'; |
6 | 8 | import { temporaryWriteTask } from 'tempy'; |
7 | 9 |
|
8 | 10 | import { getSemverBumpPulls } from './semver-pulls.js'; |
@@ -90,10 +92,18 @@ const commitAndPR = async ( |
90 | 92 |
|
91 | 93 | /** |
92 | 94 | * Perform the release |
| 95 | + * @param options The release options |
| 96 | + * @param options.dryRun Whether to simulate the release locally |
93 | 97 | */ |
94 | | -const main = async () => { |
| 98 | +const main = async ({ dryRun }: { dryRun: boolean }) => { |
| 99 | + if (dryRun) { |
| 100 | + console.log(chalk`{green Simulating release...}`); |
| 101 | + } |
| 102 | + |
95 | 103 | requireGitHubCLI(); |
96 | | - requireWriteAccess(); |
| 104 | + if (!dryRun) { |
| 105 | + requireWriteAccess(); |
| 106 | + } |
97 | 107 |
|
98 | 108 | console.log(chalk`{blue Fetching main branch...}`); |
99 | 109 | fetchMain(); |
@@ -132,20 +142,34 @@ const main = async () => { |
132 | 142 | const notes = getNotes(thisVersion, changes, stats, versionBump); |
133 | 143 | await addNotes(notes, versionBump, lastVersion); |
134 | 144 |
|
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 | + } |
145 | 157 |
|
146 | 158 | console.log(chalk`{blue {bold Done!}}`); |
147 | 159 | }; |
148 | 160 |
|
149 | 161 | 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 }); |
151 | 175 | } |
0 commit comments