Skip to content

Commit 89d07e5

Browse files
authored
ci: Fix auto-release (#474)
1 parent 6e25543 commit 89d07e5

File tree

4 files changed

+3321
-5281
lines changed

4 files changed

+3321
-5281
lines changed

.github/workflows/release-automated.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@ jobs:
1313
- name: Setup Node
1414
uses: actions/setup-node@v2
1515
with:
16-
node-version: 18
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: 22
17+
cache: 'npm'
2418
- name: Install dependencies
2519
run: npm ci
2620
- name: Run semantic-release

release.config.cjs renamed to .releaserc.js

Lines changed: 15 additions & 8 deletions
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,7 +30,7 @@ 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}`);
2935

3036
// Set changelog file
@@ -97,15 +103,16 @@ async function config() {
97103

98104
async function loadTemplates() {
99105
for (const template of Object.keys(templates)) {
100-
const text = await readFile(path.resolve(__dirname, resourcePath, templates[template].file));
106+
// For ES6 modules use:
107+
const fileUrl = import.meta.url;
108+
const __dirname = dirname(fileURLToPath(fileUrl));
109+
110+
const filePath = resolve(__dirname, resourcePath, templates[template].file);
111+
const text = await readFile(filePath, 'utf-8');
101112
templates[template].text = text;
102113
}
103114
}
104115

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

0 commit comments

Comments
 (0)