Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
executable file 45 lines (32 sloc) 1.18 KB
#!/usr/bin/env ruby
# frozen_string_literal: true
# git-gem-release-tag: Create a git tag for a Ruby namespace's version,
# build a new gem for that tag, and push that gem to Rubygems.
def act(cmd)
if ARGV.include? "--dry-run"
puts cmd
system cmd
gemspec_candidates = Dir[File.join(`pwd`.chomp, "*.gemspec")]
abort("No gemspec found.") if gemspec_candidates.empty?
abort("You have more than one gemspec, giving up.") if gemspec_candidates.size > 1
gemspec = gemspec_candidates.first
if Dir.exist?("vendor/bundle")
act "bundle exec gem build #{gemspec}"
act "gem build #{gemspec}"
gemfile_candidates = Dir[File.join(`pwd`.chomp, "*.gem")]
abort("No gemfile found, did `gem build` fail?") if gemfile_candidates.empty?
abort("More than one gemfile found, try running with them removed.") if gemfile_candidates.size > 1
gemfile = File.basename gemfile_candidates.first
/-(?<version>[^-]+)\.gem$/ =~ gemfile
tags = `git tag`.split
abort("Did you forget to bump your version?") if tags.include?(version)
# you'd better hope each of these steps works!
act "git tag #{version}"
act "git push origin #{version}"
act "gem push #{gemfile}"
act "rm -f #{gemfile}"