Sha256: 7d2ad7f6ac596c054dba4202d2654fda3fa65d0b6157d127bb14f79aeea83dd8

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents


# include task like 'rake build'
require 'bundler/gem_tasks'
# another way to build the gem
#require 'rubygems/commands/build_command'

module DevopsHelper
  module GemRakeHelper

    def build_gem
      t = find_build_task        
      raise DevopsHelper::Error, "Cannot find the build task. Please ensure the GEM is configured properly" if is_empty?(t)
      execute_build_task(t)
    end

    def publish_gem(version, opts = { },&block)
      # find the package
      root = opts[:root] || Dir.getwd
      foundGem = Dir.glob("**/*-#{version}.gem")
      if foundGem.length == 0
        raise DevopsHelper::Error, "No built gem found."
      elsif foundGem.length > 1
        if block
          targetGem = block.call(:multiple_built_gems, foundGem)
        else
          raise DevopsHelper::Error, "Multiple versions of gem found : #{foundGem}. Please provide a block for selection"
        end
      else
        targetGem = foundGem.first
      end

      cmd = "cd #{root} && gem push #{targetGem}"
      DevopsHelper::Global.instance.logger.tdebug :gem_rake_helper, "Command to publish gem : #{cmd}"  
      `#{cmd}`
      [$?, targetGem]
    end

    private
    def find_build_task
      task = nil
      Rake::Task.tasks.each do |t|
        if t.name == "build"
          task = t
          break
        end
      end
      task
    end

    def execute_build_task(task)
      task.execute if not_empty?(task) and task.is_a?(Rake::Task)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
devops_helper-0.3.1 lib/devops_helper/gem_rake_helper.rb
devops_helper-0.3.0 lib/devops_helper/gem_rake_helper.rb
devops_helper-0.2.0 lib/devops_helper/gem_rake_helper.rb