Skip to content

Commit

Permalink
Add excoveralls and codecov for test coverage (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
aifrak authored Aug 10, 2021
1 parent 636e05f commit a0cb178
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 26 deletions.
16 changes: 16 additions & 0 deletions .check-ci.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Override default config from .check.exs
[
tools: [
{
:ex_unit,
"mix coveralls.json",
env: %{"MIX_ENV" => "test"},
detect: [
{:package, :excoveralls, else: :skip},
{:file, "coveralls.json", else: :skip},
{:file, "codecov.yml", else: :skip}
],
retry: "mix coveralls.json --failed"
}
]
]
16 changes: 16 additions & 0 deletions .check-dev.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Override default config from .check.exs
[
tools: [
{
:ex_unit,
"mix test.cover",
env: %{"MIX_ENV" => "test"},
detect: [
{:package, :excoveralls, else: :skip},
{:file, "coveralls.json", else: :skip},
{:file, "codecov.yml", else: :skip}
],
retry: "mix test.cover --failed"
}
]
]
13 changes: 10 additions & 3 deletions .check.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Override default config from the "ex_check"
[
retry: false,
tools: [
# Curated tools from ex_check
{:compiler, env: %{"MIX_ENV" => "test"}},
Expand All @@ -7,11 +9,16 @@
{:npm_test, false},
{
:sobelow,
"mix sobelow --config",
env: %{"MIX_ENV" => "test"}, detect: [{:package, :phoenix, else: :disable}]
"mix sobelow.default",
env: %{"MIX_ENV" => "test"},
umbrella: [recursive: true],
detect: [
{:package, :sobelow, else: :skip},
{:package, :phoenix, else: :skip}
]
},

# Custom lints
# Custom tools
{:dockerfile_lint, "./run dockerfile:lint"},
{:elixir_eex_lint, "./run elixir:eex:lint"},
{:markdown_lint, "./run markdown:lint"},
Expand Down
24 changes: 15 additions & 9 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
# Override default config from the "credo"
%{
configs: [
%{
name: "default",
files: %{
included: [
"config/",
"lib/",
"test/",
"mix.exs",
".check*.exs",
".credo.exs",
".formatter.exs",
".sobelow-conf",
"apps/*/lib/",
"apps/*/test/",
"apps/*/mix.exs",
"apps/*/.check*.exs",
"apps/*/.credo.exs",
"apps/*/.formatter.exs"
"apps/*/.formatter.exs",
"apps/*/.sobelow-conf",
"apps/*/mix.exs"
],
excluded: [
~r"/_build/",
Expand Down Expand Up @@ -47,14 +53,14 @@
]},
{CredoNaming.Check.Consistency.ModuleFilename,
excluded_paths: [
"config",
"config/",
"mix.exs",
"priv",
"test/support",
"apps/*/config",
"apps/*/mix.exs",
"apps/*/priv",
"apps/*/test/support"
"priv/",
"test/support/",
"apps/*/config/",
"apps/*/priv/",
"apps/*/test/support/",
"apps/*/mix.exs"
],
acronyms: [{"GraphQL", "graphql"}]},

Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ jobs:
- name: Fetch and compile Elixir dependencies
if: steps.elixir-deps-cache.outputs.cache-hit != 'true'
run: |
./run dc:exec bash -c "mix deps.get && mix deps.compile"
./run dc:exec mix install_deps.ci
- name: Install node modules
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: |
./run dc:exec bash -c "npm ci --quiet"
./run dc:exec npm ci --quiet
# ---------------------------------------------- #
# Application #
Expand All @@ -130,8 +130,15 @@ jobs:
- name: Compile Elixir application
if: steps.elixir-build-cache.outputs.cache-hit != 'true'
run: |
./run dc:exec bash -c "MIX_ENV=test mix compile"
./run dc:exec mix compile.ci
- name: Run all checks
run: |
./run dc:exec mix check
./run dc:exec mix check.ci
- name: Upload Code Coverage report
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./cover/excoveralls.json
fail_ci_if_error: true
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"autoremove",
"buildx",
"chmod",
"codecov",
"deps",
"devcontainer",
"dialyxir",
Expand All @@ -165,6 +166,7 @@
"doctest",
"editorconfig",
"eval",
"excoveralls",
"gitkeep",
"gnupg",
"hadolint",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This is a template repository for Elixir projects.

[![Tests](https://github.com/aifrak/template-elixir/actions/workflows/tests.yml/badge.svg)](https://github.com/aifrak/template-elixir/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/aifrak/exercism-elixir/branch/main/graph/badge.svg?token=P1NY8S6A8F)](https://codecov.io/gh/aifrak/exercism-elixir)
[![License](https://img.shields.io/github/license/aifrak/template-elixir?color=blue)](https://github.com/aifrak/template-elixir/blob/master/LICENSE)

After cloning this template repository, rework the content of `README.md` and
Expand Down
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coverage:
status:
project:
default:
target: 100%
patch:
default:
target: 100%
7 changes: 7 additions & 0 deletions coveralls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"print_summary": false,
"coverage_options": {
"minimum_coverage": 100,
"treat_no_relevant_lines_as_covered": true
}
}
48 changes: 39 additions & 9 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ defmodule App.MixProject do
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
aliases: aliases(),
preferred_cli_env: preferred_cli_env(),
dialyzer: dialyzer()
dialyzer: dialyzer(),
test_coverage: test_coverage()
]
end

Expand All @@ -21,24 +23,48 @@ defmodule App.MixProject do

defp deps do
[
{:credo, ">= 1.5.6", only: [:test], runtime: false},
{:credo_contrib, ">= 0.2.0", only: [:test], runtime: false},
{:credo_naming, ">= 1.0.0", only: [:test], runtime: false},
{:dialyxir, ">= 1.1.0", only: [:test], runtime: false},
{:doctor, ">= 0.18.0", only: [:test], runtime: false},
{:ex_check, ">= 0.14.0", only: [:test], runtime: false},
{:sobelow, ">= 0.11.1", only: [:test], runtime: false}
{:credo, ">= 1.5.6", only: :test, runtime: false},
{:credo_contrib, ">= 0.2.0", only: :test, runtime: false},
{:credo_naming, ">= 1.0.0", only: :test, runtime: false},
{:dialyxir, ">= 1.1.0", only: :test, runtime: false},
{:doctor, ">= 0.18.0", only: :test, runtime: false},
{:ex_check, ">= 0.14.0", only: :test, runtime: false},
{:excoveralls, ">= 0.14.2", only: :test, runtime: false},
{:sobelow, ">= 0.11.1", only: :test, runtime: false}
]
end

defp aliases do
[
check: ["check --config .check-dev.exs"],
"check.ci": ["check --config .check-ci.exs"],
"compile.ci": ["compile"],
install_deps: ["deps.unlock --unused", "deps.clean --unused", "deps.get"],
"install_deps.ci": ["install_deps", "deps.compile"],
"sobelow.default": ["sobelow --config --exit"],
test: ["test --warnings-as-errors"],
"test.cover": ["test --cover"],
"test.cover.recent": ["test --cover --stale"]
]
end

defp preferred_cli_env do
[
check: :test,
"check.ci": :test,
"compile.ci": :test,
credo: :test,
coveralls: :test,
"coveralls.detail": :test,
"coveralls.html": :test,
"coveralls.json": :test,
dialyxir: :test,
dialyzer: :test,
doctor: :test,
sobelow: :test
sobelow: :test,
"test.cover": :test,
"test.cover.recent": :test,
"sobelow.default": :test
]
end

Expand All @@ -59,4 +85,8 @@ defmodule App.MixProject do
plt_file: {:no_warn, "priv/plts/dialyzer.plt"}
]
end

defp test_coverage do
[tool: ExCoveralls]
end
end
9 changes: 9 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
%{
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
"certifi": {:hex, :certifi, "2.6.1", "dbab8e5e155a0763eea978c913ca280a6b544bfa115633fa20249c3d396d9493", [:rebar3], [], "hexpm", "524c97b4991b3849dd5c17a631223896272c6b0af446778ba4675a1dff53bb7e"},
"credo": {:hex, :credo, "1.5.6", "e04cc0fdc236fefbb578e0c04bd01a471081616e741d386909e527ac146016c6", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "4b52a3e558bd64e30de62a648518a5ea2b6e3e5d2b164ef5296244753fc7eb17"},
"credo_contrib": {:hex, :credo_contrib, "0.2.0", "032af0f1f096ddc7a2128fa475fdbb34f73563ca3fb2d6f826b0fa343b76d507", [:mix], [{:credo, "~> 1.0", [hex: :credo, repo: "hexpm", optional: false]}], "hexpm", "afebe9dd51371c121aab3eb14b1c70316be4345b0333fdcedb5d6404a06be309"},
"credo_naming": {:hex, :credo_naming, "1.0.0", "eb7391de9aa57b2e1f165899923b4f0922209da6ce3213837db19cbf9c595e18", [:make, :mix], [{:credo, "~> 1.4", [hex: :credo, repo: "hexpm", optional: false]}], "hexpm", "bd370189dac84553f91ed499719bd77f3a82a0df790f254550447a121c21bd45"},
Expand All @@ -8,7 +9,15 @@
"doctor": {:hex, :doctor, "0.18.0", "114934c1740239953208a39db617699b7e2660770e81129d7f95cdf7837ab766", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "829c88c365f72c0666e443ea670ffb6f180de7b90c23d536edabdd8c722b88f4"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_check": {:hex, :ex_check, "0.14.0", "d6fbe0bcc51cf38fea276f5bc2af0c9ae0a2bb059f602f8de88709421dae4f0e", [:mix], [], "hexpm", "8a602e98c66e6a4be3a639321f1f545292042f290f91fa942a285888c6868af0"},
"excoveralls": {:hex, :excoveralls, "0.14.2", "f9f5fd0004d7bbeaa28ea9606251bb643c313c3d60710bad1f5809c845b748f0", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "ca6fd358621cb4d29311b29d4732c4d47dac70e622850979bc54ed9a3e50f3e1"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"hackney": {:hex, :hackney, "1.17.4", "99da4674592504d3fb0cfef0db84c3ba02b4508bae2dff8c0108baa0d6e0977c", [:rebar3], [{:certifi, "~>2.6.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "de16ff4996556c8548d512f4dbe22dd58a587bf3332e7fd362430a7ef3986b16"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"sobelow": {:hex, :sobelow, "0.11.1", "23438964486f8112b41e743bbfd402da3e5b296fdc9eacab29914b79c48916dd", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "9897363a7eff96f4809304a90aad819e2ad5e5d24db547af502885146746a53c"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
}
2 changes: 1 addition & 1 deletion run
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ function pre-commit {

function install-deps {
if is_inside_docker; then
mix install_deps
npm install --quiet
mix deps.get
else
dc:exec ./run install-deps
fi
Expand Down
1 change: 1 addition & 0 deletions scripts/run/elixir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function elixir:lint {
--only dialyzer \
--only doctor \
--only unused_deps \
--only sobelow \
|| status=${?}

if [[ ${status} -ne 0 ]]; then
Expand Down

0 comments on commit a0cb178

Please sign in to comment.