mina-deploy / mina

Blazing fast deployer and server automation tool
https://rubygems.org/gems/mina
Other
4.34k stars 491 forks source link

run(:local) { command "..." } should abort on failure (or be removed) #609

Open jackc opened 6 years ago

jackc commented 6 years ago

The local run environment does not check the results of its tasks.

  run(:local) do
    command "false"
    command "something-else"
  end

I would expect the task to be aborted and something-else not to run. Instead the error return code is ignored that something-else is run.

However, it is easy to work around. Given we are in rake we can use sh.

sh "false"
sh "something-else"

Given that sh is built-in, perhaps the best solution is to remove/deprecate run(:local) in favor of sh. Otherwise, perhaps it could be implemented in terms of sh instead of system.

coreyworrell commented 5 years ago

The deploy commands are all chained together with && as you can see when using mina deploy --simulate. But local commands are just placed inline.

My temporary fix is to do

run :local do
  command "something || exit 1"
  command "something else && another || exit 1"
end

But that's not very nice to look at, or have to remember. And if you try to use in_path then it will still bypass any failures because in_path wraps commands into a subprocess:

in_path("some/path") do
  command "echo first"
  command "false"
  command "echo last"
end

produces something like

...
(cd project/some/path && echo first && false && echo last && cd -)
another command
# "echo last" will not be called, but "another command" will
SwagDevOps commented 3 years ago

My temporary fix is to do

run :local do
  command "something || exit 1"
  command "something else && another || exit 1"
end

What about the following?

run :local do
  command 'set -e'
  command 'something'
  command 'something else'
  command 'another'
end

See : The Set Builtin (Bash Reference Manual)

Even it is preferable to a behavior similar to rake's sh method (throwing exceptions to interrupt workflows a a default).