Skip to content

Commit

Permalink
ci: Fix auto-release (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrezza authored Jul 12, 2024
1 parent 6e25543 commit 89d07e5
Show file tree
Hide file tree
Showing 4 changed files with 3,321 additions and 5,281 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/release-automated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 18
- name: Cache Node.js modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
node-version: 22
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run semantic-release
Expand Down
23 changes: 15 additions & 8 deletions release.config.cjs → .releaserc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
* Semantic Release Config
*/

const fs = require('fs').promises;
const path = require('path');
// For CommonJS use:
// const { readFile } = require('fs').promises;
// const { resolve } = require('path');

// For ES6 modules use:
import { readFile } from 'fs/promises';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';

// Get env vars
const ref = process.env.GITHUB_REF;
Expand All @@ -24,7 +30,7 @@ const templates = {
async function config() {

// Get branch
const branch = ref.split('/').pop();
const branch = ref?.split('/')?.pop()?.split('-')[0] || '(current branch could not be determined)';
console.log(`Running on branch: ${branch}`);

// Set changelog file
Expand Down Expand Up @@ -97,15 +103,16 @@ async function config() {

async function loadTemplates() {
for (const template of Object.keys(templates)) {
const text = await readFile(path.resolve(__dirname, resourcePath, templates[template].file));
// For ES6 modules use:
const fileUrl = import.meta.url;
const __dirname = dirname(fileURLToPath(fileUrl));

const filePath = resolve(__dirname, resourcePath, templates[template].file);
const text = await readFile(filePath, 'utf-8');
templates[template].text = text;
}
}

async function readFile(filePath) {
return await fs.readFile(filePath, 'utf-8');
}

function getReleaseComment() {
const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}';
let comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')';
Expand Down
Loading

0 comments on commit 89d07e5

Please sign in to comment.