Skip to content

Commit

Permalink
Simplify workspace.run logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pnezis committed Jun 4, 2024
1 parent 52b3ed1 commit 51dfc0a
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions workspace/lib/mix/tasks/workspace.run.ex
Original file line number Diff line number Diff line change
Expand Up @@ -250,28 +250,19 @@ defmodule Mix.Tasks.Workspace.Run do
result = run_task(project, opts)
completed_at = System.os_time(:millisecond)

case result do
{:error, status_code} ->
log([
highlight(inspect(project.app), [:bright, :red]),
" ",
highlight(mix_task_to_string(opts[:task], opts[:argv]), :bright),
" failed with ",
highlight("#{status_code}", [:bright, :light_red])
])

_other ->
:ok
end

execution_result =
%{
project: project,
task: opts[:task],
argv: opts[:argv],
status: execution_status(result, allowed_to_fail?(project.app, opts[:allow_failure])),
status_code: status_code(result),
triggered_at: triggered_at,
completed_at: completed_at
}

log_task_execution_result(execution_result)

if opts[:early_stop] do
maybe_early_stop(execution_result)
end
Expand Down Expand Up @@ -397,6 +388,10 @@ defmodule Mix.Tasks.Workspace.Run do
defp execution_status({:error, _status}, false), do: :error
defp execution_status(status, _allowed_to_fail), do: status

defp status_code({:error, status}), do: status
defp status_code(:skip), do: nil
defp status_code(:ok), do: 0

defp maybe_early_stop(result) do
case result[:status] do
:error ->
Expand All @@ -407,6 +402,18 @@ defmodule Mix.Tasks.Workspace.Run do
end
end

defp log_task_execution_result(%{status: status} = result) when status in [:error, :warn] do
log([
highlight(inspect(result.project.app), [:bright, :red]),
" ",
highlight(mix_task_to_string(result.task, result.argv), :bright),
" failed with ",
highlight("#{result.status_code}", [:bright, :light_red])
])
end

defp log_task_execution_result(_result), do: :ok

defp maybe_log_warnings(projects) do
if length(projects) > 0 do
names = Enum.map(projects, & &1.project.app)
Expand Down

0 comments on commit 51dfc0a

Please sign in to comment.