How to regenerate changelog using standard-version

How to regenerate changelog using standard-version

I had a very short project (a dozen commits) which I wanted to convert to use conventional commits. Let me describe this non-conventional procedure I had to follow.

Introduction

I wrote an introduction to conventional commits and standard-version in the previous post:

Repository

The first step was editing all commit messages to align them with the convention (git rebase -i <first commit>).

Next, I moved all existing tags to the new commits. After editing the messages, the history was rewritten and new commits were created. Thus, the existing tags pointed to old commits. I had to point them to the corresponding new commits, which was quite tedious, as for every tag I had to issue the command:

git tag -f <new version> <new hash>
e.g. git tag -f v1.0.2 fc32ca5

Configuration

I added the standard-version package to the project and created the release script:

JSON
package.json

Because that project will not have many changes, I decided to include a full log by using the full .versionrc template.

Generate changes

There are command-line switches for standard-version that disable any steps. As I wanted to only generate the changelog without bumping version, committing or tagging, I tried to run:

npm run release -- --skip.bump --skip.tag --skip.commit

The CHANGELOG.md file was created, but it only contained a header. I tried jumping through the git history to the tag versions or before the versions and generate the log in parts, but that also failed. Finally, I debugged the standard-version script and I found that internally it used an option called releaseCount that allowed to process more than the most recent version tag. Unfortunately, passing --releaseCount=0, --releaseCount=4, --release-count=4 etc. did not have any effect.

The releaseCount option is used in the following context:

JS
node_modules/conventional-changelog-core/lib/merge-config.js

To stop wasting more time, I temporarily changed fromTag to:

fromTag = gitSemverTags[gitSemverTags.length - 1]

and generated the changelog again:

npm run release -- --skip.bump --skip.tag --skip.commit

Now the CHANGELOG.md file contained all changes from all versions.

Well, almost all – except for the first version. To overcome this, I added a tag to the very first commit in my history:

git tag v0.0.0 dc49d7f

After removing the CHANGELOG.md file and running the npm command again, I had a full log from the beginning. You can see the result in https://github.com/lukaszmn/Simple-Build-Kit.

Leave a Reply

avatar
  Subscribe  
Notify of