Sha256: 340ceef0a0b7adc0f61918a5f829cbe5cf559108544f7cf0988a0c80f1629268

Contents?: true

Size: 1.28 KB

Versions: 11

Compression:

Stored size: 1.28 KB

Contents

#!/usr/bin/env ruby

require 'net/https'
require 'uri'

module RubygemsAPI
  extend self

  def published?(name, version)
    uri = URI.parse("https://rubygems.org/api/v2/rubygems/#{name}/versions/#{version}.json")
    Net::HTTP.get_response(uri).is_a?(Net::HTTPSuccess)
  end
end

module Git
  extend self

  def tag_and_push(version)
    if tag_exists?(version)
      yield
    else
      tag(version) && yield && push_tags
    end
  end

  def tag_exists?(version)
    system('git', 'rev-parse', '--verify', "v#{version}^{commit}", out: File::NULL, err: File::NULL)
  end

  def tag(version)
    puts "Running: git tag -m 'Version #{version}' v#{version}"
    system('git', 'tag', '-m', "Version #{version}", "v#{version}")
  end

  def delete_tag(version)
    puts "Running: git tag -d v#{version}"
    system('git', 'tag', '-d', "v#{version}")
  end

  def push_tags
    puts "Running: git push --tags"
    system('git', 'push', '--tag')
  end
end

spec_path, *release_command = ARGV
release_command = %w(bundle exec rake release) if release_command.empty?

spec = Gem::Specification.load(spec_path)
if RubygemsAPI.published?(spec.name, spec.version)
  puts "#{spec.name} version #{spec.version} is already published."
  exit 0
else
  Git.tag_and_push(spec.version) do
    system(*release_command)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
shipit-engine-0.31.0 lib/snippets/release-gem
shipit-engine-0.30.0 lib/snippets/release-gem
shipit-engine-0.29.0 lib/snippets/release-gem
shipit-engine-0.28.1 lib/snippets/release-gem
shipit-engine-0.28.0 lib/snippets/release-gem
shipit-engine-0.27.1 lib/snippets/release-gem
shipit-engine-0.27.0 lib/snippets/release-gem
shipit-engine-0.26.0 lib/snippets/release-gem
shipit-engine-0.25.1 lib/snippets/release-gem
shipit-engine-0.25.0 lib/snippets/release-gem
shipit-engine-0.24.0 lib/snippets/release-gem