Comments (11)
I'm closing this issue with the following solution. Thanks again @amariq for your help.
In order to sort the commit groups, you must use a .releaserc.js
file (not json
).
First, declare the desired order for groups.
const commitGroupsOrder = {
features: 1,
bugfixes: 2,
docs: 3,
styles: 4,
refactor: 5,
performances: 6,
tests: 7,
ci: 8,
chore: 9,
};
Note here : the keys are named after the
section title
. It may defer on your project.
Then, here's my release-notes-generator
config definition :
"@semantic-release/release-notes-generator",
{
preset: "conventionalcommits",
presetConfig: {
types: [
{
type: "feat",
section: "๐ Features",
hidden: false,
},
{
type: "fix",
section: "๐ Bug Fixes",
hidden: false,
},
{
type: "docs",
section: "๐ Docs",
hidden: false,
},
{
type: "style",
section: "๐จ Styles",
hidden: false,
},
{
type: "refactor",
section: "๐ฉ Refactor",
hidden: false,
},
{
type: "perf",
section: "โก๏ธ Performances",
hidden: false,
},
{
type: "test",
section: "โ
Tests",
hidden: false,
},
{
type: "ci",
section: "๐ CI",
hidden: false,
},
{
type: "chore",
section: "๐งน Chore",
hidden: false,
},
],
},
writerOpts: {
groupBy: "type",
commitGroupsSort: (commitGroupA, commitGroupB) => {
const commitGroupTitleA = commitGroupA.title.replace(/[^a-zA-Z]/gu, "").toLowerCase();
const commitGroupTitleB = commitGroupB.title.replace(/[^a-zA-Z]/gu, "").toLowerCase();
if (commitGroupsOrder[commitGroupTitleA] === undefined || commitGroupsOrder[commitGroupTitleB] === undefined) {
return 0;
}
if (commitGroupsOrder[commitGroupTitleA] < commitGroupsOrder[commitGroupTitleB]) {
return -1;
}
if (commitGroupsOrder[commitGroupTitleA] > commitGroupsOrder[commitGroupTitleB]) {
return 1;
}
return 0;
},
},
},
],
Two important parts here :
- In
presetConfig.types
, I declare the commit section titles. For example, thefeat
section will be renamed to๐ Features
. - In
writerOpts.commitGroupsSort
, I write a sort function which will compare sections and sort them by title. As you can see, I usedreplace
and some regexp to keep letters only. For example,๐ Bug Fixes
will be transformed inbugfixes
, and that's the reason why it's named that way in thecommitGroupsOrder
array. The order is based on thecommitGroupsOrder
values : the lower the section is, the higher it will appear in theCHANGELOG.md
.
Feel free to use this short code and try it out with semantic-release --dry-run
.
from release-notes-generator.
๐
Is there a way to print on stdout the generated changelog
Sure, you can use --dry-run
to test things out as far as I know.
semantic-release --dry-run
from release-notes-generator.
Ah, it looks like you put your writerOpts
inside presetConfig
.
Instead, place the writerOpts
next to presetConfig
(on the same level). Should work then ๐
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [...]
},
"writerOpts": {
"commitGroupsSort": <your function here>
}
}
from release-notes-generator.
Yeah, it also took me a good while to find out where the heck do the options get finally merged.
For me it was at conventional-changelog-writer/index.js:42. And at the line 77 the commitGroupsSort
becomes a function. You can put console.log
somere before that to see if your value gets there.
So, overall, conventionalcommits
preset sets default commitGroupsSort
here and then that value can be overridden using plugin's writerOpts
, which happens in this call chain:
- semantic-release/release-notes-generator/.../index.js:32
- conventional-changelog/conventional-changelog/.../conventional-changelog-writer/index.js:87
- conventional-changelog/conventional-changelog/.../conventional-changelog-writer/index.js:42
from release-notes-generator.
Thank you, @amariq . I have updated my comment to say it worked with your fix. It was my fault to not test with multiple types of commits, duh! I then tried to test it multiple types of commits (feat, fix, breaking etc) and it worked! Thank you again, for debugging this for me. Really appreciate it.
from release-notes-generator.
I had the same issue, and its because commitGroupsSort
accepts not commit types but some object's property name/path and then the value of that property is used to sort the commits.
So by default it's title
property, and if you want to sort by type then you need to provide commitGroupsSort
as a comparator function (example). It would require to use .releaserc.js
as a config though.
from release-notes-generator.
Thanks a lot for the clarification, I will try it out as soon as possible. Is there a way to print on stdout the generated changelog in order to test ?
When I'll have the right solution, I'll post it here for future readers with the same problem as mine.
from release-notes-generator.
I have tried it with .releaserc.js
, but it doesn't seem to overwrite the commitGroupsSort
function. Could you please provide an example where it works with preset set to conventionalcommits
for @semantic-release/release-notes-generator
plugin?
from release-notes-generator.
๐ค
It should be something like that, I think:
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"writerOpts": {
"commitGroupsSort": <your function here>
}
}
from release-notes-generator.
I have this:
["@semantic-release/release-notes-generator", {
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "breaking",
"section": "Breaking Changes",
"hidden": false
},
{
"type": "feat",
"section": "New Features",
"hidden": false
},
{
"type": "fix",
"section": "Bug Fixes",
"hidden": false
}
],
"writerOpts": {
"commitGroupsSort": (a, b) => {
console.log("called", [a, b])
throw new Error([a, b])
}
}
}
}],
and the output is:
## 1.11.1-beta.1 (2023-04-17)
### New Features
* Some change (bdd860a)
and without the writerOpts
, the output is also the same.
So I think that the custom writerOpts aren't getting replaced. Looking at the code too, it doesn't seem like it overrides the vars.
from release-notes-generator.
ah, I am sorry. I tried again with the fix, It worked as expected! Thank you ๐ ๐
from release-notes-generator.
Related Issues (20)
- Looking for a way to print the generated snippet to a file other than changelog HOT 1
- Upgrade peer dependency semantic-release to version 19.0.3 or later to fix known vulnerability HOT 1
- Refactor & chore commits not getting includes in changelog HOT 3
- Release notes generation with Bitbucket
- question: link to both GH PR numbers and external issues
- Question: conventionalcommits preset with PR owner
- Defining the commitPartial voids other wirter and presetConfig options
- I need to include other commits than `feat` and `fix`. HOT 3
- An error occurred while running semantic-release: Error [ERR_REQUIRE_ESM] HOT 7
- wrong Gitlab issue link in release notes HOT 20
- Plugin ends up abruptly without completition or error, making other plugins not to start HOT 12
- Wrong commit link for Bitbucket HOT 3
- `release skip`-ed commits still get into release notes
- Links to PRs and Contributors list HOT 2
- `MODULE_NOT_FOUND` when running with `npx` HOT 5
- Unexpected behavior for major updates with conventionalcommits preset HOT 2
- self-hosted GitLab - no issue links in release notes
- Question: Merging pre-release branches & generated changelog
- Question: Mirror release rules to release notes generator? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from release-notes-generator.