I am trying to configure semantic release to include the subject, body and footer of the commit messages in CHANGELOG.md
file, not just the subject of commit message, but no success. In my changelog I still have only the short subject of commit messages. Is there a way to set the semantic-release at this way?
Any suggestions will be helpful for me.
This can be done, but it's not exactly straightforward. The key is to set
writerOpts
for the@semantic-release/release-notes-generator
plugin.In the following example
release.config.js
file which is used to configure semantic-release, I'm setting two options:preset
(you can use a different preset) andwriterOpts
(the important parts).First, let's look at
writerOpts.commitPartial
. I'm loading a modified template that I've stored in thechangelog-template-commit.hbs
file:This is a slightly modified version of the original commit template the conventionalcommits preset uses. I've commented the changes I made to it inside the file. At the bottom, you'll find the additions for adding the commit body and breaking changes notes that I made.
For this to work, the
writerOpts.finalizeContext
option in the config above is needed. It takes each commit'sbody
and turns it into a line by line array. You could technically use thebody
in the template and not worry about this, but it won't be correctly indented if you have multiple body lines. This is taken care of in my version.This is probably not perfect and I wish conventional-changelog (which is used by
@semantic-release/release-notes-generator
) would provide some of this functionality out of the box, but it works for me.Note that I haven't fully considered all pieces of information that could be in a commit footer like references that might be handled different here by the plugin. You might need to make some more adjustments.
Oh, yes, and I highly recommend trying this locally first using
npx semantic-release --dryRun
.