From 00a8b79dd67db8eaa851bcfed4db6147b976db98 Mon Sep 17 00:00:00 2001 From: Troels Knak-Nielsen Date: Thu, 14 Jul 2016 13:24:56 +0200 Subject: [PATCH] Print a warning if a task is skipped because of re-invocation. Resolves #1689 --- CHANGELOG.md | 1 + lib/capistrano/dsl.rb | 14 ++++++++++++-- spec/lib/capistrano/dsl_spec.rb | 11 +++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be48e9e4..0da065eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Reverse Chronological Order: https://github.com/capistrano/capistrano/compare/v3.5.0...HEAD + * Added warning about future deprecation of reinvocation behaviour (@troelskn) * Added a `doctor:servers` subtask that outputs a summary of servers, roles & properties (@irvingwashington) * Raise a better error when an ‘after’ hook isn’t found (@jdelStrother) * Restrict the uploaded git wrapper script permissions to 700 (@irvingwashington) diff --git a/lib/capistrano/dsl.rb b/lib/capistrano/dsl.rb index 22c77f23..f9f8bc9c 100644 --- a/lib/capistrano/dsl.rb +++ b/lib/capistrano/dsl.rb @@ -11,8 +11,18 @@ module Capistrano include Paths include Stages - def invoke(task, *args) - Rake::Task[task].invoke(*args) + def invoke(task_name, *args) + task = Rake::Task[task_name] + if task && task.already_invoked + file, line, = caller.first.split(":") + colors = SSHKit::Color.new($stderr) + $stderr.puts colors.colorize("Skipping task `#{task_name}'.", :yellow) + $stderr.puts "Capistrano tasks may only be invoked once. Since task `#{task}' was previously invoked, invoke(\"#{task_name}\") at #{file}:#{line} will be skipped." + $stderr.puts "If you really meant to run this task again, first call Rake::Task[\"#{task_name}\"].reenable" + $stderr.puts colors.colorize("THIS BEHAVIOR MAY CHANGE IN A FUTURE VERSION OF CAPISTRANO. Please join the conversation here if this affects you.", :red) + $stderr.puts colors.colorize("https://github.com/capistrano/capistrano/issues/1686", :red) + end + task.invoke(*args) end def t(key, options={}) diff --git a/spec/lib/capistrano/dsl_spec.rb b/spec/lib/capistrano/dsl_spec.rb index 82d208d3..f7b44229 100644 --- a/spec/lib/capistrano/dsl_spec.rb +++ b/spec/lib/capistrano/dsl_spec.rb @@ -69,5 +69,16 @@ module Capistrano end end end + + describe "#invoke" do + it "will print a message on stderr, when reinvoking task" do + Rake::Task.define_task("some_task") + + dsl.invoke("some_task") + expect do + dsl.invoke("some_task") + end.to output(/.*Capistrano tasks may only be invoked once.*/).to_stderr + end + end end end