Skip to content

Commit acf636e

Browse files
authored
ci: Fix auto-release (#232)
1 parent 8ac6014 commit acf636e

File tree

4 files changed

+3221
-3340
lines changed

4 files changed

+3221
-3340
lines changed

.github/workflows/release-automated.yml

+4-10
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,14 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- name: Checkout repository
10-
uses: actions/checkout@v2
10+
uses: actions/checkout@v4
1111
with:
1212
persist-credentials: false
1313
- name: Setup Node
14-
uses: actions/setup-node@v2
14+
uses: actions/setup-node@v4
1515
with:
16-
node-version: 14
17-
- name: Cache Node.js modules
18-
uses: actions/cache@v2
19-
with:
20-
path: ~/.npm
21-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
22-
restore-keys: |
23-
${{ runner.os }}-node-
16+
node-version: 20
17+
cache: npm
2418
- name: Install dependencies
2519
run: npm ci
2620
- name: Run semantic-release

release.config.js .releaserc.js

+31-18
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
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
914
const ref = process.env.GITHUB_REF;
@@ -24,11 +29,11 @@ const templates = {
2429
async 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

98109
async 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-
109122
function 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

Comments
 (0)