pmowrer / semantic-release-monorepo

Apply semantic-release's automatic publishing to a monorepo.
MIT License
522 stars 80 forks source link

Customize generateNotes configuration #83

Closed elizabethsjudd closed 4 years ago

elizabethsjudd commented 4 years ago

We are using semantic-release and semantic-release-monorepo in our project and want to modify the default conventional-changelog-angular writerOpts configuration (specifically the transform function).

Following the guidelines for semantic release, I added the function at the root of the config object and my changes were applied to the changelog notes in GH.

module.exports = {
  branches: ['master'],
  githubUrl: 'https://github.ibm.com',
  githubApiPathPrefix: 'api/v3',
  releaseRules: [...],
  generateNotes: {
    preset: 'angular',
    writerOpts: {
      transform: (commit, context) => {...},
    }
  },
  releaseNotes: {
    issueResolution: {
      template: '{baseUrl}/{owner}/{repo}/issues/{ref}',
      baseUrl: 'https://github.ibm.com',
      source: 'github.ibm.com',
    },
  },
}

However, with this approach we lost the commit package scoping that is provided by semantic-release-monorepo.

In a different project we use semantic-release-gitmoji as our changelog convention and were able to set it up to work with semantic-release-monorepo by doing the following:

module.exports = {
  monorepo: {
    analyzeCommits: 'semantic-release-gitmoji',
    generateNotes: 'semantic-release-gitmoji',
  },
  branches: ['develop'],
  githubUrl: 'https://github.ibm.com',
  githubApiPathPrefix: 'api/v3',
  releaseRules,
  releaseNotes: {
    template,
    partials: {
      commitTemplate,
      emojiCommitsTemplate,
    },
    issueResolution: {
      template: '{baseUrl}/{owner}/{repo}/issues/{ref}',
      baseUrl: 'https://github.ibm.com',
      source: 'github.ibm.com',
    },
  },
};

I tried to do something similar in my current project:

module.exports = {
  monorepo: {
    generateNotes: {
      preset: 'angular',
      writerOpts: {
        transform: (commit, context) => {...},
      }
    },
  },
  branches: ['master'],
  githubUrl: 'https://github.ibm.com',
  githubApiPathPrefix: 'api/v3',
  releaseRules: [...],
  releaseNotes: {
    issueResolution: {
      template: '{baseUrl}/{owner}/{repo}/issues/{ref}',
      baseUrl: 'https://github.ibm.com',
      source: 'github.ibm.com',
    },
  },
}

but did not have any luck as it reverted back to using the default transform function

Debug with generateNotes in monorepo:

options values: { branches:
  [ 'master',
    { name: 'staging', prerelease: true } ],
 repositoryUrl: 'git@github.ibm.com:liz-judd/semantic-release-testing.git',
 tagFormat: '@whpal/liz-semrel-testing-utilities-v${version}',
 plugins:
  [ '@semantic-release/commit-analyzer',
    '@semantic-release/release-notes-generator',
    '@semantic-release/npm',
    '@semantic-release/github' ],
 analyzeCommits:
  [ [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction] ],
 generateNotes:
  [ [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction] ],
 monorepo:
  { generateNotes: { preset: 'angular', writerOpts: [Object] } },
 githubUrl: 'https://github.ibm.com',
 githubApiPathPrefix: 'api/v3',
 releaseRules:  [ ... ],
 releaseNotes:
  { issueResolution:
     { template: '{baseUrl}/{owner}/{repo}/issues/{ref}',
       baseUrl: 'https://github.ibm.com',
       source: 'github.ibm.com' } },
 }

Debug with generateNotes at root:

options values: { branches:
  [ 'master',
    { name: 'staging', prerelease: true } ],
 repositoryUrl: 'git@github.ibm.com:liz-judd/semantic-release-testing.git',
 tagFormat: '@whpal/liz-semrel-testing-utilities-v${version}',
 plugins:
  [ '@semantic-release/commit-analyzer',
    '@semantic-release/release-notes-generator',
    '@semantic-release/npm',
    '@semantic-release/github' ],
 analyzeCommits:
  [ [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction],
    [AsyncFunction] ],
 generateNotes:
  { preset: 'angular',
    writerOpts: { transform: [Function: transform] } },
 githubUrl: 'https://github.ibm.com',
 githubApiPathPrefix: 'api/v3',
 releaseRules: [...],
 releaseNotes:
  { issueResolution:
     { template: '{baseUrl}/{owner}/{repo}/issues/{ref}',
       baseUrl: 'https://github.ibm.com',
       source: 'github.ibm.com' } },
}
elizabethsjudd commented 4 years ago

