Skip to content

Commit 95054bf

Browse files
committed
Run mix format
1 parent 2208702 commit 95054bf

File tree

10 files changed

+76
-40
lines changed

10 files changed

+76
-40
lines changed

lib/command_line.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ defmodule ElixirScript.CommandLine do
55

66
def main(args \\ []) do
77
Logger.debug("Running in debug mode")
8-
Logger.debug("All Environment Variables: #{inspect(System.get_env(), limit: :infinity, printable_limit: :infinity)}")
8+
9+
Logger.debug(
10+
"All Environment Variables: #{inspect(System.get_env(), limit: :infinity, printable_limit: :infinity)}"
11+
)
12+
913
{opts, _, _} = OptionParser.parse(args, strict: [help: :boolean])
1014
Logger.debug("Parsed options: #{inspect(opts, limit: :infinity, printable_limit: :infinity)}")
1115

@@ -14,7 +18,10 @@ defmodule ElixirScript.CommandLine do
1418
else
1519
result = ScriptRunner.run(get_script())
1620
Core.set_output(result, "result")
17-
Logger.debug("Result output: #{inspect(result, limit: :infinity, printable_limit: :infinity)}")
21+
22+
Logger.debug(
23+
"Result output: #{inspect(result, limit: :infinity, printable_limit: :infinity)}"
24+
)
1825
end
1926
end
2027

lib/context.ex

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ defmodule ElixirScript.Context do
2424
end
2525

2626
def from_github_environment() do
27-
payload = if System.get_env("GITHUB_EVENT_PATH") do
28-
path = System.get_env("GITHUB_EVENT_PATH")
29-
if File.exists?(path) do
30-
File.read!(path) |> Jason.decode!()
27+
payload =
28+
if System.get_env("GITHUB_EVENT_PATH") do
29+
path = System.get_env("GITHUB_EVENT_PATH")
30+
31+
if File.exists?(path) do
32+
File.read!(path) |> Jason.decode!()
33+
else
34+
IO.puts("GITHUB_EVENT_PATH #{path} does not exist")
35+
%{}
36+
end
3137
else
32-
IO.puts("GITHUB_EVENT_PATH #{path} does not exist")
3338
%{}
3439
end
35-
else
36-
%{}
37-
end
3840

3941
%Context{
4042
payload: payload,
@@ -56,4 +58,3 @@ defmodule ElixirScript.Context do
5658
defp parse_int(nil), do: nil
5759
defp parse_int(value), do: String.to_integer(value)
5860
end
59-

lib/core.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ defmodule ElixirScript.Core do
3636
if System.get_env("GITHUB_OUTPUT") do
3737
EnvironmentFileCommand.issue_file_command(
3838
"OUTPUT",
39-
EnvironmentFileCommand.prepare_key_value_message(name, CommandUtils.to_command_value(value))
39+
EnvironmentFileCommand.prepare_key_value_message(
40+
name,
41+
CommandUtils.to_command_value(value)
42+
)
4043
)
4144
else
42-
Command.issue_command('set-output', name, CommandUtils.to_command_value(value))
45+
Command.issue_command(~c"set-output", name, CommandUtils.to_command_value(value))
4346
end
4447
end
4548

lib/e2e.ex

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ defmodule ElixirScript.E2e do
1010
alias ElixirScript.E2e.Entry
1111

1212
def read_test_file(file_path \\ "test/e2e_data.exs") do
13-
{data, _} = file_path
14-
|> Code.eval_file()
13+
{data, _} =
14+
file_path
15+
|> Code.eval_file()
1516

1617
data
1718
|> Enum.map(&process_entry/1)
@@ -36,8 +37,10 @@ defmodule ElixirScript.E2e do
3637
}
3738
end
3839

39-
defp slugify(name), do: name
40-
|> String.replace(~r/\s+/, "-")
41-
|> String.replace(",", "")
42-
|> String.downcase()
40+
defp slugify(name),
41+
do:
42+
name
43+
|> String.replace(~r/\s+/, "-")
44+
|> String.replace(",", "")
45+
|> String.downcase()
4346
end

