loading...

Gitflow and NPM versions

tirthaguha profile image Tirtha Guha ・2 min read

I am following standard gitflow, and I have different environments for testing the dev builds, and release builds. master goes to production.

I also have my JS app divided into multiple private npm modules which goes into private npm repository.

Q1

Is there any way I can version my npm packages, against the branches they are built on in a standard way?

What I have tried is, I have prerelease pre-ids added to the versions. like
1.0.0-rc.0 //for master
1.0.0-beta.0 //for release
1.0.0-alpha.0 //for dev

But if I create a feature branch from master, it contains the master's version. When I try to raise a PR from it to dev, then it shows conflict, since dev has -alpha.x in its version. To resolve the conflict, I'll have to consume the target branch's versioning. Same issue when it goes for merging on release branch too.

And when it comes to merging to master, the release version (one with -beta.0) completely replaces the master.
So it becomes like this: on master,

It was After Merge After version bump
1.0.0-rc.0 1.0.0-rc.0 1.0.0-beta.0 1.0.0-rc.0

Ideally after the version bump i would have wanted it to be 1.0.0-rc.1

Is it possible to keep package JSONs out of versioning.

Q2

How do I control the versioning in the package JSON of the application where these NPM modules are consumed? It too is on gitflow and feature branching model, and I would want that the App, when it is building on dev branch, it builds with artifacts that are published from their respective dev branches.

Honestly, I might be misusing gitflow too, but as of now, too confused to figure out where I'm going wrong.

Thanks in Advance

Posted on by:

tirthaguha profile

Tirtha Guha

@tirthaguha

javascript, ux, nodejs, react, backbonejs, marionettejs, npm, devops,

Discussion

pic
Editor guide
 

Multi-module Node projects and git-flow just do not play well together. Lerna might be your best bet.

 

Fixed it. with a little shell script.

 

Lerna is intriguing indeed. Will explore. Thanks.

 

The way I fixed it is as follows

//${buildNumber} and ${branch} are available as env variables in the build agent(at least available in jenkins/bamboo)
tagversion="1.0.0-${branch}.${buildNumber}"
echo $tagversion
npm version $tagversion

so my builds are created and published as
1.0.0-master.1 //for master
1.0.0-release.1 //for release
1.0.0-dev.1 //for dev