Repository: phoenixframework/phoenix
Pull request #4999 (2022-10-03 18:11:51)

mix phx.digest to return non zero error code on failure
Currently `mix phx.digest` exits with 0 on error which makes it harder to detect that something went wrong in CI/CD. This PR adds exit with 1 in such case.


Patch:
diff --git a/installer/templates/phx_web/components.ex b/installer/templates/phx_web/components.ex
index abe0a881f..0a0f12c17 100644
--- a/installer/templates/phx_web/components.ex
+++ b/installer/templates/phx_web/components.ex
@@ -27,7 +27,7 @@ defmodule <%= @web_namespace %>.Components do
       </.modal>
 
   JS commands may be passed to the `:on_cancel` and `on_confirm` attributes
-  for the caller to reactor to each button press, for example:
+  for the caller to react to each button press, for example:
 
       <.modal id="confirm" on_confirm={JS.push("delete")} on_cancel={JS.navigate(~p"/posts")}>
         Are you sure you?
@@ -126,10 +126,10 @@ defmodule <%= @web_namespace %>.Components do
   attr :id, :string, default: "flash", doc: "the optional id of flash container"
   attr :flash, :map, default: %{}, doc: "the map of flash messages to display"
   attr :title, :string, default: nil
-  attr :kind, :atom, values: [:info, :error], doc: "Used for styling and flash lookup"
+  attr :kind, :atom, values: [:info, :error], doc: "used for styling and flash lookup"
   attr :autoshow, :boolean, default: true, doc: "whether to auto show the flash on mount"
   attr :close, :boolean, default: true, doc: "whether the flash can be closed"
-  attr :rest, :global, doc: "the aribtrary HTML attributes to add to the flash container"
+  attr :rest, :global, doc: "the arbitrary HTML attributes to add to the flash container"
 
   slot :inner_block, doc: "the optional inner block that renders the flash message"
 
diff --git a/lib/mix/tasks/phx.digest.ex b/lib/mix/tasks/phx.digest.ex
index 7e5546791..689ffcf31 100644
--- a/lib/mix/tasks/phx.digest.ex
+++ b/lib/mix/tasks/phx.digest.ex
@@ -65,6 +65,7 @@ defmodule Mix.Tasks.Phx.Digest do
         Mix.shell().info [:green, "Check your digested files at #{inspect output_path}"]
       {:error, :invalid_path} ->
         Mix.shell().error "The input path #{inspect input_path} does not exist"
+        exit({:shutdown, 1})
     end
   end
 end
diff --git a/priv/templates/phx.gen.live/components.ex b/priv/templates/phx.gen.live/components.ex
index abe0a881f..0a0f12c17 100644
--- a/priv/templates/phx.gen.live/components.ex
+++ b/priv/templates/phx.gen.live/components.ex
@@ -27,7 +27,7 @@ defmodule <%= @web_namespace %>.Components do
       </.modal>
 
   JS commands may be passed to the `:on_cancel` and `on_confirm` attributes
-  for the caller to reactor to each button press, for example:
+  for the caller to react to each button press, for example:
 
       <.modal id="confirm" on_confirm={JS.push("delete")} on_cancel={JS.navigate(~p"/posts")}>
         Are you sure you?
@@ -126,10 +126,10 @@ defmodule <%= @web_namespace %>.Components do
   attr :id, :string, default: "flash", doc: "the optional id of flash container"
   attr :flash, :map, default: %{}, doc: "the map of flash messages to display"
   attr :title, :string, default: nil
-  attr :kind, :atom, values: [:info, :error], doc: "Used for styling and flash lookup"
+  attr :kind, :atom, values: [:info, :error], doc: "used for styling and flash lookup"
   attr :autoshow, :boolean, default: true, doc: "whether to auto show the flash on mount"
   attr :close, :boolean, default: true, doc: "whether the flash can be closed"
-  attr :rest, :global, doc: "the aribtrary HTML attributes to add to the flash container"
+  attr :rest, :global, doc: "the arbitrary HTML attributes to add to the flash container"
 
   slot :inner_block, doc: "the optional inner block that renders the flash message"
 


Test patch:
diff --git a/test/mix/tasks/phx.digest_test.exs b/test/mix/tasks/phx.digest_test.exs
index ddeba6ac0..ea0bb6b5c 100644
--- a/test/mix/tasks/phx.digest_test.exs
+++ b/test/mix/tasks/phx.digest_test.exs
@@ -5,8 +5,9 @@ defmodule Mix.Tasks.Phx.DigestTest do
   import MixHelper
 
   test "fails when the given paths are invalid" do
-    Mix.Tasks.Phx.Digest.run(["invalid_path", "--no-deps-check"])
+    exit_code = catch_exit(Mix.Tasks.Phx.Digest.run(["invalid_path", "--no-deps-check"]))
     assert_received {:mix_shell, :error, ["The input path \"invalid_path\" does not exist"]}
+    assert exit_code == {:shutdown, 1}
   end
 
   @output_path "mix_phoenix_digest"