Automatically build, tag, and push gems
Ruby Shell
Latest commit 4e933c8 Feb 26, 2015 @fatbusinessman fatbusinessman Merge pull request #30 from alphagov/bump_minitest
Bump minitest version
Failed to load latest commit information.
lib
test Minor style and test fixes for `--as` argument. Oct 29, 2014
.gitignore Ignore .bundle directory. May 11, 2012
.ruby-version
.travis.yml
CHANGELOG.md Release version 1.5.0. Oct 30, 2014
COPYING.txt
Gemfile
LICENCE.txt
README.md
Rakefile Make quotes consistent Jun 7, 2012
gem_publisher.gemspec Bump minitest version Feb 26, 2015
jenkins.sh Ahem. -e is exit on error. May 11, 2012

README.md

Gem Publisher

This library will assist you in automatically publishing gems to a variety of repositories.

At present, variety means RubyGems.org or GemFury.

Requires Ruby 1.8.7 or later.

How it works

It first checks whether a version tag (of the form vX.Y.Z) for the current version exists in the remote repository. If the tag does not exist, it does the following:

  • Builds a gem for the updated version
  • Remotely tags the new version
  • Pushes the gem to the gem server

Limitations

  • Only git repositories are supported
  • The remote repository must be called origin

Example

Via rake

In your Rakefile:

require "gem_publisher"

desc "Publish gem to RubyGems.org"
task :publish_gem do |t|
  gem = GemPublisher.publish_if_updated("yourgem.gemspec", :rubygems)
  puts "Published #{gem}" if gem
end

Use :gemfury instead of :rubygems if you want to publish to GemFury instead.

To push to an account you're a collaborator on, you can pass the :as option:

GemPublisher.publish_if_updated("yourgem.gemspec", :gemfury, :as => 'otheraccount')

You'll probably need to add gem_publisher as a development dependency in order to satisfy Bundler. In {name of gem}.gemspec, add the dependency:

s.add_development_dependency "gem_publisher", "~> 1.1.1"

If you're using GemFury, add that too:

s.add_development_dependency "gemfury"

You can now add rake publish_gem to your continuous integration server as a task to run after the tests pass.

This assumes that the requisite credentials have been set up so that the gem push and fury push commands work.

Via command line

This method obviates the need to add extra development dependencies to your project.

gem publish yourgem.gemspec

(rubygems is the default repository) or

gem publish -r gemfury yourgem.gemspec

To use a shared account to publish the gem with Gemfury, use

gem publish -r gemfury -a yoursharedaccount yourgem.gemspec

As before, gem push or fury push must be available and configured.