FYI, After going through some closed issues I also tried the following without any luck:

module.exports = {
  monorepo: {
    plugins:[
      '@semantic-release/commit-analyzer',
      ['@semantic-release/release-notes-generator', {
        preset: 'angular',
        writerOpts: {
          transform: (commit, context) => {...},
        }
      }],
      '@semantic-release/npm',
      '@semantic-release/github'
    ],
  },
  branches: ['master'],
  githubUrl: 'https://github.ibm.com',
  githubApiPathPrefix: 'api/v3',
  releaseRules: [ ... ],
  releaseNotes: {
    issueResolution: {
      template: '{baseUrl}/{owner}/{repo}/issues/{ref}',
      baseUrl: 'https://github.ibm.com',
      source: 'github.ibm.com',
    },
  },
}
pmowrer commented 4 years ago

Thanks for the report, @elizabethsjudd! Does it work if you move the plugins key to the top-level?

E.g.:

module.exports = {
  plugins: [
    '@semantic-release/commit-analyzer',
    ['@semantic-release/release-notes-generator', {
      preset: 'angular',
      writerOpts: {
        transform: (commit, context) => {...},
      }
    }],
    '@semantic-release/npm',
    '@semantic-release/github'
  ],
  branches: ['master'],
  githubUrl: 'https://github.ibm.com',
  githubApiPathPrefix: 'api/v3',
  releaseRules: [ ... ],
  releaseNotes: {
    issueResolution: {
      template: '{baseUrl}/{owner}/{repo}/issues/{ref}',
      baseUrl: 'https://github.ibm.com',
      source: 'github.ibm.com',
    },
  },
}
elizabethsjudd commented 4 years ago

@pmowrer That doesn't even create the custom release notes at all. Is this something I should be bring up with release-notes-generator as semantic-release-monorepo is expecting this format?

pmowrer commented 4 years ago

It depends on what version of semantic-release-monorepo and semantic-release you're trying this with. The monorepo namespace key in the config was deprecated as of v7 of this lib and would have no effect.

elizabethsjudd commented 4 years ago

@pmowrer these are the versions I'm using. So it looks like I shouldn't be using the monorepo property at all.

    "semantic-release": "^17.0.4",
    "semantic-release-monorepo": "^7.0.1"

I guess my confusion is... is this a bug for:

pmowrer commented 4 years ago

It's most likely a bug with this library... I'll dig into it!

pmowrer commented 4 years ago

I believe this has been fixed in the latest version (7.0.2). Please re-open if it's still an issue.

pmowrer commented 4 years ago

:tada: This issue has been resolved in version 7.0.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

elizabethsjudd commented 4 years ago

@pmowrer, I updated our version of monorepo to 7.0.2 and am still having the same issue where defining a custom generateNotesobject (at the root of the config) does not scope the commits to the specific packages.

Example both of the commits under build system should not be part of a thing4 package release as they are part of a utilities package (these screen shots are a dummy repo we use for testing)

Screen Shot 2020-04-06 at 10 14 50 AM

I'm also now running in to the issue of it not recognizing our custom releaseRules property either. I used to be able to have a release with the build type and now that is no longer possible.

Here's our release rules:

[
    {breaking: true, release: 'major'},
    {revert: true, release: 'patch'},
    {type: 'feat', release: 'minor'},
    {type: 'fix', release: 'patch'},
    {type: 'perf', release: 'patch'},
    {type: 'docs', release: 'patch'},
    {type: 'style', release: 'patch'},
    {type: 'test', release: 'patch'},
    {type: 'build', release: 'patch'},
    {type: 'ci', release: 'patch'},
    {type: 'refactor', release: 'patch'},
  ],

but when I have a merge with only a build type, our CI system says it does not detect any changes

