Permalink
Cannot retrieve contributors at this time
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?
snippets/git-gem-release-tag/git-gem-release-tag
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
45 lines (32 sloc)
1.18 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
else | |
system cmd | |
end | |
end | |
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}" | |
else | |
act "gem build #{gemspec}" | |
end | |
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}" |