How I setup Semaphore CI to publish my NPM Package

Chai Phonbopit
Today I Learned ❤️Chai
3 min readSep 5, 2018

A couple week ago, I learned about how to setup Semaphore CI to automatically publish my NPM Package.

SemaphoreCI is the Continuous Integration service of choice for me (I used both my personal and company projects) In this post I just notes what I learned about how to setup for publishing an NPM Package.

I will skip a part about NPM and focus on SemaphoreCI Setting, I assume you already have NPM project and already to set up semaphore project

I want to publish my React and Redux Utils function to NPM Package.

And project on Semaphore here

Setup NPM Token

Before we publish to npmjs we need to login but for SemaphoreCI, we can’t logged in via browser or terminal, all we need is to use token from npmjs

I created token by go to https://www.npmjs.com and select Settings => Create new token

We use this token for publish to NPM

Next we need to setup Semaphore project to know about npm token that .npmrc contains a snippet code like this:

//registry.npmjs.org/:_authToken=MY_TOKEN

Then, I go to Project Setting => Configuration Files and then create a file name and paste a content.

We use Semaphore environment variable $NPM_TOKEN for NPM Token

Next step, We setup environment variable by assign MY_TOKEN to $NPM_TOKEN variable like this:

Set up Deployment

First step, I create deployment server with Generic deployment

Setup Deployment

Then, I chose Automatic because I want to let Semaphore will deploy every build.

And select master branch only for do this job (another branch just run a test don’t deploy)

For a script I just create 2 commands with:

npm build
npm publish --access=public
  • npm build : To create build version of library
  • npm publish Publish to NPM with public access (for scoped NPM)

And now, everything work as I expected. Done 🎉

Happy Coding ❤️

--

--