Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 998 of the free egghead.io lessons, plus get JavaScript content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Automating Releases with semantic-release

5:49 JavaScript lesson by

There are so many repeated steps when releasing a new version of a library. The tool semantic-release automates this process by pushing off the responsibility of your releases to continuous integration. Trust us, this will change your workflow for the better.


egghead.io comment guidelines

Avatar
egghead.io

There are so many repeated steps when releasing a new version of a library. The tool semantic-release automates this process by pushing off the responsibility of your releases to continuous integration. Trust us, this will change your workflow for the better.

Avatar
LOGESH KUMAR

Hi,

After I choose Tarvis CI, I am getting this error in console.

ERR! semantic-release Could not get repository on Travis CI.
ERR! semantic-release { file: 'not found' }

In reply to egghead.io
Avatar
David

I got the same thing. I went to https://travis-ci.org and created an account (authorization via github), and it worked afterwards.

In reply to LOGESH KUMAR
Avatar
Kent C.

Ah! I must have missed that because I've had a travis account for a long time and I didn't think about it. Sorry about that! You might think about filing an issue to improve this experience on https://github.com/semantic-release/semantic-release

In reply to David
Avatar
LOGESH KUMAR

But I have an account in https://travis-ci.org already and I can see my github repositories listed there. I have also enabled the repository I am working on in travis. I am still getting the same error. I am using Ubuntu 14.04 , nmp - v2.11.2 and node v0.12.6.

In reply to David
Avatar
Kent C.

Hmm... That's odd. I would recommend you reach out to the semantic-release project on github and see if they can help you troubleshoot. You might also try emailing support@travis-ci.com

In reply to LOGESH KUMAR
Avatar
Juanmnl Cornejo

I'm having a problem on travis build. It stalls while launching the tests. I'm sure the -w flag is responsible so i removed it. I've pushed the changes to github, but when relaunching the build on travis, the test command still has the -w flag.
How do i update the github project on travis. (tried removing and adding again w/ no success)

Avatar
Kent C.

I actually recommend that your test script not have the -w flag (even though that's what I originally did in the video) and in your .travis.yml, make sure that your script runs npm run test. I do in angular-formly

Good luck!

In reply to Juanmnl Cornejo
Avatar
Juanmnl Cornejo

Hey! Thanks for the quick answer! Everything worked after waiting a bit (the new commit arrived and everything went green).
Guess i'll wait for the commit to propagate next time :)

In reply to Kent C.
Avatar
Leo

Hi Kent, thanks a lot for sharing this amazing library. I just have 2 steps that I'm struggling with.

1) I use gulp-header that reads my package.json to insert the correct version as annotations in my .min.js, however, semantic-release don't let any version into the package.json, do you have an alternative, for it? Thanks?

2) How would publish bower? Do I need to create a tag on my own? Thanks

Avatar
Kent C.

Hi Leo! So... Two things

1) Just run gulp-header after semantic-release pre. You'll see that I changed the semantic-release script in angular-formly here. semantic-release pre will set the version in package.json.
2) Don't publish to bower. It's dead. However, semantic-release does create a tag for you, so it should just work out of the box.

In reply to Leo
Avatar
Leo

Hi Kent,

Many thanks for your reply.

1) Allright, I'll run semantic-release pre, than gulp-header. That's really cool. I just need to make sure all my PR helpers use the correct commit messages convention. (I found out you wrote a lib to force that, I'll try it)

2) I've read about replace bower to npm, however this won't be done to quickly. I'm still have many users from bower in my lib. I realized that created a tag. It should be fine though.

Awesome video btw!

In reply to Kent C.
Avatar
RanchardZ

I have the same problem with LOGESH KUMAR. Login Travis CI with my github account and sync the repos. I add the .travis.yml myself and it works on travisCI. But when I run semantic-release-ci setup..The same error messages show up.

In reply to egghead.io
Avatar
RanchardZ

