diff --git a/Rudyfile b/Rudyfile index 8cac1c35..ab5ea790 100644 --- a/Rudyfile +++ b/Rudyfile @@ -167,7 +167,6 @@ routines do end end - anything do # $ rudy anything before :display_uptime # Specify a dependency script :rudy do # This is Ruby, so any valid syntax @@ -177,22 +176,7 @@ routines do uptime do # $ rudy uptime script :rudy do - uptime - end - end - - tag do - before_local do |option, argv| - msg, suffix = option.message, argv.shift - msg ||= 'Another release by Rudy' - suffix ||= git 'rev-parse', '--short', 'HEAD' - @tagname = Time.now.strftime("%Y-%m-%d-#{user}-#{suffix}") - git 'tag', :a, @tagname, :m, msg - end - after_local do - # The instance variable set in the previous local block is - # available here, but not in remote blocks (and vice versa) - echo "Created tag: #{@tagname}" + uptime end end diff --git a/lib/rudy.rb b/lib/rudy.rb index d5cfdc3e..4196ba5b 100644 --- a/lib/rudy.rb +++ b/lib/rudy.rb @@ -163,6 +163,5 @@ def message; "Private key file #{@obj} not found."; end require 'rudy/metadata' # important require 'rudy/machines' require 'rudy/routines' -require 'rudy/scm' diff --git a/lib/rudy/scm.rb b/lib/rudy/scm.rb deleted file mode 100644 index 91bf2c5e..00000000 --- a/lib/rudy/scm.rb +++ /dev/null @@ -1,75 +0,0 @@ - - -module Rudy - module SCM - - class NotAWorkingCopy < Rudy::Error - def message - "Not the root directory of a #{@obj} working copy" - end - end - class CannotCreateTag < Rudy::Error - def message - "There was an unknown problem creating a release tag (#{@obj})" - end - end - class DirtyWorkingCopy < Rudy::Error - def message - "Please commit local #{@obj} changes" - end - end - class RemoteError < Rudy::Error; end - class NoRemoteURI < Rudy::Error; end - class TooManyTags < Rudy::Error - def message; "Too many tag creation attempts!"; end - end - class NoRemotePath < Rudy::Error - def message - "Add a path for #{@obj} in your routines config" - end - end - - - module ObjectBase - - - def raise_early_exceptions; raise "override raise_early_exceptions"; end - - # copied from routines/helper.rb - def trap_rbox_errors(ret=nil, &command) - begin - ret = command.call - puts ' ' << ret.stdout.join("#{$/} ") if !ret.stdout.empty? - print_response(ret) - rescue Rye::CommandError => ex - print_response(ex) - exit 12 unless keep_going? - rescue Rye::CommandNotFound => ex - STDERR.puts " CommandNotFound: #{ex.message}".color(:red) - STDERR.puts ex.backtrace - exit 12 unless keep_going? - end - - ret - end - - - private - def keep_going? - Annoy.pose_question(" Keep going?\a ", /yes|y|ya|sure|you bet!/i, STDERR) - end - - def print_response(rap) - [:stderr].each do |sumpin| - next if rap.send(sumpin).empty? - STDERR.puts " #{sumpin}: #{rap.send(sumpin).join("#{$/} ")}".color(:red) - end - STDERR.puts " Exit code: #{rap.exit_code}".color(:red) if rap.exit_code != 0 - end - - end - - end -end - -Rudy::Utils.require_glob(RUDY_LIB, 'rudy', 'scm', '*.rb') \ No newline at end of file diff --git a/lib/rudy/scm/git.rb b/lib/rudy/scm/git.rb deleted file mode 100644 index d008e1f9..00000000 --- a/lib/rudy/scm/git.rb +++ /dev/null @@ -1,217 +0,0 @@ - -require 'date' - - -module Rudy - module SCM - class GIT - require 'grit' - include Rudy::SCM::ObjectBase - include Grit - - attr_accessor :base_uri - attr_accessor :remote - attr_accessor :branch - attr_reader :repo - attr_reader :rbox - attr_reader :rtag - attr_reader :user - attr_reader :pkey - attr_reader :changes - - # * +args+ a hash of params from the git block in the routines config - # - def initialize(args={}) - args = { - :privatekey => nil, - :remote => :origin, - :branch => :master, - :user => :root, - :changes => :enforce, - :path => nil - }.merge(args) - @remote, @branch, @path = args[:remote], args[:branch], args[:path] - @user, @pkey, @changes = args[:user], args[:privatekey], args[:changes] - @repo = Repo.new(Dir.pwd) if GIT.working_copy? - end - - def engine; :git; end - - def liner_note - "%-40s (git:%s:%s)" % [@rtag, @remote, @branch] - end - - def create_release(username=nil, msg=nil) - @rtag = find_next_rtag(username) - msg ||= 'Another Release by Rudy!' - msg.tr!("'", "''") - ret = Rye.shell(:git, "tag", @rtag) # Use annotated? -a -m '#{msg}' - raise ret.stderr.join($/) if ret.exit_code > 0 - ret = Rye.shell(:git, "push") if @remote - raise ret.stderr.join($/) if ret.exit_code > 0 - ret = Rye.shell(:git, "push #{@remote} #{rtag}") if @remote - raise ret.stderr.join($/) if ret.exit_code > 0 - @rtag - end - - # rel-2009-03-05-user-rev - def find_next_rtag(username=nil) - now = Time.now - mon = now.mon.to_s.rjust(2, '0') - day = now.day.to_s.rjust(2, '0') - rev = "01" - criteria = ['rel', now.year, mon, day, rev] - criteria.insert(-2, username) if username - rev.succ! while valid_rtag?(criteria.join(Rudy::DELIM)) && rev.to_i < 50 - raise TooManyTags if rev.to_i >= 50 - criteria.join(Rudy::DELIM) - end - - def delete_rtag(rtag=nil) - rtag ||= @rtag - ret = trap_rbox_errors { Rye.shell(:git, 'tag', :d, rtag) } - raise ret.stderr.join($/) if ret.exit_code > 0 # TODO: retest - # Equivalent to: "git push origin :tag-name" which deletes a remote tag - ret = trap_rbox_errors { Rye.shell(:git, "push #{@remote} :#{rtag}") } if @remote - raise ret.stderr.join($/) if ret.exit_code > 0 - true - end - - def create_remote_checkout(rbox) - - # Make sure the directory above the clone path exists - # and that it's owned by the request user. - rbox.mkdir(:p, File.dirname(@path)) - rbox.chown(@user, File.dirname(@path)) - - begin - original_user = rbox.user - rbox.switch_user(@user) - - if @pkey - # Try when debugging: ssh -vi path/2/pkey git@github.com - key = File.basename(@pkey) - homedir = rbox.getenv['HOME'] - rbox.mkdir(:p, :m, '700', '.ssh') rescue nil # :p says keep quiet if it exists - if rbox.file_exists?(".ssh/#{key}") - puts " Remote private key #{key} already exists".colour(:red) - else - rbox.upload(@pkey, ".ssh/#{key}") - end - - ## NOTE: The following are two attempts at telling git which - ## private key to use. Both fail. The only thing I could get - ## to work is modifying the ~/.ssh/config file. - ## - ## This runs fine, but "git clone" doesn't care. - ## git config --global --replace-all http.sslKey /home/delano/.ssh/id_rsa - ## rbox.git('config', '--global', '--replace-all', 'http.sslKey', "#{homedir}/.ssh/#{key}") - ## - ## "git clone" doesn't care about this either. Note that both these - ## config attempts come directly from the git-config man page: - ## http://www.kernel.org/pub/software/scm/git/docs/git-config.html - ## export GIT_SSL_KEY=/home/delano/.ssh/id_rsa - ## rbox.setenv("GIT_SSL_KEY", "#{homedir}/.ssh/#{key}") - - if rbox.file_exists?('.ssh/config') - rbox.cp('.ssh/config', ".ssh/config-previous") - ssh_config = rbox.download('.ssh/config') - end - - ssh_config ||= StringIO.new - ssh_config.puts $/, "IdentityFile #{homedir}/.ssh/#{key}" - puts " Adding IdentityFile #{key} to #{homedir}/.ssh/config" - - rbox.upload(ssh_config, '.ssh/config') - rbox.chmod('0600', '.ssh/config') - - end - - # We need to add the host keys to the user's known_hosts file - # to prevent the git commands from failing when it raises the - # "Host key verification failed." messsage. - if rbox.file_exists?('.ssh/known_hosts') - rbox.cp('.ssh/known_hosts', ".ssh/known_hosts-previous") - known_hosts = rbox.download('.ssh/known_hosts') - end - known_hosts ||= StringIO.new - remote = get_remote_uri - host = URI.parse(remote).host rescue nil - host ||= remote.scan(/\A.+?@(.+?)\:/).flatten.first - known_hosts.puts $/, Rye.remote_host_keys(host) - puts " Adding host key for #{host} to .ssh/known_hosts" - - rbox.upload(known_hosts, '.ssh/known_hosts') - rbox.chmod('0600', '.ssh/known_hosts') - - trap_rbox_errors { - rbox.git('clone', get_remote_uri, @path) - } - rbox.cd(@path) - trap_rbox_errors { - rbox.git('checkout', :b, @rtag) - } - rescue Rye::CommandError => ex - puts ex.message - ensure - # Return to the original user and directory - rbox.switch_user(original_user) - rbox.cd - end - - end - - - def get_remote_uri - ret = Rye.shell(:git, "config", "remote.#{@remote}.url") - ret.stdout.first - end - - # Check if the given remote is valid. - #def has_remote?(remote) - # success = false - # (@repo.remotes || []).each do |r| - # end - # success - #end - - def valid_rtag?(tag) - # git tag -l tagname returns a 0 exit code and stdout is empty - # when a tag does not exit. When it does exist, the exit code - # is 0 and stdout contains the tagname. - ret = Rye.shell(:git, 'tag', :l, tag) - # change :l to :d for quick deleting above and return true - # OR: just change to :d to always recreate the same tag - (ret.exit_code == 0 && ret.stdout.to_s == tag) - end - - # Are all local changes committed? - def self.clean_working_copy?(path=Dir.pwd) - Rye.shell(:git, 'diff').stdout == [] - end - def clean_working_copy?; GIT.clean_working_copy?; end - - def self.working_copy?(path=Dir.pwd) - (File.exists?(File.join(path, '.git'))) - end - def working_copy?; GIT.working_copy?; end - - def raise_early_exceptions - raise NotAWorkingCopy, :git unless working_copy? - raise DirtyWorkingCopy, :git unless @changes.to_s == 'ignore' || clean_working_copy? - raise NoRemoteURI, "remote.#{@remote}.url not set" if get_remote_uri.nil? - raise NoRemotePath, :git if @path.nil? - raise PrivateKeyNotFound, @pkey if @pkey && !File.exists?(@pkey) - find_next_rtag # will raise exception is there's a problem - - # We can't check stuff that requires access to the machine b/c the - # machine may not be running yet. These include: - # * Remote checkout path already exists - # * No git available - # ... - # If create_remote_checkout should fail, it should print a message - # about the release that was created and how to install it manually - end - end - end -end \ No newline at end of file diff --git a/lib/rudy/scm/svn.rb b/lib/rudy/scm/svn.rb deleted file mode 100644 index 37263f54..00000000 --- a/lib/rudy/scm/svn.rb +++ /dev/null @@ -1,110 +0,0 @@ - -require 'date' - -module Rudy - module SCM - class SVN - attr_accessor :base_uri - - attr_reader :changes - - def initialize(args={}) - args = { - :privatekey => nil, - :base_uri => nil, - :user => :root, - :changes => :enforce, - :path => nil - }.merge(args) - @base_uri, @path = args[:base_uri], args[:path] - @user, @pkey, @changes = args[:user], args[:privatekey], args[:changes] - end - - def engine; :svn; end - - def liner_note - "%-40s (svn:%s:%s)" % [@rtag, @base_uri, @branch] - end - - def create_release(username=nil, msg=nil) - local_uri, local_revision = local_info - rtag = find_next_rtag(username) - release_uri = "#{@base_uri}/#{rtag}" - msg ||= 'Another Release by Rudy!' - msg.tr!("'", "\\'") - cmd = "svn copy -m '#{msg}' #{local_uri} #{release_uri}" - - `#{cmd} 2>&1` - - release_uri - end - - def switch_working_copy(tag) - raise "Invalid release tag (#{tag})." unless valid_rtag?(tag) - `svn switch #{tag}` - end - - # rel-2009-03-05-user-rev - def find_next_rtag(username=nil) - now = Time.now - mon = now.mon.to_s.rjust(2, '0') - day = now.day.to_s.rjust(2, '0') - rev = "01" - criteria = ['rel', now.year, mon, day, rev] - criteria.insert(-2, username) if username - tag = criteria.join(Rudy::DELIM) - # Keep incrementing the revision number until we find the next one. - tag.succ! while (valid_rtag?("#{@base_uri}/#{tag}")) - tag - end - - def local_info - ret = Rye.shell(:svn, "info").join - # URL: http://some/uri/path - # Repository Root: http://some/uri - # Repository UUID: c5abe49d-53e4-4ea3-9314-89e1e25aa7e1 - # Revision: 921 - ret.scan(/URL: (http:.+?)\s*\n.+Revision: (\d+)/m).flatten - end - - def working_copy?(path) - (File.exists?(File.join(path, '.svn'))) - end - - def valid_rtag?(uri) - ret = `svn info #{uri} 2>&1` || '' # Valid SVN URIs will return some info - (ret =~ /Repository UUID/) ? true : false - end - - # Are all local changes committed? - def self.clean_working_copy?(path=Dir.pwd) - Rye.shell(:svn, 'diff', '.').stdout == [] - end - def clean_working_copy?; SVN.clean_working_copy?; end - - def self.working_copy?(path=Dir.pwd) - (File.exists?(File.join(path, '.svn'))) - end - def working_copy?; SVN.working_copy?; end - - - def raise_early_exceptions - raise NotAWorkingCopy, :svn unless working_copy? - raise DirtyWorkingCopy, :svn unless @changes.to_s == 'ignore' || clean_working_copy? - #raise NoRemoteURI, "remote.#{@remote}.url not set" if get_remote_uri.nil? - raise NoRemotePath, :svn if @path.nil? - raise PrivateKeyNotFound, @pkey if @pkey && !File.exists?(@pkey) - find_next_rtag # will raise exception is there's a problem - - # We can't check stuff that requires access to the machine b/c the - # machine may not be running yet. These include: - # * Remote checkout path already exists - # * No git available - # ... - # If create_remote_checkout should fail, it should print a message - # about the release that was created and how to install it manually - end - - end - end -end \ No newline at end of file diff --git a/rudy.gemspec b/rudy.gemspec index f6460e1c..450539bf 100644 --- a/rudy.gemspec +++ b/rudy.gemspec @@ -16,7 +16,7 @@ s.add_dependency 'drydock', '>= 0.6.3' s.add_dependency 'caesars', '>= 0.6.6' - s.add_dependency 'rye', '>= 0.6.5' + s.add_dependency 'rye', '>= 0.7.0' s.add_dependency 'sysinfo', '>= 0.5.1' s.add_dependency 'storable', '>= 0.5.2' s.add_dependency 'annoy', '>= 0.5.0'