2
2
* Semantic Release Config
3
3
*/
4
4
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';
7
12
8
13
// Get env vars
9
14
const ref = process . env . GITHUB_REF ;
@@ -24,11 +29,11 @@ const templates = {
24
29
async function config ( ) {
25
30
26
31
// Get branch
27
- const branch = ref . split ( '/' ) . pop ( ) ;
32
+ const branch = ref ? .split ( '/' ) ? .pop ( ) ?. split ( '-' ) [ 0 ] || '(current branch could not be determined)' ;
28
33
console . log ( `Running on branch: ${ branch } ` ) ;
29
34
30
35
// Set changelog file
31
- //const changelogFile = `./changelogs/CHANGELOG_${branch}.md`;
36
+ // const changelogFile = `./changelogs/CHANGELOG_${branch}.md`;
32
37
const changelogFile = `./CHANGELOG.md` ;
33
38
console . log ( `Changelog file output to: ${ changelogFile } ` ) ;
34
39
@@ -38,14 +43,10 @@ async function config() {
38
43
const config = {
39
44
branches : [
40
45
'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 } ,
49
50
] ,
50
51
dryRun : false ,
51
52
debug : true ,
@@ -82,13 +83,23 @@ async function config() {
82
83
'npmPublish' : true ,
83
84
} ] ,
84
85
[ '@semantic-release/git' , {
85
- assets : [ changelogFile , 'package.json' , 'package-lock.json' ] ,
86
+ assets : [ changelogFile , 'package.json' , 'package-lock.json' , 'npm-shrinkwrap.json' ] ,
86
87
} ] ,
87
88
[ '@semantic-release/github' , {
88
89
successComment : getReleaseComment ( ) ,
89
90
labels : [ 'type:ci' ] ,
90
91
releasedLabels : [ 'state:released<%= nextRelease.channel ? `-\${nextRelease.channel}` : "" %>' ]
91
92
} ] ,
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
+ ] ,
92
103
] ,
93
104
} ;
94
105
@@ -97,15 +108,17 @@ async function config() {
97
108
98
109
async function loadTemplates ( ) {
99
110
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' ) ;
101
118
templates [ template ] . text = text ;
102
119
}
103
120
}
104
121
105
- async function readFile ( filePath ) {
106
- return await fs . readFile ( filePath , 'utf-8' ) ;
107
- }
108
-
109
122
function getReleaseComment ( ) {
110
123
const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}' ;
111
124
const comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')' ;
0 commit comments