@@ -51,6 +51,8 @@ const OPEN_SOURCE_LICENSES = [
51
51
/ M I T / u, / B S D / u, / A p a c h e / u, / I S C / u, / W T F / u, / P u b l i c D o m a i n / u, / L G P L / u, / P y t h o n / u
52
52
] ;
53
53
54
+ const MAIN_GIT_BRANCH = "main" ;
55
+
54
56
//------------------------------------------------------------------------------
55
57
// Data
56
58
//------------------------------------------------------------------------------
@@ -78,6 +80,8 @@ const NODE = "node ", // intentional extra space
78
80
TEST_FILES = "\"tests/{bin,conf,lib,tools}/**/*.js\"" ,
79
81
PERF_ESLINTRC = path . join ( PERF_TMP_DIR , "eslint.config.js" ) ,
80
82
PERF_MULTIFILES_TARGET_DIR = path . join ( PERF_TMP_DIR , "eslint" ) ,
83
+ CHANGELOG_FILE = "./CHANGELOG.md" ,
84
+ VERSIONS_FILE = "./docs/src/_data/versions.json" ,
81
85
82
86
/*
83
87
* glob arguments with Windows separator `\` don't work:
@@ -125,6 +129,14 @@ function execSilent(cmd) {
125
129
return exec ( cmd , { silent : true } ) . stdout ;
126
130
}
127
131
132
+ /**
133
+ * Gets name of the currently checked out Git branch.
134
+ * @returns {string } Name of the currently checked out Git branch.
135
+ */
136
+ function getCurrentGitBranch ( ) {
137
+ return execSilent ( "git branch --show-current" ) . trim ( ) ;
138
+ }
139
+
128
140
/**
129
141
* Generates a release blog post for eslint.org
130
142
* @param {Object } releaseInfo The release metadata.
@@ -274,10 +286,14 @@ function publishSite() {
274
286
/**
275
287
* Updates the changelog, bumps the version number in package.json, creates a local git commit and tag,
276
288
* and generates the site in an adjacent `website` folder.
289
+ * @param {Object } options Release options.
290
+ * @param {string } options.packageTag Tag that should be added to the package submitted to the npm registry.
277
291
* @returns {void }
278
292
*/
279
- function generateRelease ( ) {
280
- ReleaseOps . generateRelease ( ) ;
293
+ function generateRelease ( { packageTag } ) {
294
+ echo ( `Current Git branch: ${ getCurrentGitBranch ( ) } ` ) ;
295
+
296
+ ReleaseOps . generateRelease ( /* prereleaseId = */ void 0 , packageTag ) ;
281
297
const releaseInfo = JSON . parse ( cat ( ".eslint-release-info.json" ) ) ;
282
298
283
299
echo ( "Generating site" ) ;
@@ -343,19 +359,33 @@ function generatePrerelease(prereleaseId) {
343
359
function publishRelease ( ) {
344
360
ReleaseOps . publishRelease ( ) ;
345
361
const releaseInfo = JSON . parse ( cat ( ".eslint-release-info.json" ) ) ;
346
- const isPreRelease = / [ a - z ] / u. test ( releaseInfo . version ) ;
347
362
348
- /*
349
- * for a pre-release, push to the "next" branch to trigger docs deploy
350
- * for a release, push to the "latest" branch to trigger docs deploy
351
- */
352
- if ( isPreRelease ) {
353
- exec ( "git push origin HEAD:next -f" ) ;
354
- } else {
355
- exec ( "git push origin HEAD:latest -f" ) ;
356
- }
363
+ const docsSiteBranch = releaseInfo . packageTag === "maintenance"
364
+ ? `v${ semver . major ( releaseInfo . version ) } .x`
365
+ : releaseInfo . packageTag ; // "latest" or "next"
366
+
367
+ echo ( `Updating docs site branch: ${ docsSiteBranch } ` ) ;
368
+ exec ( `git push origin HEAD:${ docsSiteBranch } -f` ) ;
357
369
358
370
publishSite ( ) ;
371
+
372
+ // Update changelog and list of versions on the main branch
373
+ if ( getCurrentGitBranch ( ) !== MAIN_GIT_BRANCH ) {
374
+ echo ( `Updating changelog and versions on branch: ${ MAIN_GIT_BRANCH } ` ) ;
375
+
376
+ exec ( `git checkout ${ MAIN_GIT_BRANCH } --force` ) ;
377
+
378
+ fs . writeFileSync ( CHANGELOG_FILE , `${ releaseInfo . markdownChangelog } ${ cat ( CHANGELOG_FILE ) } ` ) ;
379
+
380
+ const versions = JSON . parse ( cat ( VERSIONS_FILE ) ) ;
381
+
382
+ versions . items . find ( ( { branch } ) => branch === docsSiteBranch ) . version = releaseInfo . version ;
383
+ fs . writeFileSync ( VERSIONS_FILE , `${ JSON . stringify ( versions , null , 4 ) } \n` ) ;
384
+
385
+ exec ( `git add ${ CHANGELOG_FILE } ${ VERSIONS_FILE } ` ) ;
386
+ exec ( `git commit -m "chore: updates for v${ releaseInfo . version } release"` ) ;
387
+ exec ( "git push origin HEAD" ) ;
388
+ }
359
389
}
360
390
361
391
/**
@@ -1105,6 +1135,6 @@ target.perf = function() {
1105
1135
} ) ;
1106
1136
} ;
1107
1137
1108
- target . generateRelease = generateRelease ;
1138
+ target . generateRelease = ( [ packageTag ] ) => generateRelease ( { packageTag } ) ;
1109
1139
target . generatePrerelease = ( [ prereleaseType ] ) => generatePrerelease ( prereleaseType ) ;
1110
1140
target . publishRelease = publishRelease ;
0 commit comments