Skip to content

Commit

Permalink
feat: migrate to semantic-release 24
Browse files Browse the repository at this point in the history
  • Loading branch information
Stamo-Gochev committed Jan 23, 2025
1 parent a57ef3b commit d26ca87
Show file tree
Hide file tree
Showing 18 changed files with 6,684 additions and 2,344 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = {
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest"
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
}
Expand Down
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
# . "$(dirname "$0")/_/husky.sh"

npx --no -- commitlint --edit "$1"
16 changes: 8 additions & 8 deletions analyzeCommits.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const analyzeCommits = require('@semantic-release/commit-analyzer')
const SemanticReleaseError = require('@semantic-release/error')
const execSync = require('child_process').execSync;
const lastTag = require('./lastTag');
const utils = require('./utils');
import { analyzeCommits } from '@semantic-release/commit-analyzer';
import SemanticReleaseError from '@semantic-release/error';
import { execSync } from 'child_process';
import { lastTag } from './lastTag.js';
import { ghActionsBranch } from './utils.js';

const until = f => array => {
const first = array[0];
Expand All @@ -21,10 +21,10 @@ const lastTaggedRelease = () => {
return execSync(`git rev-list ${args}`, { encoding: 'utf8' }).trim();
};

module.exports = function (pluginConfig, config, cb) {
export default function (pluginConfig, config, cb) {
// run standard commit analysis
return analyzeCommits(pluginConfig, config, function(error, type) {
const branch = config.env.TRAVIS_BRANCH || config.env.GIT_LOCAL_BRANCH || utils.ghActionsBranch(config.env);
const branch = config.env.TRAVIS_BRANCH || config.env.GIT_LOCAL_BRANCH || ghActionsBranch(config.env);
const branchTags = config.options.branchTags;
const distTag = branchTags && branchTags[branch];

Expand Down Expand Up @@ -63,5 +63,5 @@ module.exports = function (pluginConfig, config, cb) {
cb(error, releaseType);
});
});
};
}

4 changes: 2 additions & 2 deletions bin/find-dev-deps.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const fs = require('fs');
const json = fs.readFileSync('package.json', { encoding: 'utf-8' });
import { readFileSync } from 'fs';
const json = readFileSync('package.json', { encoding: 'utf-8' });
const meta = JSON.parse(json);
const deps = Object.assign({}, meta.dependencies, meta.peerDependencies);

Expand Down
60 changes: 30 additions & 30 deletions bin/semantic-prerelease.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
#!/usr/bin/env node

const utils = require('../utils');
const path = require('path');
const validateConfig = require('../validateConfig');
const config = require(path.resolve('package.json'));
const branch = process.env.TRAVIS_BRANCH || process.env.GIT_LOCAL_BRANCH || utils.ghActionsBranch(process.env);
import { ghActionsBranch } from '../utils.js';
import { resolve } from 'path';
import validateConfig from '../validateConfig.js';
const config = require(resolve('package.json'));
const branch = process.env.TRAVIS_BRANCH || process.env.GIT_LOCAL_BRANCH || ghActionsBranch(process.env);
const branchTags = config.release && config.release.branchTags;
const tag = branchTags && branchTags[branch];
const dryRun = process.argv.find(arg => /^(--dry-run|-n)$/.test(arg));
const publicPackage = process.argv.find(arg => /^(--public)$/.test(arg));
const validate = process.argv.find(arg => /^(--validate|-v)$/.test(arg));
const command = [ 'npm', 'publish' ];
const command = ['npm', 'publish'];

if (validate) {
validateConfig(config);
return;
}
validateConfig(config);
// return;
} else {
if (tag) {
command.push('--tag', tag);
}

if (tag) {
command.push('--tag', tag);
}
if (publicPackage) {
command.push('--access=public');
}

if (publicPackage) {
command.push('--access=public');
}
if (!branchTags) {
console.warn('[WARN] No branch tag configuration');
}

if (!branchTags) {
console.warn('[WARN] No branch tag configuration');
}

if (dryRun) {
console.log(command.join(' '));
} else {
const exec = require('child_process').exec;
exec(command.join(' '), function(error, stdout, stderr) {
console.log(stdout);
if (dryRun) {
console.log(command.join(' '));
} else {
const exec = require('child_process').exec;
exec(command.join(' '), function (error, stdout, stderr) {
console.log(stdout);

if (error) {
console.error(`[ERROR] npm publish: ${stderr}`);
process.exit(1);
}
});
if (error) {
console.error(`[ERROR] npm publish: ${stderr}`);
process.exit(1);
}
});
}
}
3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
extends: ["@commitlint/config-conventional"],
};
4 changes: 2 additions & 2 deletions condition-github-actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var SRError = require('@semantic-release/error')
import SRError from '@semantic-release/error'

module.exports = function (pluginConfig, config, cb) {
export function verifyConditions(pluginConfig, config, cb) {
var env = config.env

if (!Object.hasOwnProperty.call(env, 'GITHUB_ACTION')) {
Expand Down
11 changes: 5 additions & 6 deletions generateNotes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const changelog = require('conventional-changelog')
const parseUrl = require('github-url-from-git')
const lastTag = require('./lastTag');
import changelog from 'conventional-changelog';
import parseUrl from 'github-url-from-git';
import { lastTag } from './lastTag.js';

module.exports = function (pluginConfig, {pkg}, cb) {
export default function (pluginConfig, {pkg}, cb) {
const repository = pkg.repository ? parseUrl(pkg.repository.url) : null
const from = lastTag();

Expand All @@ -12,5 +12,4 @@ module.exports = function (pluginConfig, {pkg}, cb) {
from: from,
file: false
}, cb)
};

}
14 changes: 7 additions & 7 deletions getLastRelease.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const defaultLastRelease = require('@semantic-release/last-release-npm');
const lastTag = require('./lastTag');
const utils = require('./utils');
module.exports = function (pluginConfig, config, cb) {
import defaultLastRelease from '@semantic-release/last-release-npm';
import lastTag from './lastTag';
import { ghActionsBranch } from './utils';

export default function (pluginConfig, config, cb) {
let branch;
let oldTag;

Expand All @@ -10,7 +11,7 @@ module.exports = function (pluginConfig, config, cb) {
} else if (config.env.GIT_LOCAL_BRANCH) {
branch = config.env.GIT_LOCAL_BRANCH;
} else if (config.env.GITHUB_REF) {
branch = utils.ghActionsBranch(config.env);
branch = ghActionsBranch(config.env);
} else {
throw new Error('Unable to determine Git branch. Tried TRAVIS_BRANCH, GIT_LOCAL_BRANCH and GITHUB_REF');
}
Expand All @@ -34,5 +35,4 @@ module.exports = function (pluginConfig, config, cb) {
}
cb(err, res);
});
};

}
8 changes: 3 additions & 5 deletions lastTag.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const execSync = require('child_process').execSync;
import { execSync } from 'child_process';

const lastTag = ({ branch = 'origin/master', dev = true } = {}) => {
export const lastTag = ({ branch = 'origin/master', dev = true } = {}) => {
const exclude = dev ? ' --exclude="*dev*"' : '';
return execSync(`git describe --tags --match "v[0-9]*" ${exclude} --abbrev=0 ${branch} || true`,
{ encoding: 'utf8' }
).trim();
};

module.exports = lastTag;
}
Loading

0 comments on commit d26ca87

Please sign in to comment.