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

Conventional Commit with Fixed versioning #1383

Closed
codeNoobie opened this issue Apr 18, 2018 · 11 comments
Closed

Conventional Commit with Fixed versioning #1383

codeNoobie opened this issue Apr 18, 2018 · 11 comments

Comments

@codeNoobie
Copy link

Do we support publish with conventional-commits for fixed versioning?

@evocateur
Copy link
Member

Yes, this is what lerna itself does.

@codeNoobie
Copy link
Author

codeNoobie commented Apr 18, 2018

Okay. Then help me identify if below is a bug or an expected behavior.

I have two packages currently managed by lerna. I am using default versioning with conventional commit. I am ensuring that commit messages are in conventional commit format. After every commit, I run the below command.

lerna publish --conventional-commits --changelog-preset angular-bitbucket --skip-npm --yes

Let's say the initial versions are:

package-1 -> 0.0.0
package-2 -> 0.0.0

For any commit, that requires minor and patch version update according to conventional commits guidelines, Lerna correctly updates the versions of all packages even those which did not have any change since the last release. This is good.

But when i create a Breaking Change commit which only modifies one package, say package-1, the above Lerna publish command only updates the major version of package-1. But, package-2's version is not modified. I would expect the major version of package-2 to be modified as well.

package-1 -> 1.0.0
package-2 -> 0.0.0

Now I create another patch commit involving only package-1. This time, all the package versions are now modified. Moreover, the major version of package 2 also gets updated.
It does successfully update the version of

package-1 -> 1.0.1
package-2 -> 1.0.1

Is this an expected behavior? If not, am i missing something with config or this is indeed a bug?

Here is my lerna.json:

{
  "lerna": "2.10.2",
  "packages": [
    "libs/*"
  ],
  "commands": {
    "publish": {
      "conventional-commits" : "true"
    }
  },
  "npmClient": "yarn",
  "useWorkspaces": true,
  "loglevel": "silent"
}
yarn -version
1.5.1

node -v
v9.8.0

lerna -v
2.10.2

OsX High sierra

@evocateur
Copy link
Member

This would have been useful information to include in the original bug report.

@evocateur evocateur reopened this Apr 18, 2018
@evocateur
Copy link
Member

Why the --skip-npm? Probably not the cause, but definitely odd, if you do it after every commit.

@codeNoobie
Copy link
Author

@evocateur Yes, I agree I should have added the details with the original description.

I am in the process of setting up a new Angular 5 mono repo. The two lerna packages are component libraries. We are using https://github.com/dherges/ng-packagr to transpile and build the distribution in Angular Package format. This is an important use case for us.

Lerna publish doesn't support publishing a folder/tarball within a package. I have seen few threads on these in Lerna forum and I understand that the Lerna team is against providing this use case. But it is also important for us to publish the transpiled package. So I am trying to work around these requirements.

Lerna publish --skip-npm would take care of the version upgrade, git tag and changelog creation. I would then run a separate script to build these transpiled packages and publish them separately to our private repository. Currently, I am in the process of building this flow.

Lerna has helped us with a lot of our use case. Thanks for actively maintaining it!

@codeNoobie
Copy link
Author

codeNoobie commented Apr 18, 2018

@evocateur I tried digging into the code myself. Here is what I found.

Below line is updating pkg's version to the global version in Fixed mode. It is iterating over the pkgs in this.updates.

for (const { pkg } of this.updates) {

If we go to line 126, we can see that this.updates contains the list of packages that are updated.

this.updates = collectUpdates(this);

This could be the reason for my issue. It seems like for Fixed mode, we should be iterating over all packages instead of the updated ones.

Thoughts?

@evocateur
Copy link
Member

It seems like for Fixed mode, we should be iterating over all packages instead of the updated ones.

I think you're right, logically, but in practice, it's mostly an aberration around how we handle major version bumps. I would definitely expect a conventional major bump in a fixed repo to bump all packages.

...and as far as I can tell, it kinda means we would have to refactor collect-updates to take into account the recommendVersions() logic ...somehow. Oy.

Right now, a workaround exists (for fixed versioning), although it is regrettably not exactly automatic: When you know there is a breaking change, pass --force-publish to lerna publish --conventional-commits, and it should(?) ensure that all packages are bumped to the new major. I haven' tested it, so caveat emptor.

@codeNoobie
Copy link
Author

Thanks Daniel!

This works. Although, are you planning to fix this as a bug in the current version or the upcoming version? I can attempt at submitting a PR for this change.

@bchenSyd
Copy link
Contributor

bchenSyd commented Apr 21, 2018

--force-publish=* will always cause a patch bump. not sure if it's to be exepected
If your project is developed by a team, and under a CI pipeline, unnecessary bump may cause confusions

I created a PR #1391, please have a look @evocateur

@codeNoobie
Copy link
Author

I would wait for this fix to go in. :)

@lock
Copy link

lock bot commented Dec 27, 2018

This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants