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,11 @@ 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)' ;
2833 console . log ( `Running on branch: ${ branch } ` ) ;
2934
3035 // Set changelog file
31- //const changelogFile = `./changelogs/CHANGELOG_${branch}.md`;
36+ // const changelogFile = `./changelogs/CHANGELOG_${branch}.md`;
3237 const changelogFile = `./CHANGELOG.md` ;
3338 console . log ( `Changelog file output to: ${ changelogFile } ` ) ;
3439
@@ -38,14 +43,10 @@ async function config() {
3843 const config = {
3944 branches : [
4045 'master' ,
41- // { name: 'alpha', prerelease: true },
42- // { name: 'beta', prerelease: true },
43- // 'next-major',
44- // Long-Term-Support branches
45- // { name: 'release-1', range: '1.x.x', channel: '1.x' },
46- // { name: 'release-2', range: '2.x.x', channel: '2.x' },
47- // { name: 'release-3', range: '3.x.x', channel: '3.x' },
48- // { name: 'release-4', range: '4.x.x', channel: '4.x' },
46+ 'main' ,
47+ 'release' ,
48+ { name : 'alpha' , prerelease : true } ,
49+ { name : 'beta' , prerelease : true } ,
4950 ] ,
5051 dryRun : false ,
5152 debug : true ,
@@ -82,13 +83,23 @@ async function config() {
8283 'npmPublish' : true ,
8384 } ] ,
8485 [ '@semantic-release/git' , {
85- assets : [ changelogFile , 'package.json' , 'package-lock.json' ] ,
86+ assets : [ changelogFile , 'package.json' , 'package-lock.json' , 'npm-shrinkwrap.json' ] ,
8687 } ] ,
8788 [ '@semantic-release/github' , {
8889 successComment : getReleaseComment ( ) ,
8990 labels : [ 'type:ci' ] ,
9091 releasedLabels : [ 'state:released<%= nextRelease.channel ? `-\${nextRelease.channel}` : "" %>' ]
9192 } ] ,
93+ // Back-merge module runs last because if it fails it should not impede the release process
94+ [
95+ "@saithodev/semantic-release-backmerge" ,
96+ {
97+ "backmergeBranches" : [
98+ { from : "beta" , to : "alpha" } ,
99+ { from : "release" , to : "beta" } ,
100+ ]
101+ }
102+ ] ,
92103 ] ,
93104 } ;
94105
@@ -97,15 +108,17 @@ async function config() {
97108
98109async function loadTemplates ( ) {
99110 for ( const template of Object . keys ( templates ) ) {
100- const text = await readFile ( path . resolve ( __dirname , resourcePath , templates [ template ] . file ) ) ;
111+
112+ // For ES6 modules use:
113+ // const fileUrl = import.meta.url;
114+ // const __dirname = dirname(fileURLToPath(fileUrl));
115+
116+ const filePath = resolve ( __dirname , resourcePath , templates [ template ] . file ) ;
117+ const text = await readFile ( filePath , 'utf-8' ) ;
101118 templates [ template ] . text = text ;
102119 }
103120}
104121
105- async function readFile ( filePath ) {
106- return await fs . readFile ( filePath , 'utf-8' ) ;
107- }
108-
109122function getReleaseComment ( ) {
110123 const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}' ;
111124 const comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')' ;
0 commit comments