Skip to content

Commit cd8f7e5

Browse files
committed
Add e2e.set_github_matrix mix task
1 parent 472cb69 commit cd8f7e5

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
defmodule Mix.Tasks.E2e.SetGithubMatrix do
2+
use Mix.Task
3+
4+
alias ElixirScript.Core
5+
alias ElixirScript.E2e
6+
alias ElixirScript.E2e.Entry
7+
8+
@moduledoc """
9+
Mix task to generate matrix information from E2E test data for GitHub Actions workflows.
10+
"""
11+
12+
@shortdoc "Generates matrix information from the E2E data file, to feed into a GitHub Actions matrix."
13+
14+
def run(args) do
15+
output_key = List.first(args) || "matrix"
16+
E2e.read_test_file()
17+
|> log_detected_tests()
18+
|> map_entries_for_json()
19+
|> encode_for_github_actions()
20+
|> Core.set_output(output_key)
21+
Core.log_output()
22+
end
23+
24+
# Logs the detected E2E tests to the console.
25+
defp log_detected_tests(entries) do
26+
IO.puts("E2E tests found:")
27+
Enum.each(entries, &log_test_entry/1)
28+
entries # Return the unchanged list of entries
29+
end
30+
31+
# Logs a single E2E test entry.
32+
defp log_test_entry(entry) do
33+
IO.puts(" * \"#{entry.name}\"")
34+
end
35+
36+
# Converts a list of `Entry` structs into a list of maps suitable for JSON encoding.
37+
defp map_entries_for_json(entries) do
38+
Enum.map(entries, &entry_to_map_for_json/1)
39+
end
40+
41+
# Converts an `Entry` struct to a map for JSON encoding.
42+
defp entry_to_map_for_json(%Entry{} = entry) do
43+
Map.take(entry, [:name, :script, :expected])
44+
end
45+
46+
# Encodes the provided entries into a JSON structure for GitHub Actions matrix.
47+
defp encode_for_github_actions(entries) do
48+
%{"include" => entries}
49+
|> Jason.encode!()
50+
end
51+
end

0 commit comments

Comments
 (0)