0

Using @semantic-release I'd like to consider refactor changes for both, triggering a new release and write down in the CHANGELOG.md file.

So far, I've included refactor commits at "@semantic-release/commit-analyzer" so they are triggering a patch release:

[
  "@semantic-release/commit-analyzer",
  {
    "preset": "angular",
    "releaseRules": [
      {
        "type": "refactor",
        "release": "patch"
      }
    ]
  }
],      

But those commit msgs aren't included in the CHANGELOG file, how can I setup "@semantic-release/release-notes-generator" plugin for including refactor commits? I find related doc confusing and lack of examples


  1. generated CHANGELOG example
## [0.6.4](.../compare/v0.6.3...v0.6.4) (date)

## [0.6.3](.../compare/v0.6.2...v0.6.3) (date)
  1. desired CHANGELOG
## [0.6.4](.../compare/v0.6.3...v0.6.4) (date)

[[>>INCLUDE HERE COMMIT MSG + LINK<<]]

## [0.6.3](.../compare/v0.6.2...v0.6.3) (date)
Manu Artero
  • 9,238
  • 6
  • 58
  • 73

2 Answers2

3

If anyone finds this useful: we need to config "@semantic-release/release-notes-generator" for considering other keywords besides feat and fix including these dicts:

{
   "type": "refactor",
   "section": "title to be used in changelog.md",
   "hidden": false
}

For copy-pasting, this setup is gathering both refactor, chore and perf into ## Internal section (note i needed to write explicitly default values, I guess this is because it's overriding the config)

[
  "@semantic-release/release-notes-generator",
  {
    "preset": "conventionalCommits",
    "parserOpts": {
      "noteKeywords": [
        "BREAKING CHANGE",
        "BREAKING CHANGES",
        "BREAKING"
      ]
    },
    "presetConfig": {
      "types": [
        {
          "type": "feat",
          "section": "Features"
        },
        {
          "type": "fix",
          "section": "Bug Fixes"
        },
        {
          "type": "chore",
          "section": "Internal",
          "hidden": false
        },
        {
          "type": "refactor",
          "section": "Internal",
          "hidden": false
        },
        {
          "type": "perf",
          "section": "Internal",
          "hidden": false
        }
      ]
    }
  }
]
Manu Artero
  • 9,238
  • 6
  • 58
  • 73
3

The above answer is correct, but I feel its a bit incomplete. Even after adding the above commit types, the release will not be triggered on all the commit types. If you wish to trigger the release on all or selected commit types (ex. refactor, docs ci etc.) you can use the configuration as below:

// release.config.js

module.exports = {
  plugins: [
    [
      '@semantic-release/commit-analyzer',
      {
        preset: 'conventionalCommits',
        releaseRules: [
          { type: 'revert', scope: '*', release: 'patch' },
          { type: 'docs', scope: '*', release: 'patch' },
          { type: 'style', scope: '*', release: 'patch' },
          { type: 'chore', scope: '*', release: 'patch' },
          { type: 'refactor', scope: '*', release: 'patch' },
          { type: 'test', scope: '*', release: 'patch' },
          { type: 'build', scope: '*', release: 'patch' },
          { type: 'ci', scope: '*', release: 'patch' },
          { type: 'improvement', scope: '*', release: 'patch' },
        ],
      },
    ],
    [
      '@semantic-release/release-notes-generator',
      {
        preset: 'conventionalCommits',
        presetConfig: {
          types: [
            { type: 'feat', section: 'Features' },
            { type: 'fix', section: 'Bug Fixes' },
            { type: 'perf', section: 'Performance Improvements' },
            { type: 'revert', section: 'Reverts' },
            { type: 'docs', section: 'Documentation', hidden: false },
            { type: 'style', section: 'Styles', hidden: false },
            { type: 'chore', section: 'Miscellaneous Chores', hidden: false },
            { type: 'refactor', section: 'Code Refactors', hidden: false },
            { type: 'test', section: 'Tests', hidden: false },
            { type: 'build', section: 'Build System', hidden: false },
            { type: 'ci', section: 'CI/CD', hidden: false },
            { type: 'improvement', section: 'Improvements', hidden: false },
          ],
        },
      },
    ],
    ['@semantic-release/github'],
    [
      '@semantic-release/npm',
      {
        npmPublish: false,
      },
    ],
    '@semantic-release/changelog',
    '@semantic-release/git',
  ],
  branch: 'master',
};
Working of the above config:

@semantic-release/commit-analyzer will trigger the release for feat, fix & BREAKING CHANGE as usual. I've only added the rest of the types that are ignored by default. Needless to say that they will be considered as patches and will only bump the patch number from semantic versioning in your tags, release notes, changelog & package.json file.

@semantic-release/release-notes-generator will just make sure that the commits are grouped correctly based on the type and will display my custom headings defined with the section key.

Hope this helps someone in future!
Salvino D'sa
  • 4,018
  • 1
  • 7
  • 19