it's my mistake..But, maybe other friends would come across the same problem following this lecture. If we follow the lecture's instructions strictly and create same warstars-names repo on our github. we are not allowed to publish our repo on npm..so there I change my repo name to myname-warstars-names. This is where the problem lies...We need to change our package.json too. because the settings there remain the same with warstars-names instead of myname-warstarts-names...

In reply to RanchardZ
Avatar
RanchardZ

see my last post.~maybe your problem is similar with mine.

In reply to LOGESH KUMAR

There are a couple of repeated steps when releasing a new version of a library. First you have to develop the new feature or the bug fix, and then you have to commit that and you have to tag that commit, and you have to publish it and you push it up to GitHub.

There are a lot of different steps, and as programmers we don't like to repeat ourselves, so there's a tool that was developed called semantic release that makes releasing new versions of your software super, super easy. We're going to do that now with our library, Star Wars names.

We'll run npm install -g semantic-release-cli. Now, with that installed, let's go ahead and run semantic-release-cli setup. This is going to take us through a prompt. Our GitHub repository is not private, with a capital N there, that's the default, so we'll just hit enter.

Our npm repository or registry is just the normal one, so I'll go with the default there. It read my npm username and my npm email. It got my GitHub username, and now I'm going to choose what continuous integration service I'm using.

The way that semantic release works is that it will actually release your software or your library during continuous integration. We haven't set up any continuous integration, but semantic release will actually set it up for us and will initialize things for us.

We're going to stick with Travis CI. If you don't want to use Travis CI, you want to use Snap or Codeship or something else, then you can just print the tokens and then you can use those and set those in your continuous integration. We'll go ahead and stick with Travis CI.

What semantic release is doing is it's creating a travis job for our library and adding a couple of things to our project. For us, we're just going to stick with a single node version in our travis.yml, and now let's go ahead and look at our project.

There are a couple of new things in here. First you'll see the travis.yml is new. We'll look at that in a moment. Then you'll also have package.json. Let's go ahead and look at some of the changes here.

The first thing you'll notice is we have removed the version from our package.json. This isn't really that big of a deal because when we actually release, then travis will do the releasing and semantic release will actually add the version to our package.json right before it releases.

We don't have to worry about what version our library is in. We're just using some conventions with our commit messages to specify the types of changes that we're making, and then semantic release is able to determine the version based off of the changes that are in our Git history.

I'm going to actually restore the version and just set it to 0.0.0 and say it's semantically released. The reason why I'm doing that is when I run npm install, npm will give me a warning if my package doesn't have a version, so I'm putting that back in there.

With the scripts, it's adding a script semantic release, and it's calling semantic release pre, and then it is doing the npm.publish for us, and then semantic release post. Semantic release does a lot of magic under the covers to make sure that things are ready for when this npm.publish happens, like setting the version properly. It's also updating our url to be https url, and it's adding the semantic release dependency to our dev dependencies.

Now let's go ahead and take a look at the travis.yml. It's specifying we don't need sudo, it's specifying our language, setting up the cash so we don't install our known modules over and over again. We don't need a notification, or we can set that up if we want to.

It's saying before install, go ahead and install the latest version of npm at 2.0. Before we run our script we'll npm prune, and then after we run our script, after our script is successful, then we run the semantic release script that semantic release created for us here.

Now we're going to go ahead and configure travis to make sure that we run the build before we actually release. We don't want to do any sort of releasing before we verify that our tests are working.

Let's go ahead and add a script here with npm.runtest. Now our test will run, and if they fail, then this after success will never run and we won't release a new version. However if they do succeed, then we will release a new version, and semantic release will find out what version it should be based off of our git commits, and we'll talk about that in the next lesson.

Just to review, what you need to do is you run npm.install -g globally, semantic-release-cli, and then setup. That'll take you through this prompt here. Depending on what CI you decide to use, it will create a travis.yml if you choose travis.

Here we have the travis.yml here. We added this script here to make sure that we are running our test so we don't push out a new release if our tests are breaking. Semantic release added this script which it's using in the after success.

That is how you set up your repository to be released with semantic release.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?