Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Upgrade semantic release #9185

Merged
11 changes: 3 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-
- name: Install dependencies
- name: Install prod dependencies
run: npm ci
- name: Remove dev dependencies
run: ./ci/uninstallDevDeps.sh @actions/core
- name: CI Node Engine Check
run: npm run ci:checkNodeEngine
check-lint:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-automated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version: 18.20.0
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Cache Node.js modules
uses: actions/cache@v4
Expand Down
25 changes: 16 additions & 9 deletions release.config.js → .releaserc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
* Semantic Release Config
*/

const fs = require('fs').promises;
const path = require('path');
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 +29,7 @@ const templates = {
async function config() {

// Get branch
const branch = ref.split('/').pop().split('-')[0];
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 @@ -89,7 +94,7 @@ async function config() {
[
"@saithodev/semantic-release-backmerge",
{
"branches": [
"backmergeBranches": [
{ from: "beta", to: "alpha" },
{ from: "release", to: "beta" },
]
Expand All @@ -103,15 +108,17 @@ 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}';
const comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')';
Expand Down
22 changes: 22 additions & 0 deletions ci/uninstallDevDeps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Read package exclusion list from arguments
exclusionList=("$@")

# Convert exclusion list to grep pattern
exclusionPattern=$(printf "|%s" "${exclusionList[@]}")
exclusionPattern=${exclusionPattern:1}

# Get list of all dev dependencies
devDeps=$(jq -r '.devDependencies | keys | .[]' package.json)

# Filter out exclusion list
depsToUninstall=$(echo "$devDeps" | grep -Ev "$exclusionPattern")

# If there are dependencies to uninstall then uninstall them
if [ -n "$depsToUninstall" ]; then
echo "Uninstalling dev dependencies: $depsToUninstall"
npm uninstall $depsToUninstall
else
echo "No dev dependencies to uninstall"
fi
Loading
Loading