semantic-release / commit-analyzer

:bulb: semantic-release plugin to analyze commits with conventional-changelog
MIT License
373 stars 74 forks source link

Adding ReleaseRules types list is working fine with release versioning but Changelog commits are empty. #234

Open isabr85 opened 3 years ago

isabr85 commented 3 years ago

I've added to @semantic-release/commit-analyzer plugin a list of types under releaseRules:

module.exports = {
    branches: [
        '+([0-9])?(.{+([0-9]),x}).x',
        'main', 
        'dev',
    'master'
    ],
    plugins: [
        ["@semantic-release/commit-analyzer", {
          preset: "angular",
          releaseRules: [
            {type: "docs", release: "patch"},
            {type: "refactor", release: "patch"},
            {type: "ci", release: "patch"},
            {type: "style", release: "patch"},
            {type: "test", release: "patch"},
            {type: "chore", release: "patch"}
          ]
        }],
        ['@semantic-release/release-notes-generator', {
            writerOpts: {
                finalizeContext: function (context) {
                    return {
                        ...context,
                        repository: 'myRepository',
                        owner: 'ownerName',
                        repoUrl: 'https://dev.azure.com',
                        commit: '_git/projectName/commit',
                        linkCompare: false
                    };
                }
            },
            host: 'https://dev.azure.com',
            issue: '_workitems/edit'
        }],
        '@semantic-release/changelog'
    ],
    prepare: [
        ["@semantic-release/exec", {
            "prepareCmd": 'echo ##vso[task.setvariable variable=nextRelease]${nextRelease.version}'
        }],
        '@semantic-release/changelog',
        [ 
            '@semantic-release/git',
            { 
                message: 'ci(release): <%= nextRelease.version %> \n\n<%= nextRelease.notes %>'
            }
        ] 
    ]
}; 

It seems to be fine, when I make a commit of one of the types displayed in the list I can clearly see that release version is being increasing according to my definition. But then I am looking at CHANGELOG.md file and it seems that commits are not being written and it left blanked.

image

Any idea what can cause this issue? I tried to search for a solution for this scenario few days and I feel I don't have any way to solve it by my own.

Can you tell me what is wrong with my script?

tmeijn commented 3 years ago

So the commit analyzer has nothing to do with writing the changelog. It just tells semantic-release whether there should be a release or not.

@semantic-release/release-notes-generator determines which commit types show up in the changelog and IIRC default it's just feat and fix types.

I'll share part of my config show you hopefully you'll get the idea:


[
      "@semantic-release/release-notes-generator",
      {
        "preset": "conventionalcommits",
        "presetConfig": {
          "types": [
            {
              "type": "feat",
              "section": "New Feature(s) 🚀"
            },
            {
              "type": "fix",
              "section": "Bug Fix(es) 🐛️"
            },
            {
              "type": "docs",
              "section": "Documentation Changes 📝"
            },
            {
              "type": "refactor",
              "section": "Code Refactoring 💅"
            },
            {
              "type": "test",
              "section": "Tests 📡️"
            },
            {
              "type": "perf",
              "section": "Performance Improvement(s) 🚄️"
            },
            {
              "type": "build",
              "section": "Build system 🛠️"
            }
          ]
        }
      }
    ],

Let me know if this helps 😄

arkadioz commented 10 months ago

@tmeijn this worked and helped understand what was going on with the empty changelog, but I notice that for the breaking changes it is using a section called ⚠ BREAKING CHANGES, I tried to change this by using the same config you provided but adding another config at the start (just added it for feat! to see if it works but not so far):

[
      "@semantic-release/release-notes-generator",
      {
        "preset": "conventionalcommits",
        "presetConfig": {
          "types": [
            {
              "breaking": true,
              "type": "feat!",
              "section": "BREAKING"
            },
            {
              "type": "feat",
              "section": "New Feature(s) 🚀"
            },
            {
              "type": "fix",
              "section": "Bug Fix(es) 🐛️"
            },
            {
              "type": "docs",
              "section": "Documentation Changes 📝"
            },
            {
              "type": "refactor",
              "section": "Code Refactor 💅"
            },
            {
              "type": "test",
              "section": "Tests 📡️"
            },
            {
              "type": "perf",
              "section": "Performance Improvement(s) 🚄️"
            },
            {
              "type": "build",
              "section": "Build system 🛠️"
            }
          ]
        }
      }
    ]

In other words I could not figure out how to change the section name for the breaking changes, appreciate any help/guidance/guesses

tmeijn commented 9 months ago

Hey @arkadioz, sorry for the late response, but that section is hard coded in the conventionalcommits package. I started an effort a long time ago (https://github.com/conventional-changelog/conventional-changelog/pull/981/files) to make it configurable, but abandoned the PR it will likely not get to it soon/at all.