Skip to content

Commit

Permalink
CI: run tests with multiple parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
rinpatch committed Dec 29, 2019
1 parent 2cd6c1e commit 17eab75
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,39 @@ on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
env:
PARSER: ${{ matrix.parser }}

container:
image: elixir:${{ matrix.elixir }}-slim

name: Elixir ${{ matrix.elixir }}
name: Elixir ${{ matrix.elixir }} with ${{ matrix.parser }}

strategy:
fail-fast: false
matrix:
elixir: [1.9, 1.8, 1.7, 1.6, 1.5]
parser: [fast_html, html5ever, mochiweb]

steps:
- uses: actions/checkout@v1.0.0

- name: Install dependencies
run: |-
apt-get update
if [ "$PARSER" = "fast_html" ]; then apt-get -y install build-essential; fi
if [ "$PARSER" = "html5ever" ]; then apt-get -y install cargo; fi
mix local.rebar --force
mix local.hex --force
mix deps.get
- name: Check format
if: matrix.elixir >= 1.6
if: matrix.elixir >= 1.8
run: mix format --check-formatted

- name: Run tests
run: |-
mix test
mix test.$PARSER
- name: Run inch.report
if: matrix.elixir >= 1.7
Expand Down
24 changes: 12 additions & 12 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,26 @@ defmodule Floki.Mixfile do
end

defp deps do
# Needed to avoid installing unnecessary deps on the CI
parsers =
case System.get_env("PARSER") do
nil -> [:fast_html, :html5ever]
parser -> [String.to_atom(parser)]
end
|> Enum.map(fn name -> {name, ">= 0.0.0", optional: true, only: [:dev, :test]} end)

[
{:html_entities, "~> 0.5.0"},
{:earmark, "~> 1.2", only: :dev},
{:ex_doc, "~> 0.18", only: :dev},
{:credo, ">= 0.0.0", only: [:dev, :test]},
{:inch_ex, ">= 0.0.0", only: :docs},
{:html5ever, ">= 0.0.0", optional: true, only: [:dev, :test]},
{:fast_html, ">= 0.0.0", optional: true, only: [:dev, :test]},
{:mochiweb, ">= 0.0.0", optional: true, only: [:dev, :test]}
]
{:inch_ex, ">= 0.0.0", only: :docs}
] ++ parsers
end

defp aliases do
parsers = get_parsers()
# Hardcoded because we can't load the floki application and get the module list at this point.
parsers = [Floki.HTMLParser.Mochiweb, Floki.HTMLParser.FastHtml, Floki.HTMLParser.Html5ever]

{aliases, cli_names} =
Enum.map_reduce(parsers, [], fn parser, acc ->
Expand All @@ -54,12 +60,6 @@ defmodule Floki.Mixfile do
|> Keyword.put(:test, &test_with_parser(cli_names, &1))
end

# Hardcoded because we can't load the floki application and get the module list at this point.
defp get_parsers() do
[Floki.HTMLParser.Mochiweb, Floki.HTMLParser.FastHtml, Floki.HTMLParser.Html5ever]
end

# Hack: If Mix.Task.Test.run is called the second time, it won't run any tests
defp test_with_parser(parser_cli_names, args) when is_list(parser_cli_names) do
Enum.each(parser_cli_names, fn cli_name ->
Mix.shell().cmd("mix test.#{cli_name} --color #{Enum.join(args, " ")}",
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"credo": {:hex, :credo, "1.1.5", "caec7a3cadd2e58609d7ee25b3931b129e739e070539ad1a0cd7efeeb47014f4", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.21.2", "caca5bc28ed7b3bdc0b662f8afe2bee1eedb5c3cf7b322feeeb7c6ebbde089d6", [:mix], [{:earmark, "~> 1.3.3 or ~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"fast_html": {:hex, :fast_html, "1.0.0", "eb73ab6dc4d1498b3760489629487fc6b82e0df71c316171a425a71deff2fdcf", [:make, :mix], [], "hexpm"},
"fast_html": {:hex, :fast_html, "1.0.1", "5bc7df4dc4607ec2c314c16414e4111d79a209956c4f5df96602d194c61197f9", [:make, :mix], [], "hexpm"},
"html5ever": {:hex, :html5ever, "0.7.0", "9f63ec1c783b2dc9f326840fcc993c01e926dbdef4e51ba1bbe5355993c258b4", [:mix], [{:rustler, "~> 0.18.0", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm"},
"html_entities": {:hex, :html_entities, "0.5.0", "40f5c5b9cbe23073b48a4e69c67b6c11974f623a76165e2b92d098c0e88ccb1d", [:mix], [], "hexpm"},
"inch_ex": {:hex, :inch_ex, "2.0.0", "24268a9284a1751f2ceda569cd978e1fa394c977c45c331bb52a405de544f4de", [:mix], [{:bunt, "~> 0.2", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
Expand Down

0 comments on commit 17eab75

Please # to comment.