Skip to content

Commit

Permalink
Adding tasks for creating and deleting git tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
TwP committed Nov 2, 2009
1 parent fea80ad commit acae55d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 7 deletions.
4 changes: 1 addition & 3 deletions lib/bones/helpers.rb
Expand Up @@ -9,10 +9,8 @@ module Bones::Helpers
GEM = "#{RUBY} -S gem"
HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and
system("svn --version 2>&1 > #{DEV_NULL}"))
HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and
system("git --version 2>&1 > #{DEV_NULL}"))

HAVE = Hash.new
HAVE = Hash.new(false)

def have?( key, &block )
return HAVE[key] if block.nil?
Expand Down
3 changes: 0 additions & 3 deletions lib/bones/plugins/ann.rb
@@ -1,7 +1,4 @@

require 'net/smtp'
require 'time'

module Bones::Plugins::Ann
include ::Bones::Helpers
extend self
Expand Down
78 changes: 78 additions & 0 deletions lib/bones/plugins/git.rb
@@ -0,0 +1,78 @@

module Bones::Plugins::Git
include ::Bones::Helpers
extend self

def post_load
have?(:git) {
Dir.entries(Dir.pwd).include?('.git') and
system("git --version 2>&1 > #{DEV_NULL}")
}
end

def define_tasks
return unless have? :git

config = ::Bones.config
namespace :git do

# A prerequisites task that all other tasks depend upon
task :prereqs

desc 'Show tags from the git repository'
task :tags => 'git:prereqs' do |t|
puts Git.open('.').tags.map {|t| t.name}.reverse
end

desc 'Create a new tag in the git repository'
task :create_tag => 'git:prereqs' do |t|
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
abort "Versions don't match #{v} vs #{config.version}" if v != config.version

git = Git.open '.'
tag = "%s-%s" % [config.name, config.version]
puts "Creating git tag '#{tag}'."

begin
git.add_tag tag
rescue Git::GitExecuteError
abort "Tag creation failed: tag '#{tag}' already exists."
end

if git.remotes.map {|r| r.name}.include? 'origin'
unless system "git push origin #{tag}"
abort "Could not push tag to remote git repository."
end
end
end # task

desc 'Delete a tag from the git repository'
task :delete_tag => 'git:prereqs' do |t|
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'

git = Git.open '.'
tag = "%s-%s" % [config.name, v]

unless git.tags.map {|t| t.name}.include? tag
puts "Tag '#{tag}' does not exist."
break
end

puts "Deleting git tag '#{tag}'."
abort 'Tag deletion failed.' unless system "git tag -d '#{tag}'"

if git.remotes.map {|r| r.name}.include? 'origin'
unless system "git push origin ':refs/tags/#{tag}'"
abort "Could not delete tag from remote git repository."
end
end
end # task

end # namespace :git

task 'gem:release' => 'git:create_tag'
end

end # module Bones::Plugins::Git

# EOF
8 changes: 7 additions & 1 deletion lib/bones/plugins/test.rb
Expand Up @@ -27,9 +27,15 @@ def initialize_test
}
end

def post_load
have?(:test) {
Kernel.test(?e, config.test.file) or not config.test.files.to_a.empty?
}
end

def define_tasks
config = ::Bones.config
return unless Kernel.test(?e, config.test.file) or not config.test.files.to_a.empty?
return unless have? :test

namespace :test do

Expand Down
1 change: 1 addition & 0 deletions lib/bones/smtp_tls.rb
Expand Up @@ -9,6 +9,7 @@
begin
require "openssl"
require "net/smtp"
require 'time'

Net::SMTP.class_eval do
private
Expand Down

0 comments on commit acae55d

Please sign in to comment.