Sha256: f1225dc30f4281c2c490bb409bae62eefaba1212df334761b7db7c9149417158

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

class GemDeployment
  CREDENTIAL_DIR_PATH = '~/.gem/credentials'
  CREDENTIAL_FILE_PATH = '~/.gem/credentials'
  VERSION_FILE_PATH = './lib/slack_resources/version.rb'

  def initialize(api_key = '', version = 'tiny')
    @api_key = api_key
    @version = version
  end

  def execute!
    major, minor, tiny = fetch_version

    major += 1 if major?
    minor += 1 if minor?
    tiny += 1 if tiny?

    next_version = [major, minor, tiny].join('.')

    `echo "---\n:rubygems_api_key: #{@api_key}\n" > ~/.gem/credentials && chmod 600 ~/.gem/credentials`
    puts `cat ~/.gem/credentials`

    File.write(VERSION_FILE_PATH, <<~VER)
      module SlackResources
        VERSION = '#{next_version}'.freeze
      end
    VER

    result = `gem build slack_resources.gemspec`
    puts result
    gem_file = result.match(/File: *(.+)\n/m)[1]
    puts `gem push #{gem_file}`
  end

  private

  def fetch_version
    `gem search slack_resources`.match(/\(([\d.]+)\)/)[1].split('.').map(&:to_i)
  end

  def major?
    @version == 'major'
  end

  def minor?
    @version == 'minor'
  end

  def tiny?
    @version == 'tiny'
  end
end

GemDeployment.new(*ARGV).execute! if __FILE__ == $0

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slack_resources-0.1.2 .circleci/gem_deployment.rb