Posts Tagged release

Releasing Gems self-opinionated

Wednesday, September 15th, 2010

Packaging and releasing gems is easy. Many people simply use jeweler to handle all the tiresome tasks. Others try to avoid 3rd-party tools and don’t take any “opinionated” shortcuts at all.

Not that I would care about opinions, anyway. However, I catched myself using a mixture of all ruby release tools, so here’s my current workflow.

1. Get your tests running

At some point you usually notice that your code is stable (or looks as if, at least) and you decide to release a gem. Yiha, party time!

2. Bump the version

I like doing this manually. Why? It’s so simple. Open the version.rb file, edit and save.

So, after incrementing the version by whatever minor, major, patchlevel or development flag, the version file ends up with something like

module Cells
  VERSION = "3.4.0.beta2" # i was "3.4.0.beta1"!
end

3. Update the gemspec

Now this is something where jeweler comes in handy! Having a decent Rakefile configuration I punch in

$ rake gemspec

and let jeweler create my gemspec file. Why should I write my own rake task if this gem does it for me?

4. Check the gemspec

That’s something I do. Always. Open cells.gemspec and check if all files are listed.

To get rid of nasty tmp files that aren’t packaged in your gem but appear in the gemspec, tweak the Rakefile:

spec.files        = FileList["[A-Z]*", "lib/**/*"] - ["Gemfile.lock"]
spec.test_files   = FileList["test/**/*"] - FileList["test/dummy/log/*"]

5. Commit and tag

I like doing this manually as well. I remember times where jeweler used to drive me nuts and wouldn’t let me do me what I want.

$ git commit -m "releasing 3.4.0.beta2 which looks kinda stable, dude."
$ git tag v3.4.0.beta2

Tagging this commit is important, so people browsing your code on github can jump to specific versions. You even may want to push things to your origin now.

6. Build the gem and release

Couple of months ago I happened to learn that this can be done with gem itself. The command packages and releases the gem.

$ gem build cells.gemspec

This bundles all the files into a new file cells-3.4.0.beta2.gem, which is awesome.

Let’s push it to rubygems.org.

$ gem push cells-3.4.0.beta2.gem

At this point, lean back and grab a beer. You’re done.

I really like the diversity of tools in open-source communities. And I love the fact that I’m free to use ‘em in combination. So that’s how I release things and keep control over several building steps.

You like it?