[Question] Bump version and publish packages from one branch but keep tags in another branch
See original GitHub issueHi there! I’m new to Lerna and posted my issue as question on StackOverflow first but it didn’t get enough attention therefore I post it here now.
I’m migrating my project consisting of many dependent on each other packages to monorepo with Lerna. We follow something like Gitflow workflow during development. The main concept is to make all source code changes in develop
branch and all other branches (feature, bugfix, etc.) created from and merged back to develop
. As long as new version of a package is ready we publish it by npm publish
or yarn publish
and then merge it to master
branch and tag it there manually the following way:
$ git checkout develop
Make some changes in source code including version bumping…
$ git add -A
$ git commit -m "Make some changes and version bump."
$ git checkout master
$ git merge --no-ff develop -m "Version 0.14.1."
$ git tag -a 0.14.1 -m "Version 0.14.1."
Now I want to achieve the same thing managing all the packages with Lerna. Looking at the docs I stated that publish command relies on version command that, in turn, uses changed command behind the scenes to detect changes made in packages since latest release:
List local packages that have changed since the last tagged release
Consider that some change is made in develop
branch in one package (say, @geoapps/layout
)
$ lerna changed
says that all packages are changed (that is not that I expect):
info cli using local version of lerna
lerna notice cli v3.13.1
lerna info Assuming all packages changed
@geoapps/angle
@geoapps/camera-scene-mode-switcher
...
@geoapps/tracer
@geoapps/vector
lerna success found 39 packages ready to publish
I guess that it happens due to Lerna looks for tagged commits in develop
branch to compare with but nothing is found there. If I commit source code changes to master
branch
then Lerna detects them in single @geoapps/layout
package properly:
$ git checkout master
$ lerna changed
info cli using local version of lerna
lerna notice cli v3.13.1
lerna info Looking for changed packages since 0.14.1
@geoapps/layout
lerna success found 1 package ready to publish
But making changes in master
branch is also not what I want to do. include-merged-tags was another option I tried to use but seems it works only when tagged commit is also a part of the history of develop
branch:
$ git checkout develop
$ git merge --no-ff master -m "Sync with master."
$ lerna changed --include-merged-tags
info cli using local version of lerna
lerna notice cli v3.13.1
lerna info Looking for changed packages since 0.14.1
@geoapps/layout
lerna success found 1 package ready to publish
Since all source code changes tagged in master
branch are present in develop
branch I wonder whether it is possible to force Lerna to compare changes made in develop
branch not with tagged commits from master
but with their parent commits (0.14.1^2
) also belonging to develop
. Is it possible?
lerna.json
{
"packages": [
"packages/*"
],
"version": "0.14.1",
"npmClient": "yarn",
"command": {
"version": {
"allowBranch": "develop"
}
}
}
Executable | Version |
---|---|
lerna --version |
3.13.1 |
npm --version |
6.9.0 |
yarn --version |
1.15.2 |
node --version |
10.15.0 |
OS | Version |
---|---|
Kubuntu | 18.04 |
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
I post current workaround for my particular use case for further reference.
We don’t want to change our git workflow for many reasons so patching Lerna is an acceptable way to go right now. Just created git patch and placed it in the root directory of my project using Lerna.
lerna-version-since.patch
If something changes in
commands/version/command.js
then we will probably update the patch. In order to apply the patch one should run this command:Having patched Lerna it’s now possible to bump and publish in
develop
branch and tag a release inmaster
. In order to make things simplier I wrote a script calledlerna-gitflow.js
that makes everything automatically. Here is a script section ofpackage.json
:All these
publish:*
andchanges
commands should be run from development branch (develop
by default).changes
command just shows changed packages in development branch (develop
) since latest release tag in release branch (master
by default).publish
command does two things:package.json
files of changed packages, in rootpackage.json
andlerna.json
and commits them todevelop
branch locally (it can be done separately by running, for example,./lerna-gitflow.js version patch
);develop
branch, then merges changes tomaster
branch without fast-forward and tag a new release there (it also can be done separately by running./lerna-gitflow.js publish --skip-version
).postinstall
script tries to patch Lerna on anynpm install
oryarn install
call otherwise required changes to make everything working will be lost.lerna-gitflow.js
I would recommend forking
@lerna/version
into your own package and installing annpm:
alias that resolves it to your fork whenlerna
is installed.