@@ -44,6 +44,11 @@ dotenv.config({ path: ROOT_ENV_PATH });
44
44
45
45
export const COMMON_SCOPES = [ 'specs' , 'clients' ] ;
46
46
47
+ // python pre-releases have a pattern like `X.Y.ZaN` for alpha or `X.Y.ZbN` for beta
48
+ // see https://peps.python.org/pep-0440/
49
+ // It also support ruby pre-releases like `X.Y.Z.alpha.N` for alpha or `X.Y.Z.beta.N` for beta
50
+ const preReleaseRegExp = new RegExp ( / \d \. \d \. \d ( \. ? a ( l p h a \. ) ? \d + | \. ? b ( e t a \. ) ? \d + ) $ / ) ;
51
+
47
52
// Prevent fetching the same user multiple times
48
53
const fetchedUsers : Record < string , string > = { } ;
49
54
@@ -181,14 +186,13 @@ export function getNextVersion(current: string, releaseType: semver.ReleaseType
181
186
182
187
let nextVersion : string | null = current ;
183
188
184
- // python pre-releases have a pattern like `X.Y.ZaN` for alpha or `X.Y.ZbN` for beta
185
- // see https://peps.python.org/pep-0440/
186
- // It also support ruby pre-releases like `X.Y.Z.alpha.N` for alpha or `X.Y.Z.beta.N` for beta
187
- if (
188
- releaseType !== 'major' &&
189
- ( / \d \. \d \. \d \. ? a ( l p h a \. ) ? \d + $ / . test ( current ) || / \d \. \d \. \d \. ? b ( e t a \. ) ? \d + $ / . test ( current ) )
190
- ) {
191
- nextVersion = current . replace ( / \d + $ / , ( match ) => `${ parseInt ( match , 10 ) + 1 } ` ) ;
189
+ const preReleaseVersion = current . match ( preReleaseRegExp ) ;
190
+ if ( preReleaseVersion ?. length ) {
191
+ if ( releaseType === 'major' ) {
192
+ nextVersion = current . replace ( preReleaseVersion [ 1 ] , '' ) ;
193
+ } else {
194
+ nextVersion = current . replace ( / \d + $ / , ( match ) => `${ parseInt ( match , 10 ) + 1 } ` ) ;
195
+ }
192
196
} else if ( current . endsWith ( '-SNAPSHOT' ) ) {
193
197
// snapshots should not be bumped
194
198
nextVersion = current ;
@@ -210,11 +214,13 @@ export async function decideReleaseStrategy({
210
214
commits,
211
215
languages,
212
216
major,
217
+ dryRun,
213
218
} : {
214
219
versions : VersionsBeforeBump ;
215
220
commits : PassedCommit [ ] ;
216
221
languages : Language [ ] ;
217
222
major ?: boolean ;
223
+ dryRun ?: boolean ;
218
224
} ) : Promise < Versions > {
219
225
const versionsToPublish : Versions = { } ;
220
226
@@ -247,8 +253,7 @@ export async function decideReleaseStrategy({
247
253
248
254
console . log ( `Deciding next version bump for ${ lang } .` ) ;
249
255
250
- // allows forcing a client release
251
- if ( process . env . LOCAL_TEST_DEV ) {
256
+ if ( dryRun ) {
252
257
nbGitDiff = 1 ;
253
258
}
254
259
@@ -362,8 +367,6 @@ async function getCommits(): Promise<{
362
367
363
368
/**
364
369
* Ensure the release environment is correct before triggering.
365
- *
366
- * You can bypass blocking checks by setting LOCAL_TEST_DEV to true.
367
370
*/
368
371
async function prepareGitEnvironment ( ) : Promise < void > {
369
372
ensureGitHubToken ( ) ;
@@ -372,19 +375,11 @@ async function prepareGitEnvironment(): Promise<void> {
372
375
await configureGitHubAuthor ( ) ;
373
376
}
374
377
375
- if (
376
- ! process . env . LOCAL_TEST_DEV &&
377
- ( await run ( 'git rev-parse --abbrev-ref HEAD' ) ) !== MAIN_BRANCH
378
- ) {
378
+ if ( ( await run ( 'git rev-parse --abbrev-ref HEAD' ) ) !== MAIN_BRANCH ) {
379
379
throw new Error ( `You can run this script only from \`${ MAIN_BRANCH } \` branch.` ) ;
380
380
}
381
381
382
- if (
383
- ! process . env . LOCAL_TEST_DEV &&
384
- ( await getNbGitDiff ( {
385
- head : null ,
386
- } ) ) !== 0
387
- ) {
382
+ if ( ( await getNbGitDiff ( { head : null } ) ) !== 0 ) {
388
383
throw new Error ( 'Working directory is not clean. Commit all the changes first.' ) ;
389
384
}
390
385
@@ -483,11 +478,15 @@ async function updateLTS(versions: Versions, withGraphs?: boolean): Promise<void
483
478
export async function createReleasePR ( {
484
479
languages,
485
480
major,
481
+ dryRun,
486
482
} : {
487
483
languages : Language [ ] ;
488
484
major ?: boolean ;
485
+ dryRun ?: boolean ;
489
486
} ) : Promise < void > {
490
- await prepareGitEnvironment ( ) ;
487
+ if ( ! dryRun ) {
488
+ await prepareGitEnvironment ( ) ;
489
+ }
491
490
492
491
console . log ( 'Searching for commits since last release...' ) ;
493
492
const { validCommits, skippedCommits } = await getCommits ( ) ;
@@ -538,6 +537,12 @@ export async function createReleasePR({
538
537
539
538
await updateLTS ( versions , true ) ;
540
539
540
+ if ( dryRun ) {
541
+ console . log ( ' > asked for a dryrun, stopping here' ) ;
542
+
543
+ return ;
544
+ }
545
+
541
546
const headBranch = `chore/prepare-release-${ TODAY } ` ;
542
547
console . log ( `Switching to branch: ${ headBranch } ` ) ;
543
548
if ( await gitBranchExists ( headBranch ) ) {
@@ -551,11 +556,7 @@ export async function createReleasePR({
551
556
console . log ( `Pushing updated changes to: ${ headBranch } ` ) ;
552
557
const commitMessage = generationCommitText . commitPrepareReleaseMessage ;
553
558
await run ( 'git add .' ) ;
554
- if ( process . env . LOCAL_TEST_DEV ) {
555
- await run ( `git commit -m "${ commitMessage } [skip ci]"` ) ;
556
- } else {
557
- await run ( `CI=false git commit -m "${ commitMessage } "` ) ;
558
- }
559
+ await run ( `CI=false git commit -m "${ commitMessage } "` ) ;
559
560
560
561
// cleanup all the changes to the generated files (the ones not commited because of the pre-commit hook)
561
562
await run ( `git checkout .` ) ;
0 commit comments