Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Conventional commits do not respect '!' or "BREAKING CHANGE" #2668

Open
alexforsyth opened this issue Jul 23, 2020 · 20 comments
Open

Bug: Conventional commits do not respect '!' or "BREAKING CHANGE" #2668

alexforsyth opened this issue Jul 23, 2020 · 20 comments

Comments

@alexforsyth
Copy link

alexforsyth commented Jul 23, 2020

Lerna conventional commits do not respect '!' as denoting a breaking change when part of the 'types' on a conventional commit. Additionally, It seems like including the '!' may make lerna not recognize that commit as a valid conventional commit in some cases. This repo also highlights this problem.

EDIT: Looks like “BREAKING CHANGE:” is also not being respected.

Repro repo:
https://github.com/alexforsyth/lerna-conventional-commits

Expected Behavior

The generated changelog should list breaking changes, when a '!' is included on a type.

ex. 2 from conventional commits

refactor!: drop support for Node 6

Should be equal to using the BREAKING CHANGE: phrase in the footer.

Current Behavior

The generated changelog does not include the change when '!' is included on a type.

ex.

refactor!: drop support for Node 6

Possible Solution

Steps to Reproduce (for bugs)

This repo is a live example that highlights this problem.

@alexforsyth
Copy link
Author

Bump

@alexforsyth alexforsyth changed the title Conventional commits do not respect '!' on types Conventional commits do not respect '!' or "BREAKING CHANGE" Oct 13, 2020
@alexforsyth alexforsyth changed the title Conventional commits do not respect '!' or "BREAKING CHANGE" Bug: Conventional commits do not respect '!' or "BREAKING CHANGE" Oct 13, 2020
@kamsar
Copy link

kamsar commented Oct 14, 2020

The default settings uses conventional-changelog-angular which is not the conventional commits spec, and doesn't support !.

It will work if you add --changelog-preset conventionalcommits, see #2138

Also in your repro, you're explicitly specifying the bump as minor, which overrides using conventional commits to determine the desired bump - maybe that's what you want, though.

https://github.com/alexforsyth/lerna-conventional-commits/blob/b575a9278be8ea053a8e1617014fe9be679d1272/package.json#L12

@kamsar
Copy link

kamsar commented Oct 14, 2020

This can also be specified in lerna.json: https://github.com/lerna/lerna/tree/master/commands/version#--create-release-type

i.e.

{
  "changelogPreset": {
    "name": "conventionalcommits",
    "issueUrlFormat": "{{host}}/{{owner}}/{{repository}}/issues/{{id}}"
  }
}

@mrchief
Copy link

mrchief commented Mar 8, 2021

I'm seeing the same issue with lerna 3.2 and v4. Adding

{
  "changelogPreset": {
    "name": "conventionalcommits",
    "issueUrlFormat": "{{host}}/{{owner}}/{{repository}}/issues/{{id}}"
  }
}

has no effect.

@mrchief
Copy link

mrchief commented Mar 8, 2021

Digging further I found this:
image

which is the right behavior as button has breaking changes.

which seems to be related to #2761, #2766

After upgrading packages to 1.x, versioning seems to do the right thing (respect feat!:...)

image

@xiaoxinghu
Copy link

how do we get major version bump to work? I am using v4 and I tried with commit messages have both ! and/or BREAKING CHANGE: all over the place, I still get minor. Here is my Lerna config:

{
  "version": "2.6.0",
  "npmClient": "yarn",
  "useWorkspaces": true,
  "command": {
    "version": {
      "allowBranch": "master",
      "conventionalCommits": true,
      "createRelease": "github",
      "exact": true,
      "message": "chore(release): %s"
    }
  },
  "ignoreChanges": ["**/__tests__/**", "**/*.test.ts"],
  "packages": ["packages/*"]
}

and I use lerna publish --yes in ci.

@privatenumber
Copy link

privatenumber commented Sep 1, 2021

If your package is in major version zero (eg. v0.x.y), the semver rules are shifted over, so breaking changes happen in v0.x.0, and features & patches happen in v0.0.y.

Therefore, a breaking change in a package that is in 0.x.y, will only bump x.

I wish this was better documented, but it's in the npm docs:

^1.2.3 := >=1.2.3 <2.0.0
^0.2.3 := >=0.2.3 <0.3.0
^0.0.3 := >=0.0.3 <0.0.4


Requested for improved documentation around this here.

@richardkazuomiller
Copy link
Contributor

I also can't get BREAKING CHANGE to work in my project. Has anyone figured this out? 🤔

@privatenumber
Copy link

@richardkazuomiller

Provide your lerna configuration and the package.json of your subpackage so others can help

@richardkazuomiller
Copy link
Contributor

lerna.json

{
  "packages": [
    "packages/*"
  ],
  "version": "1.23.0",
  "command": {
    "publish": {
      "conventionalCommits": true,
      "message": "chore(release): publish",
      "registry": "https://npm.pkg.github.com",
      "allowBranch": "master"
    }
  }
}

I don't think there's anything of relevance in package.json

@privatenumber
Copy link

privatenumber commented Sep 6, 2021

