Override rake release task to use Gemfury
Asked Answered
P

1

6

I'm hosting a private gem on Gemfury and would like to override rake release task to push to my Gemfury private URL instead of Rubygems.

I'de like to keep the Git tag creation though.

Any ideas where I should begin to?

Here is what my Rakefile looks like:

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task default: :spec
task test:    :spec
Perri answered 14/8, 2013 at 10:53 Comment(0)
P
6

Actually found the answer:

Rakefile

require 'bundler/gem_tasks'
require 'rubygems/builder'
require 'gemfury'
require 'gemfury/command'

# Override rubygem_push to push to gemfury instead when doing `rake release`
module Bundler
  class GemHelper
    def rubygem_push(path)
      ::Gemfury::Command::App.start(['push', path])
    end
  end
end

Now when doing:

rake release

It create git tags and push to my Gemfury private gem repository.

You'll want to create a file in ~/.gem/gemfury with your secret key:

---
:gemfury_api_key: 1H...
Perri answered 16/8, 2013 at 17:28 Comment(6)
Is there any way to specify the gemfury_api_key on the command line? I'd like to have Jenkins doing a build and push of my gem, and don't much fancy having the secret in the source code somewhere.Pap
This is how it is implemented. I don't think what you want to achieve is possible.Perri
Thanks - I only realised later that the .gem directory doesn't make it into the packaged gem, which was my main concern.Pap
Ah - on my Jenkins box I'm getting cannot load such file -- rubygems/builder when executing the Rakefile. Any ideas why? I'm thinking maybe my version of RubyGems is too old?Pap
This is a very nice solution you put together and I plan on using it. The only thing that occurred to me is that it's a bit risky to depend on the internals of Bundler since this is a protected method, and if there is a refactoring at a higher level this could disappear out from under you, leading to accidentally pushing a private gem to rubygems.org. What I did is to include this guard raise "Bundler::GemHelper#rubygem_push method not found !!! monkeypatch repair needed" unless Bundler::GemHelper.instance_methods.include?(:rubygem_push)Arrack
Also fwiw I added desc "Modified to push to Gemfury"; task :release so that rake -T shows that it is not a stock bundler task.Arrack

© 2022 - 2024 — McMap. All rights reserved.