22 * Semantic Release Config
33 */
44
5- const fs = require ( 'fs' ) . promises ;
6- const path = require ( 'path' ) ;
5+ const { readFile } = require ( 'fs' ) . promises ;
6+ const { resolve } = require ( 'path' ) ;
7+
8+ // For ES6 modules use:
9+ // import { readFile } from 'fs/promises';
10+ // import { resolve, dirname } from 'path';
11+ // import { fileURLToPath } from 'url';
712
813// Get env vars
914const ref = process . env . GITHUB_REF ;
@@ -24,11 +29,13 @@ const templates = {
2429async function config ( ) {
2530
2631 // Get branch
27- const branch = ref . split ( '/' ) . pop ( ) ;
32+ const branch = ref ?. split ( '/' ) ?. pop ( ) ?. split ( '-' ) [ 0 ] || '(current branch could not be determined)' ;
33+ // eslint-disable-next-line no-console
2834 console . log ( `Running on branch: ${ branch } ` ) ;
2935
3036 // Set changelog file
3137 const changelogFile = `./changelogs/CHANGELOG_${ branch } .md` ;
38+ // eslint-disable-next-line no-console
3239 console . log ( `Changelog file output to: ${ changelogFile } ` ) ;
3340
3441 // Load template file contents
@@ -38,13 +45,10 @@ async function config() {
3845 branches : [
3946 'release' ,
4047 { name : 'alpha' , prerelease : true } ,
41- { name : 'beta' , prerelease : true } ,
48+ // { name: 'beta', prerelease: true },
4249 'next-major' ,
43- // Long-Term-Support branches
44- // { name: 'release-1', range: '1.x.x', channel: '1.x' },
45- // { name: 'release-2', range: '2.x.x', channel: '2.x' },
46- // { name: 'release-3', range: '3.x.x', channel: '3.x' },
47- // { name: 'release-4', range: '4.x.x', channel: '4.x' },
50+ // Long-Term-Support branch
51+ 'release-8.x.x' ,
4852 ] ,
4953 dryRun : false ,
5054 debug : true ,
@@ -58,13 +62,13 @@ async function config() {
5862 { scope : 'no-release' , release : false } ,
5963 ] ,
6064 parserOpts : {
61- noteKeywords : [ 'BREAKING CHANGE' , 'BREAKING CHANGES' , 'BREAKING' ] ,
65+ noteKeywords : [ 'BREAKING CHANGE' ] ,
6266 } ,
6367 } ] ,
6468 [ '@semantic-release/release-notes-generator' , {
6569 preset : 'angular' ,
6670 parserOpts : {
67- noteKeywords : [ 'BREAKING CHANGE' , 'BREAKING CHANGES' , 'BREAKING' ]
71+ noteKeywords : [ 'BREAKING CHANGE' ]
6872 } ,
6973 writerOpts : {
7074 commitsSort : [ 'subject' , 'scope' ] ,
@@ -86,12 +90,13 @@ async function config() {
8690 [ '@semantic-release/github' , {
8791 successComment : getReleaseComment ( ) ,
8892 labels : [ 'type:ci' ] ,
89- releasedLabels : [ 'state:released<%= nextRelease.channel ? `-${nextRelease.channel}` : "" %>' ]
93+ releasedLabels : [ 'state:released<%= nextRelease.channel ? `-\ ${nextRelease.channel}` : "" %>' ]
9094 } ] ,
95+ // Back-merge module runs last because if it fails it should not impede the release process
9196 [
92- ' @saithodev/semantic-release-backmerge' ,
97+ " @saithodev/semantic-release-backmerge" ,
9398 {
94- 'branches' : [
99+ "backmergeBranches" : [
95100 // { from: 'beta', to: 'alpha' },
96101 // { from: 'release', to: 'beta' },
97102 { from : 'release' , to : 'alpha' } ,
@@ -106,15 +111,17 @@ async function config() {
106111
107112async function loadTemplates ( ) {
108113 for ( const template of Object . keys ( templates ) ) {
109- const text = await readFile ( path . resolve ( __dirname , resourcePath , templates [ template ] . file ) ) ;
114+
115+ // For ES6 modules use:
116+ // const fileUrl = import.meta.url;
117+ // const __dirname = dirname(fileURLToPath(fileUrl));
118+
119+ const filePath = resolve ( __dirname , resourcePath , templates [ template ] . file ) ;
120+ const text = await readFile ( filePath , 'utf-8' ) ;
110121 templates [ template ] . text = text ;
111122 }
112123}
113124
114- async function readFile ( filePath ) {
115- return await fs . readFile ( filePath , 'utf-8' ) ;
116- }
117-
118125function getReleaseComment ( ) {
119126 const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}' ;
120127 const comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')' ;
0 commit comments