Skip to content

Commit a7273c6

Browse files
authored
refactor: Upgrade semantic-release (#56)
1 parent 5c150d2 commit a7273c6

File tree

3 files changed

+7460
-7690
lines changed

3 files changed

+7460
-7690
lines changed

release.config.js .releaserc.js

+28-15
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
* Semantic Release Config
33
*/
44

5-
const fs = require('fs').promises;
6-
const path = require('path');
5+
// For CommonJS use:
6+
const { readFile } = require('fs').promises;
7+
const { resolve } = require('path');
8+
9+
// For ES6 modules use:
10+
// import { readFile } from 'fs/promises';
11+
// import { resolve, dirname } from 'path';
12+
// import { fileURLToPath } from 'url';
713

814
// Get env vars
915
const ref = process.env.GITHUB_REF;
@@ -24,9 +30,9 @@ const templates = {
2430
async function config() {
2531

2632
// Get branch
27-
const branch = ref.split('/').pop();
33+
const branch = ref?.split('/')?.pop()?.split('-')[0] || '(current branch could not be determined)';
2834
console.log(`Running on branch: ${branch}`);
29-
35+
3036
// Set changelog file
3137
//const changelogFile = `./changelogs/CHANGELOG_${branch}.md`;
3238
const changelogFile = `./CHANGELOG.md`;
@@ -38,9 +44,11 @@ async function config() {
3844
const config = {
3945
branches: [
4046
'main',
41-
// { name: 'alpha', prerelease: true },
42-
// { name: 'beta', prerelease: true },
43-
// 'next-major',
47+
'master',
48+
'release',
49+
{ name: 'alpha', prerelease: true },
50+
{ name: 'beta', prerelease: true },
51+
'next-major',
4452
// Long-Term-Support branches
4553
// { name: 'release-1', range: '1.x.x', channel: '1.x' },
4654
// { name: 'release-2', range: '2.x.x', channel: '2.x' },
@@ -59,13 +67,13 @@ async function config() {
5967
{ scope: 'no-release', release: false },
6068
],
6169
parserOpts: {
62-
noteKeywords: [ 'BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING' ],
70+
noteKeywords: [ 'BREAKING CHANGE' ],
6371
},
6472
}],
6573
['@semantic-release/release-notes-generator', {
6674
preset: 'angular',
6775
parserOpts: {
68-
noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING']
76+
noteKeywords: [ 'BREAKING CHANGE' ]
6977
},
7078
writerOpts: {
7179
commitsSort: ['subject', 'scope'],
@@ -87,7 +95,7 @@ async function config() {
8795
['@semantic-release/github', {
8896
successComment: getReleaseComment(),
8997
labels: ['type:ci'],
90-
releasedLabels: ['state:released<%= nextRelease.channel ? `-${nextRelease.channel}` : "" %>']
98+
releasedLabels: ['state:released<%= nextRelease.channel ? `-\${nextRelease.channel}` : "" %>']
9199
}],
92100
],
93101
};
@@ -97,19 +105,24 @@ async function config() {
97105

98106
async function loadTemplates() {
99107
for (const template of Object.keys(templates)) {
100-
const text = await readFile(path.resolve(__dirname, resourcePath, templates[template].file));
108+
// For ES6 modules use:
109+
// const fileUrl = import.meta.url;
110+
// const __dirname = dirname(fileURLToPath(fileUrl));
111+
112+
const filePath = resolve(__dirname, resourcePath, templates[template].file);
113+
const text = await readFile(filePath, 'utf-8');
101114
templates[template].text = text;
102115
}
103116
}
104117

105-
async function readFile(filePath) {
106-
return await fs.readFile(filePath, 'utf-8');
107-
}
108-
109118
function getReleaseComment() {
110119
const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}';
111120
let comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')';
112121
return comment;
113122
}
114123

124+
// For CommonJS use:
115125
module.exports = config();
126+
127+
// For ES6 modules use:
128+
// export default config();

0 commit comments

Comments
 (0)