diff --git a/lib/bones/helpers.rb b/lib/bones/helpers.rb index b3ab922..f99830d 100644 --- a/lib/bones/helpers.rb +++ b/lib/bones/helpers.rb @@ -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? diff --git a/lib/bones/plugins/ann.rb b/lib/bones/plugins/ann.rb index 025ef6d..e2cb291 100644 --- a/lib/bones/plugins/ann.rb +++ b/lib/bones/plugins/ann.rb @@ -1,7 +1,4 @@ -require 'net/smtp' -require 'time' - module Bones::Plugins::Ann include ::Bones::Helpers extend self diff --git a/lib/bones/plugins/git.rb b/lib/bones/plugins/git.rb new file mode 100644 index 0000000..7843a43 --- /dev/null +++ b/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 diff --git a/lib/bones/plugins/test.rb b/lib/bones/plugins/test.rb index 3b8079f..59674e6 100644 --- a/lib/bones/plugins/test.rb +++ b/lib/bones/plugins/test.rb @@ -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 diff --git a/lib/bones/smtp_tls.rb b/lib/bones/smtp_tls.rb index 4bce96c..e610cec 100644 --- a/lib/bones/smtp_tls.rb +++ b/lib/bones/smtp_tls.rb @@ -9,6 +9,7 @@ begin require "openssl" require "net/smtp" + require 'time' Net::SMTP.class_eval do private