Release NPM package with git-flow

by Willem — 2 minutes

Having an NPM package in an enterprise environment and wanting to release that package using the git-flow model? Then using the node-generate-release can be very helpful. This blog shows how to execute an integrated git flow release from your NPM package, even if your master and develop branches are protected.

Install plugin

Let’s assume we have all changes in the develop branch and we would like to create a release with all the current changes in develop. With the git-flow release the result will be that all changes will be merged into master and a tag for the release version is created with correct version. Before we can finish the release the correct version in NPM package.json needs to be set. This can all be nicely done with node-generate-release plugin.

## install the node-generate-release plugin globally
## now we can use the CLI as script)
npm install -g node-generate-release

Add as script

Now we can add a release script that will call the generate-release CLI from the plugin.

{
  "scripts": {
    "release": "generate-release"
  }
}

Run

If we run the following command from the command line, the complete git flow release start and git flow release finish commands will be performed.

npm run release

With pull requests

In many cases the master and develop branches are protected. Therefore we need to create pull requests in the git repository before merging the release/* branch back. In that case we want to skip the git flow release finish process and push the release/* branch. To do so we can include the following property in our package.json:

Add the following snippet to package.json:

{
  "config": {
    "generateRelease": {
      "skip_git_flow_finish": true
    }
  }
}

More configuration can be found here

Original blog post

meerdivotion

Cases

Blogs

Event