[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  There are no relevant changes, so no new version is released.
pmowrer commented 4 years ago

@elizabethsjudd Thanks for trying this out and sorry it still isn't working! A few questions as I try to diagnose this further:

elizabethsjudd commented 4 years ago

Release config:

{ branches:
   [ 'master',
     { name: 'staging', prerelease: true },
     { name: 'v1', channel: 'v1x' },
     { name: 'next', prerelease: true } ],
  githubUrl: 'https://github.ibm.com',
  githubApiPathPrefix: 'api/v3',
  releaseRules:
   [ { breaking: true, release: 'major' },
     { revert: true, release: 'patch' },
     { type: 'feat', release: 'minor' },
     { type: 'fix', release: 'patch' },
     { type: 'perf', release: 'patch' },
     { type: 'docs', release: 'patch' },
     { type: 'style', release: 'patch' },
     { type: 'test', release: 'patch' },
     { type: 'build', release: 'patch' },
     { type: 'ci', release: 'patch' },
     { type: 'refactor', release: 'patch' },
     { scope: 'minor-*', release: 'minor' },
     { scope: 'patch-*', release: 'patch' },
     { scope: 'no-release', release: false } ],
  releaseNotes:
   { issueResolution:
      { template: '{baseUrl}/{owner}/{repo}/issues/{ref}',
        baseUrl: 'https://github.ibm.com',
        source: 'github.ibm.com' } },
  generateNotes:
   { preset: 'angular',
     writerOpts: { transform: [Function: transform] } },
  tagFormatPrefix: '@whpal/liz-semrel-testing-',
  tagFormat: '@whpal/liz-semrel-testing-utilities-v${version}' }

We do not have any custom plugin setup.

Here's the config that's printed out from the --debug flag

semantic-release:config options values: { branches:
  semantic-release:config    [ 'master',
  semantic-release:config      { name: 'staging', prerelease: true },
  semantic-release:config      { name: 'v1', channel: 'v1x' },
  semantic-release:config      { name: 'next', prerelease: true } ],
  semantic-release:config   repositoryUrl: 'git@github.ibm.com:liz-judd/semantic-release-testing.git',
  semantic-release:config   tagFormat: '@whpal/liz-semrel-testing-utilities-v${version}',
  semantic-release:config   plugins:
  semantic-release:config    [ '@semantic-release/commit-analyzer',
  semantic-release:config      '@semantic-release/release-notes-generator',
  semantic-release:config      '@semantic-release/npm',
  semantic-release:config      '@semantic-release/github' ],
  semantic-release:config   analyzeCommits:
  semantic-release:config    [ [AsyncFunction: semantic-release-monorepo],
  semantic-release:config      [AsyncFunction: semantic-release-monorepo],
  semantic-release:config      [AsyncFunction: semantic-release-monorepo],
  semantic-release:config      [AsyncFunction: semantic-release-monorepo],
  semantic-release:config      [AsyncFunction: semantic-release-monorepo],
  semantic-release:config      [AsyncFunction: semantic-release-monorepo],
  semantic-release:config      [AsyncFunction: semantic-release-monorepo],
  semantic-release:config      [AsyncFunction: semantic-release-monorepo],
  semantic-release:config      [AsyncFunction: semantic-release-monorepo],
  semantic-release:config      [AsyncFunction: semantic-release-monorepo] ],
  semantic-release:config   generateNotes:
  semantic-release:config    { preset: 'angular',
  semantic-release:config      writerOpts: { transform: [Function: transform] } },
  semantic-release:config   githubUrl: 'https://github.ibm.com',
  semantic-release:config   githubApiPathPrefix: 'api/v3',
  semantic-release:config   releaseRules:
  semantic-release:config    [ { breaking: true, release: 'major' },
  semantic-release:config      { revert: true, release: 'patch' },
  semantic-release:config      { type: 'feat', release: 'minor' },
  semantic-release:config      { type: 'fix', release: 32m'patch' },
  semantic-release:config      { type: 'perf', release: 'patch' },
  semantic-release:config      { type: 'docs', release: 'patch' },
  semantic-release:config      { type: 'style', release: 'patch' },
  semantic-release:config      { type: 'test', release: 'patch' },
  semantic-release:config      { type: 'build', release: 'patch' },
  semantic-release:config      { type: 'ci', release: 'patch' },
  semantic-release:config      { type: 'refactor', release: 'patch' },
  semantic-release:config      { scope: 'minor-*', release: 'minor' },
  semantic-release:config      { scope: 'patch-*', release: 'patch' },
  semantic-release:config      { scope: 'no-release', release: false } ],
  semantic-release:config   releaseNotes:
  semantic-release:config    { issueResolution:
  semantic-release:config       { template: '{baseUrl}/{owner}/{repo}/issues/{ref}',
  semantic-release:config         baseUrl: 'https://github.ibm.com',
  semantic-release:config         source: 'github.ibm.com' } },
  semantic-release:config   tagFormatPrefix: '@whpal/liz-semrel-testing-',
  semantic-release:config   _: [],
  semantic-release:config   debug: true,
  semantic-release:config   '$0': 'node_modules/.bin/semantic-release' } 

The config is in a release.config.js file and in the root of our package.json we include:

"release": {
    "extends": [
      "semantic-release-monorepo",
      "./release.config"
    ]
  }

Using a JavaScript file allows us to break up the config in to multiple objects and share them across the multiple packages in the monorepo.


Here's the output of the debug from the packages that had changes in this particular push

[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
  semantic-release:monorepo Running 'analyzeCommits' version '7.0.2' +0ms
  semantic-release:monorepo Filter commits by package path: "packages/thing2" +0ms
  semantic-release:monorepo Including commit "build: trying to debug" because it modified package file "packages/thing2/README.md". +117ms
  semantic-release:monorepo Including commit "build: update semantic release monorepo version" because it modified package file "packages/thing2/package-lock.json". +0ms
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  Found 2 commits for package @whpal/liz-semrel-testing-thing2 since last release
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  Analyzing commit: build: trying to debug
  semantic-release:commit-analyzer Analyzing with default rules +0ms
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  The commit should not trigger a release
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  Analyzing commit: build: update semantic release monorepo version
  semantic-release:commit-analyzer Analyzing with default rules +1ms
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  The commit should not trigger a release
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  Analysis of 2 commits complete: no release
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] 90m› ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔ 39m Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  There are no relevant changes, so no new version is released.

and

[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
  semantic-release:monorepo Running 'analyzeCommits' version '7.0.2' +0ms
  semantic-release:monorepo Filter commits by package path: "packages/utilities" +0ms
  semantic-release:monorepo Including commit "build: trying to debug" because it modified package file "packages/utilities/release.config.js". +49ms
  semantic-release:monorepo Including commit "build: testing releaseRules" because it modified package file "packages/utilities/release.config.common.js". +0ms
  semantic-release:monorepo Including commit "bug: fix JS bug in generateNotes function" because it modified package file "packages/utilities/release.config.common.js". +0ms
  semantic-release:monorepo Including commit "build: revert changes for generateNotes" because it modified package file "packages/utilities/release.config.common.js". +0ms
  semantic-release:monorepo Including commit "build: update semantic release monorepo version" because it modified package file "packages/utilities/package-lock.json". +0ms
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  Found 5 commits for package @whpal/liz-semrel-testing-utilities since last release
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  Analyzing commit: build: trying to debug
  semantic-release:commit-analyzer Analyzing with default rules +0ms
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  The commit should not trigger a release
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  Analyzing commit: build: testing releaseRules
  semantic-release:commit-analyzer Analyzing with default rules +1ms
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  The commit should not trigger a release
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  Analyzing commit: bug: fix JS bug in generateNotes function
  semantic-release:commit-analyzer Analyzing with default rules +1ms
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  The commit should not trigger a release
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  Analyzing commit: build: revert changes for generateNotes
  semantic-release:commit-analyzer Analyzing with default rules +0ms
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  The commit should not trigger a release
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  Analyzing commit: build: update semantic release monorepo version
  semantic-release:commit-analyzer Analyzing with default rules +0ms
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  The commit should not trigger a release
[semantic-release] [[Function: semantic-release-monorepo]] › ℹ  Analysis of 5 commits complete: no release
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › 32m✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  Start step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ✔  Completed step "analyzeCommits" of plugin "[Function: semantic-release-monorepo]"
[semantic-release] › ℹ  There are no relevant changes, so no new version is released.

Let me know if you need anything else and thank you for looking in to this.

pmowrer commented 4 years ago

That release config is using the old format semantic-release format. As of version 15.10, most of the configuration has been moved into the plugins. None of githubUrl, githubApiPathPrefix, releaseRules , releaseNotes, generateNotes are valid top-level configuration keys anymore - I think that's why the release rules aren't being applied anymore.

See the current top-level config options here: https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration

(I'd recommend running the latest version of this plugin with the latest version of semantic-release.)

Here's roughly what I think your config should look like. Please reference the individual plugin READMEs via semantic-release for their respective configuration options:

https://github.com/semantic-release/commit-analyzer https://github.com/semantic-release/github https://github.com/semantic-release/release-notes-generator

module.exports = {
  branches: ...,
  plugins: [
    ['@semantic-release/commit-analyzer', {
      "releaseRules": [ 
       { breaking: true, release: 'major' },
       { revert: true, release: 'patch' },
       { type: 'feat', release: 'minor' }, 
       ...
       ]
    }],
    ['@semantic-release/release-notes-generator', {
      preset: 'angular',
      writerOpts: {
        transform: (commit, context) => {...},
      }
    }],
    '@semantic-release/npm',
    ['@semantic-release/github', {
      githubUrl: 'https://github.ibm.com',
      githubApiPathPrefix: 'api/v3',
    }]
  ],
}
elizabethsjudd commented 4 years ago

That did the trick @pmowrer. Thank you so much for your help!

its-dibo commented 2 years ago

I have a similar issue with npm options

described here