lib/github_actions/environment_file_command.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ defmodule ElixirScript.GitHubActions.EnvironmentFileCommand do
8585
::endgroup::
8686
"""
8787
def log_output do
88-
IO.puts "::group::Set outputs"
88+
IO.puts("::group::Set outputs")
89+
8990
"GITHUB_OUTPUT"
9091
|> System.get_env()
9192
|> File.read!()
@@ -96,6 +97,6 @@ defmodule ElixirScript.GitHubActions.EnvironmentFileCommand do
9697
|> File.read!()
9798
|> log_content("GITHUB_ENV")
9899

99-
IO.puts "::endgroup::"
100+
IO.puts("::endgroup::")
100101
end
101102
end

lib/github_actions/workflow_command_utils.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
defmodule ElixirScript.GitHubActions.CommandUtils do
2-
32
def to_command_value(nil), do: ""
43

54
def to_command_value(input) when is_binary(input), do: input

lib/mix/tasks/docker.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ defmodule Mix.Tasks.Docker do
1111
end
1212

1313
defp build do
14-
System.cmd("docker", ["build", "--progress", "plain", "--tag", "elixir_script:latest", "-f", ".github/Dockerfile", "."])
14+
System.cmd("docker", [
15+
"build",
16+
"--progress",
17+
"plain",
18+
"--tag",
19+
"elixir_script:latest",
20+
"-f",
21+
".github/Dockerfile",
22+
"."
23+
])
1524
end
1625
end

lib/mix/tasks/e2e/set_github_matrix.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@ defmodule Mix.Tasks.E2e.SetGithubMatrix do
1313

1414
def run(args) do
1515
output_key = List.first(args) || "matrix"
16+
1617
E2e.read_test_file()
1718
|> log_detected_tests()
1819
|> map_entries_for_json()
1920
|> encode_for_github_actions()
2021
|> Core.set_output(output_key)
22+
2123
Core.log_output()
2224
end
2325

2426
# Logs the detected E2E tests to the console.
2527
defp log_detected_tests(entries) do
2628
IO.puts("E2E tests found:")
2729
Enum.each(entries, &log_test_entry/1)
28-
entries # Return the unchanged list of entries
30+
# Return the unchanged list of entries
31+
entries
2932
end
3033

3134
# Logs a single E2E test entry.

test/e2e_data.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
%{
1717
name: "Event context is available",
1818
script: "Map.keys(context) |> Enum.sort",
19-
expected: "[__struct__,action,actor,api_url,event_name,graphql_url,job,payload,ref,run_id,run_number,server_url,sha,workflow]"
20-
},
19+
expected:
20+
"[__struct__,action,actor,api_url,event_name,graphql_url,job,payload,ref,run_id,run_number,server_url,sha,workflow]"
21+
}
2122
]

test/e2e_test.exs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,40 @@ defmodule ElixirScript.E2eTest do
1010

1111
describe "read_test_file" do
1212
test "when providing a name it gets slugified" do
13-
file_path = create_temp_file([ %{ name: "Test name", script: "" } ])
13+
file_path = create_temp_file([%{name: "Test name", script: ""}])
1414
result = E2e.read_test_file(file_path) |> List.first() |> Map.take([:name, :id])
15-
assert result == %{ name: "Test name", id: "test-name" }
15+
assert result == %{name: "Test name", id: "test-name"}
1616
end
1717

1818
test "can read a simple example script" do
19-
file_path = create_temp_file([ %{ name: "Test name", script: "IO.puts(\"Hello, world!\")" } ])
19+
file_path = create_temp_file([%{name: "Test name", script: "IO.puts(\"Hello, world!\")"}])
2020
result = E2e.read_test_file(file_path) |> List.first() |> Map.take([:file, :script])
21-
assert result == %{ file: nil, script: "IO.puts(\"Hello, world!\")", }
21+
assert result == %{file: nil, script: "IO.puts(\"Hello, world!\")"}
2222
end
2323

2424
test "can read an expected value" do
25-
file_path = create_temp_file([ %{ name: "Test name", script: "\"foo\"", expected: "foo" } ])
25+
file_path = create_temp_file([%{name: "Test name", script: "\"foo\"", expected: "foo"}])
2626
result = E2e.read_test_file(file_path) |> List.first() |> Map.take([:expected])
27-
assert result == %{ expected: "foo" }
27+
assert result == %{expected: "foo"}
2828
end
2929

3030
test "can read a file example" do
31-
file_path = create_temp_file([ %{ name: "Test name", file: "./foo.ex" } ])
31+
file_path = create_temp_file([%{name: "Test name", file: "./foo.ex"}])
3232
result = E2e.read_test_file(file_path) |> List.first() |> Map.take([:file, :script])
33-
assert result == %{ file: "./foo.ex", script: nil, }
33+
assert result == %{file: "./foo.ex", script: nil}
3434
end
3535

3636
test "fails if neither script nor file is specified" do
37-
file_path = create_temp_file([ %{ name: "Test name" } ])
37+
file_path = create_temp_file([%{name: "Test name"}])
38+
3839
assert_raise KeyError, "key :script or :file not found in: %{name: \"Test name\"}", fn ->
3940
E2e.read_test_file(file_path)
4041
end
4142
end
4243

4344
test "fails if name is not specified" do
44-
file_path = create_temp_file([ %{ script: "" } ])
45+
file_path = create_temp_file([%{script: ""}])
46+
4547
assert_raise KeyError, "key :name not found in: %{script: \"\"}", fn ->
4648
E2e.read_test_file(file_path)
4749
end
@@ -75,7 +77,8 @@ defmodule ElixirScript.E2eTest.Runner do
7577
alias ElixirScript.ScriptRunner
7678

7779
def run_test(%Entry{name: name, file: nil, script: script, expected: expected}) do
78-
actual = run_script_and_capture_output(script)
80+
actual =
81+
run_script_and_capture_output(script)
7982
|> convert_to_github_actions_output()
8083

8184
unless is_nil(expected) do
@@ -114,12 +117,17 @@ defmodule ElixirScript.E2eTest.Runner do
114117
# @return A string that matches the expected output format of GitHub Actions.
115118
defp convert_to_github_actions_output(data) do
116119
case data do
117-
binary when is_binary(binary) -> binary # Already a string, no change needed.
118-
list when is_list(list) -> # Serialize the list as GitHub Actions would output it.
120+
# Already a string, no change needed.
121+
binary when is_binary(binary) ->
122+
binary
123+
124+
# Serialize the list as GitHub Actions would output it.
125+
list when is_list(list) ->
119126
list
120127
|> Enum.map(&convert_element_to_string/1)
121128
|> Enum.join(",")
122129
|> wrap_in_brackets()
130+
123131
_ ->
124132
inspect(data)
125133
|> String.trim_leading("\"")
@@ -128,6 +136,7 @@ defmodule ElixirScript.E2eTest.Runner do
128136
end
129137

130138
defp convert_element_to_string(element) when is_atom(element), do: Atom.to_string(element)
131-
defp convert_element_to_string(element), do: element # For any non-atom elements.
139+
# For any non-atom elements.
140+
defp convert_element_to_string(element), do: element
132141
defp wrap_in_brackets(joined), do: "[#{joined}]"
133142
end

0 commit comments

Comments
 (0)