@@ -51,6 +51,8 @@ const OPEN_SOURCE_LICENSES = [
5151/ 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
5252] ;
5353
54+ const MAIN_GIT_BRANCH = "main" ;
55+
5456//------------------------------------------------------------------------------
5557// Data
5658//------------------------------------------------------------------------------
@@ -78,6 +80,8 @@ const NODE = "node ", // intentional extra space
7880TEST_FILES = "\"tests/{bin,conf,lib,tools}/**/*.js\"" ,
7981PERF_ESLINTRC = path . join ( PERF_TMP_DIR , "eslint.config.js" ) ,
8082PERF_MULTIFILES_TARGET_DIR = path . join ( PERF_TMP_DIR , "eslint" ) ,
83+ CHANGELOG_FILE = "./CHANGELOG.md" ,
84+ VERSIONS_FILE = "./docs/src/_data/versions.json" ,
8185
8286/*
8387 * glob arguments with Windows separator `\` don't work:
@@ -125,6 +129,14 @@ function execSilent(cmd) {
125129return exec ( cmd , { silent :true } ) . stdout ;
126130}
127131
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+
128140/**
129141 * Generates a release blog post for eslint.org
130142 *@param {Object } releaseInfo The release metadata.
@@ -274,10 +286,14 @@ function publishSite() {
274286/**
275287 * Updates the changelog, bumps the version number in package.json, creates a local git commit and tag,
276288 * 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.
277291 *@returns {void }
278292 */
279- function generateRelease ( ) {
280- ReleaseOps . generateRelease ( ) ;
293+ function generateRelease ( { packageTag} ) {
294+ echo ( `Current Git branch:${ getCurrentGitBranch ( ) } ` ) ;
295+
296+ ReleaseOps . generateRelease ( /* prereleaseId = */ void 0 , packageTag ) ;
281297const releaseInfo = JSON . parse ( cat ( ".eslint-release-info.json" ) ) ;
282298
283299echo ( "Generating site" ) ;
@@ -343,19 +359,33 @@ function generatePrerelease(prereleaseId) {
343359function publishRelease ( ) {
344360ReleaseOps . publishRelease ( ) ;
345361const releaseInfo = JSON . parse ( cat ( ".eslint-release-info.json" ) ) ;
346- const isPreRelease = / [ a - z ] / u. test ( releaseInfo . version ) ;
347362
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` ) ;
357369
358370publishSite ( ) ;
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+ }
359389}
360390
361391/**
@@ -1105,6 +1135,6 @@ target.perf = function() {
11051135} ) ;
11061136} ;
11071137
1108- target . generateRelease = generateRelease ;
1138+ target . generateRelease = ( [ packageTag ] ) => generateRelease ( { packageTag } ) ;
11091139target . generatePrerelease = ( [ prereleaseType ] ) => generatePrerelease ( prereleaseType ) ;
11101140target . publishRelease = publishRelease ;