Maybe. Sometimes, the bug is in the places you least suspect (which is why you don't find it 😅).

In this case, I was curious what the version of your subpackage is. But seems youre not using independent mode.

Can you provide the commit message you used to try to trigger the breaking change?

@richardkazuomiller
Copy link
Contributor

I tried a few things and finally got the major version bump 😂.

Doing an empty commit (git commit --allow-empty ...) like this looks like it should work when not using independent mode, but doesn't:

feat(my-package): aaa

BREAKING CHANGE: bbb

Putting BREAKING CHANGE in a merge commit, somehow is recognized by conventional commits, shown by the fact that it shows up in the changelog, however it also doesn't bump the version.

What finally worked is we reworded a recent commit to a file inside one of the packages to include BREAKING CHANGE in the description of the commit. For people like me who prefer to think in terms of PRs rather than individual commits, this might be an easy place to get stuck. If anyone else has this problem, try rewording a commit (not a merge commit) that changes a file inside one of the packages. package.json should always work, but probably any file included in the package should also work.

@qrosmeli
Copy link

qrosmeli commented Sep 9, 2021

@richardkazuomiller your comment really help me. I was trying to get a major bump with a commit on a shared folder for all packages. As soon I did a silly change with a commit inside a package it recognized as a major change.

Commit: git commit -a -m 'feat!: Dummy breaking change'
Command: lerna version --no-push --conventional-commits --changelog-preset conventionalcommits --no-changelog

(We do not want the Angular preset, to be able to use the conventionalcommits preset you need to install the conventional-changelog-conventionalcommits package)

This has been the ONLY way I have been able to get a Major bump. I have been struggling with this for hours.

@richardkazuomiller
Copy link
Contributor

@qrosmeli That's great! I'm glad I could help 😸

@beamery-tomht
Copy link

If your package is in major version zero (eg. v0.x.y), the semver rules are shifted over, so breaking changes happen in v0.x.0, and features & patches happen in v0.0.y.

@privatenumber OH MY @£$@$ this has been driving me mad! Thanks so much for sharing this information!!

@andresilva-cc
Copy link

andresilva-cc commented Mar 9, 2023

If your package is in major version zero (eg. v0.x.y), the semver rules are shifted over, so breaking changes happen in v0.x.0, and features & patches happen in v0.0.y.

Therefore, a breaking change in a package that is in 0.x.y, will only bump x.

I wish this was better documented, but it's in the npm docs:

^1.2.3 := >=1.2.3 <2.0.0
^0.2.3 := >=0.2.3 <0.3.0
^0.0.3 := >=0.0.3 <0.0.4

Requested for improved documentation around this here.

And how do I get out of 0.x.y version using the --conventional-commits option? Or do I need to bump it manually with lerna version (without using --conventional-commits)?

@amaralc
Copy link

amaralc commented Mar 12, 2023

@richardkazuomiller your comment really help me. I was trying to get a major bump with a commit on a shared folder for all packages. As soon I did a silly change with a commit inside a package it recognized as a major change.

Commit: git commit -a -m 'feat!: Dummy breaking change' Command: lerna version --no-push --conventional-commits --changelog-preset conventionalcommits --no-changelog

(We do not want the Angular preset, to be able to use the conventionalcommits preset you need to install the conventional-changelog-conventionalcommits package)

This has been the ONLY way I have been able to get a Major bump. I have been struggling with this for hours.

Thank you so much @qrosmeli and @richardkazuomiller . Passing --changelog-preset conventionalcommits was the only way it worked for me too.

@Allensy
Copy link

Allensy commented Mar 14, 2023

I managed to make it work!

TL;DR:
Just add BREAKING CHANGE: <description>} footer to the bottom of your commit message.

I managed to resolve that using breaking change footer convention in the commit message:

feat(lang)!: changed property name
BREAKING CHANGE: Changed property name `action` to `callback`

As you can also see here: https://www.conventionalcommits.org/en/v1.0.0/#specification
The ! doesn't signal conventional commits that there is a breaking change, it's only used to draw attention.
The BREAKING CHANGE footer on the other hand actually does that.
So running lerna version --conventional-commits or lerna publish --conventional-commits will actually bump major versions for the affected files.

@aasen
Copy link

aasen commented Mar 14, 2023

I read it differently, as it says or appends a ! after the type/scope so I would expect the ! be enough. But I agree adding BREAKING CHANGE: <description>} works.

Screenshot 2023-03-14 at 14 50 02

@ohare93
Copy link

ohare93 commented Jul 10, 2023

@richardkazuomiller your comment really help me. I was trying to get a major bump with a commit on a shared folder for all packages. As soon I did a silly change with a commit inside a package it recognized as a major change.

Commit: git commit -a -m 'feat!: Dummy breaking change' Command: lerna version --no-push --conventional-commits --changelog-preset conventionalcommits --no-changelog

(We do not want the Angular preset, to be able to use the conventionalcommits preset you need to install the conventional-changelog-conventionalcommits package)

This has been the ONLY way I have been able to get a Major bump. I have been struggling with this for hours.

Didn't work for me 🤔 even with a commit message of

feat!: lerna major bump

BREAKING CHANGE: stuff

Just ended up manually doing a major release to 1.0.0 via lerna version major 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests