From e476aaba3955c385bbc441496d90319028771a0b Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Wed, 25 Sep 2024 01:47:57 +0200 Subject: [PATCH] ci: Upgrade semantic-release (#93) --- .github/workflows/release-automated.yml | 14 +++----- release.config.js | 47 ++++++++++++++++--------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/.github/workflows/release-automated.yml b/.github/workflows/release-automated.yml index f6957fe..0df25df 100644 --- a/.github/workflows/release-automated.yml +++ b/.github/workflows/release-automated.yml @@ -1,7 +1,7 @@ name: release-automated on: push: - branches: [ main, master, release, alpha, beta ] + branches: [ main, master, release, alpha, beta, next-major ] jobs: release: runs-on: ubuntu-latest @@ -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: 24 + cache: 'npm' - name: Install dependencies run: npm ci - name: Run semantic-release @@ -28,4 +22,4 @@ jobs: env: GH_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/release.config.js b/release.config.js index f7f33ca..d1416e0 100644 --- a/release.config.js +++ b/release.config.js @@ -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; @@ -24,9 +30,9 @@ 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 //const changelogFile = `./changelogs/CHANGELOG_${branch}.md`; const changelogFile = `./CHANGELOG.md`; @@ -38,9 +44,11 @@ async function config() { const config = { branches: [ 'main', - // { name: 'alpha', prerelease: true }, - // { name: 'beta', prerelease: true }, - // 'next-major', + 'master', + 'release', + { name: 'alpha', prerelease: true }, + { name: 'beta', prerelease: true }, + 'next-major', // Long-Term-Support branches // { name: 'release-1', range: '1.x.x', channel: '1.x' }, // { name: 'release-2', range: '2.x.x', channel: '2.x' }, @@ -59,13 +67,13 @@ async function config() { { scope: 'no-release', release: false }, ], parserOpts: { - noteKeywords: [ 'BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING' ], + noteKeywords: [ 'BREAKING CHANGE' ], }, }], ['@semantic-release/release-notes-generator', { preset: 'angular', parserOpts: { - noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING'] + noteKeywords: [ 'BREAKING CHANGE' ] }, writerOpts: { commitsSort: ['subject', 'scope'], @@ -79,7 +87,7 @@ async function config() { 'changelogFile': changelogFile, }], ['@semantic-release/npm', { - 'npmPublish': true, + 'npmPublish': false, }], ['@semantic-release/git', { assets: [changelogFile, 'package.json', 'package-lock.json'], @@ -87,7 +95,7 @@ async function config() { ['@semantic-release/github', { successComment: getReleaseComment(), labels: ['type:ci'], - releasedLabels: ['state:released<%= nextRelease.channel ? `-${nextRelease.channel}` : "" %>'] + releasedLabels: ['state:released<%= nextRelease.channel ? `-\${nextRelease.channel}` : "" %>'] }], ], }; @@ -97,19 +105,24 @@ 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 + ')'; return comment; } -module.exports = config(); +// For CommonJS use: +// module.exports = config(); + +// For ES6 modules use: +export default config();