labzero / bootleg

Simple deployment and server automation for Elixir.
MIT License
396 stars 24 forks source link

Support doing a "dry run" of a bootleg task. #146

Open holetse opened 7 years ago

holetse commented 7 years ago

Currently there is no way to tell exactly what tasks/hooks will get executed when a particular task is invoked, especially when another package is providing some of those tasks for you. The bootleg mix tasks would support a --dry-run flag, which would cause bootleg to load and parse its config files like normal, and then "run" the tasks with remote turned into a no-op (or maybe patch into SSHKit's dry run functionality). During the run, it would print out each task/hook as they are entered/exited.

The flexibility of the DSL is a bit of a disadvantage here, as things like invoke can be conditionalised on the results of a remote call. Doing AST traversal, it should be possible to detect those cases and maybe the output would reflect both branches? Or warn that the results are unknown (we don't want to follow too many conditional branches if the user has a bunch of conditional invokes).

This feature is probably going to need to rely on AST parsing instead of actual code execution to avoid side-effects like notifying APMs or touching files via system calls.

Example output:

$ mix bootleg.build --dry-run
Dry run...
task :build started
  task :compile started
    remote :build, MIX_ENV=prod mix deps.compile
    remote :build, MIX_ENV=prod mix compile
  task :compile ended
  task :generate_release started
    remote :build, MIX_ENV=prod mix release
  task :generate_release ended
task :build ended
rjanja commented 7 years ago

It sounds like it may be simpler to avoid walking the AST (or doing so in a later task) and initially just going through the list of tasks registered to run. It could be left to the user to examine those tasks for calls to invoke.

E.g.:

task :build started
  before_hook :compile, fun started
  before_hook :compile, fun ended
  task :compile started
  task :compile ended
  after_hook :compile, :special_task called
  after_hook :compile, :special_task ended
task :build ended

This could be simplified if we were only inspecting one-level deep:

task :build started
  before_hook :compile, fun
  task :compile
  after_hook :compile, :special_task
task :build ended

I'm not sure how practical this is, but I love the idea of seeing the dry-run execution.

rjanja commented 5 years ago

It would be great to be able to use this feature to automatically generate accurate workflows documentation.