mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Allow to invoke iterant tasks (#1911)
* Add invoke! method for repeatedly invoking tasks * Add #invoke! spec
This commit is contained in:
parent
a76b0766b0
commit
7334409962
3 changed files with 64 additions and 8 deletions
11
CHANGELOG.md
11
CHANGELOG.md
|
|
@ -16,11 +16,20 @@ gem "capistrano", :github => "capistrano/capistrano"
|
|||
|
||||
## master
|
||||
|
||||
https://github.com/capistrano/capistrano/compare/v3.8.1...HEAD
|
||||
https://github.com/capistrano/capistrano/compare/v3.8.2...HEAD
|
||||
|
||||
* Your contribution here!
|
||||
|
||||
* Updated `deploy:cleanup` to continue rotating the releases and skip the invalid directory names instead of skipping the whole rotation of releases. The warning message has changed slightly due to the change of behavior.
|
||||
* [#1911](https://github.com/capistrano/capistrano/pull/1911): Add Capistrano::DSL#invoke! for repetetive tasks
|
||||
|
||||
### Breaking changes:
|
||||
|
||||
* None
|
||||
|
||||
### Other changes:
|
||||
|
||||
* None
|
||||
|
||||
## `3.8.2` (2017-06-16)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,13 +19,19 @@ module Capistrano
|
|||
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 "If you really meant to run this task again, use invoke!(\"#{task_name}\")"
|
||||
$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 invoke!(task_name, *args)
|
||||
task = Rake::Task[task_name]
|
||||
task.reenable
|
||||
task.invoke(*args)
|
||||
end
|
||||
|
||||
def t(key, options={})
|
||||
I18n.t(key, options.merge(scope: :capistrano))
|
||||
end
|
||||
|
|
|
|||
|
|
@ -71,13 +71,54 @@ module Capistrano
|
|||
end
|
||||
|
||||
describe "#invoke" do
|
||||
it "will print a message on stderr, when reinvoking task" do
|
||||
Rake::Task.define_task("some_task")
|
||||
context "reinvoking" do
|
||||
it "will not reenable invoking task" do
|
||||
counter = 0
|
||||
|
||||
dsl.invoke("some_task")
|
||||
expect do
|
||||
dsl.invoke("some_task")
|
||||
end.to output(/.*Capistrano tasks may only be invoked once.*/).to_stderr
|
||||
Rake::Task.define_task("A") do
|
||||
counter += 1
|
||||
end
|
||||
|
||||
expect do
|
||||
dsl.invoke("A")
|
||||
dsl.invoke("A")
|
||||
end.to change { counter }.by(1)
|
||||
end
|
||||
|
||||
it "will print a message on stderr" do
|
||||
Rake::Task.define_task("B")
|
||||
|
||||
expect do
|
||||
dsl.invoke("B")
|
||||
dsl.invoke("B")
|
||||
end.to output(/If you really meant to run this task again, use invoke!/).to_stderr
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#invoke!" do
|
||||
context "reinvoking" do
|
||||
it "will reenable invoking task" do
|
||||
counter = 0
|
||||
|
||||
Rake::Task.define_task("C") do
|
||||
counter += 1
|
||||
end
|
||||
|
||||
expect do
|
||||
dsl.invoke!("C")
|
||||
dsl.invoke!("C")
|
||||
end.to change { counter }.by(2)
|
||||
end
|
||||
|
||||
it "will not print a message on stderr" do
|
||||
Rake::Task.define_task("D")
|
||||
|
||||
expect do
|
||||
dsl.invoke!("D")
|
||||
dsl.invoke!("D")
|
||||
end.to_not output(/If you really meant to run this task again, use invoke!/).to_stderr
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue