I have a project released with distillery that uses a plugin.
The plugin may fail, and return :error in this case.
defmodule XxxPlugin do
use Mix.Releases.Plugin
def before_assembly(release = %Release{}, name: name) do
result = Mix.shell.cmd("...")
info "Return code from plugin #{result}"
if result != 0 do
error("Plugin failed with result #{result}")
:error
else
release
end
end
end
The mix release... build is properly stopped in this case, but the status code of mix is still 0.
Is there a proper way to stop the build and return an error code ?
The Distillery documentation states that Mix.Releases.Plugin callbacks like before_assembly should return an altered %Release{} struct, or nil.
The documentation is not clear on what happens when you return nil however, but I’d expect packing the release to fail (and hopefully, if Distillery provides it, using a non-zero exit status code.)
As returning nil also results in a 0 return code, I think that the behaviour you want is not currently supported by Distillery. I’d suggest opening an issue on Distillery’s GitHub project.