From f0b13782e0e02e8adcc21aea7a9d7ba421839692 Mon Sep 17 00:00:00 2001 From: Simon Jesenko Date: Fri, 22 May 2015 23:45:40 +0200 Subject: [PATCH 1/2] Enable skipping of rvm tasks When executing capistrano task which does not execute any ruby code at target host, checking of rvm and ruby versions is unnecessary. This commit enables skipping of rvm hooks by specifying `:skip_rvm_for_tasks` variable, containing an array of strings/regexes against which currently executing top-level capistrano task is matched. --- lib/capistrano/tasks/rvm.rake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/capistrano/tasks/rvm.rake b/lib/capistrano/tasks/rvm.rake index b2845db..94a0a31 100644 --- a/lib/capistrano/tasks/rvm.rake +++ b/lib/capistrano/tasks/rvm.rake @@ -4,6 +4,7 @@ RVM_USER_PATH = "~/.rvm" namespace :rvm do desc "Prints the RVM and Ruby version on the target host" task :check do + next if should_skip on roles(fetch(:rvm_roles, :all)) do if fetch(:log_level) == :debug puts capture(:rvm, "version") @@ -14,6 +15,7 @@ namespace :rvm do end task :hook do + next if should_skip on roles(fetch(:rvm_roles, :all)) do rvm_path = fetch(:rvm_custom_path) rvm_path ||= case fetch(:rvm_type) @@ -43,6 +45,12 @@ namespace :rvm do end end +def should_skip + skip_rvm_for_tasks = fetch(:skip_rvm_for_tasks, []) + invoked_with_task = Rake.application.top_level_tasks.last + skip_rvm_for_tasks.any? { |t| Regexp.new(t).match(invoked_with_task) } +end + Capistrano::DSL.stages.each do |stage| after stage, 'rvm:hook' after stage, 'rvm:check' From f15be9c62938b520b6da33f9d01b9c3b1ed3a3d6 Mon Sep 17 00:00:00 2001 From: Simon Jesenko Date: Sat, 23 May 2015 07:26:17 +0200 Subject: [PATCH 2/2] Skip rvm only for exact string matches When entry in `skip_rvm_for_tasks` is a string, it must be the same as the _full_ top-level capistrano task name. --- lib/capistrano/tasks/rvm.rake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/capistrano/tasks/rvm.rake b/lib/capistrano/tasks/rvm.rake index 94a0a31..b73d713 100644 --- a/lib/capistrano/tasks/rvm.rake +++ b/lib/capistrano/tasks/rvm.rake @@ -48,7 +48,13 @@ end def should_skip skip_rvm_for_tasks = fetch(:skip_rvm_for_tasks, []) invoked_with_task = Rake.application.top_level_tasks.last - skip_rvm_for_tasks.any? { |t| Regexp.new(t).match(invoked_with_task) } + skip_rvm_for_tasks.any? do |t| + if t.is_a?(Regexp) + t.match(invoked_with_task) + else + t == invoked_with_task + end + end end Capistrano::DSL.stages.each do |stage|