From 66f4b49104a8a58a5267ba5d4cf73373bd1ed947 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Sat, 9 Mar 2024 11:11:21 +0100 Subject: [PATCH 1/8] Add code coverage --- .github/workflows/ci.yml | 9 ++++++++- mix.exs | 13 +++++++++++-- mix.lock | 3 +++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4798d8..ab4dcb9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,7 @@ jobs: elixir: "1.16" otp: "26.2" lint: lint + coverage: coverage steps: - uses: actions/checkout@v4 @@ -52,4 +53,10 @@ jobs: - run: mix compile --warnings-as-errors if: ${{ matrix.lint }} - - run: mix test + - name: mix test + run: | + if [ -z "${{ matrix.coverage }}"" ]; then + mix test + else + mix coveralls.html + fi diff --git a/mix.exs b/mix.exs index 9ae6e5a..30fe166 100644 --- a/mix.exs +++ b/mix.exs @@ -14,7 +14,14 @@ defmodule Mox.MixProject do description: "Mocks and explicit contracts for Elixir", deps: deps(), docs: docs(), - package: package() + package: package(), + test_coverage: [tool: ExCoveralls], + preferred_cli_env: [ + coveralls: :test, + "coveralls.detail": :test, + "coveralls.post": :test, + "coveralls.html": :test + ] ] end @@ -31,7 +38,9 @@ defmodule Mox.MixProject do defp deps do [ {:nimble_ownership, "~> 0.3.0"}, - {:ex_doc, "~> 0.16", only: :docs} + {:castore, "~> 1.0", only: :test}, + {:ex_doc, "~> 0.16", only: :docs}, + {:excoveralls, "~> 0.18", only: :test} ] end diff --git a/mix.lock b/mix.lock index 36d7fbb..b84eb11 100644 --- a/mix.lock +++ b/mix.lock @@ -1,6 +1,9 @@ %{ + "castore": {:hex, :castore, "1.0.5", "9eeebb394cc9a0f3ae56b813459f990abb0a3dedee1be6b27fdb50301930502f", [:mix], [], "hexpm", "8d7c597c3e4a64c395980882d4bca3cebb8d74197c590dc272cfd3b6a6310578"}, "earmark_parser": {:hex, :earmark_parser, "1.4.26", "f4291134583f373c7d8755566122908eb9662df4c4b63caa66a0eabe06569b0a", [:mix], [], "hexpm", "48d460899f8a0c52c5470676611c01f64f3337bad0b26ddab43648428d94aabc"}, "ex_doc": {:hex, :ex_doc, "0.28.5", "3e52a6d2130ce74d096859e477b97080c156d0926701c13870a4e1f752363279", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "d2c4b07133113e9aa3e9ba27efb9088ba900e9e51caa383919676afdf09ab181"}, + "excoveralls": {:hex, :excoveralls, "0.18.0", "b92497e69465dc51bc37a6422226ee690ab437e4c06877e836f1c18daeb35da9", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1109bb911f3cb583401760be49c02cbbd16aed66ea9509fc5479335d284da60b"}, + "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, "makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, From adb970a53fcd65030c992785a710b071ffe241a5 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Sat, 9 Mar 2024 11:13:25 +0100 Subject: [PATCH 2/8] GH token --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab4dcb9..323d7e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,8 @@ jobs: runs-on: ubuntu-20.04 env: MIX_ENV: test + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + strategy: fail-fast: false matrix: From 4a3e8da34f0f99cd018116584a56bbaf8f665f05 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Sat, 9 Mar 2024 11:13:52 +0100 Subject: [PATCH 3/8] Ooopsie --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 323d7e2..998b538 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,7 @@ jobs: - name: mix test run: | - if [ -z "${{ matrix.coverage }}"" ]; then + if [ -z "${{ matrix.coverage }}" ]; then mix test else mix coveralls.html From f167c127cb5454fc050b0219b1efad0f63f1c0f9 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Sun, 10 Mar 2024 18:40:03 +0100 Subject: [PATCH 4/8] Bump nimble_ownership --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 30fe166..c717c0b 100644 --- a/mix.exs +++ b/mix.exs @@ -37,7 +37,7 @@ defmodule Mox.MixProject do defp deps do [ - {:nimble_ownership, "~> 0.3.0"}, + {:nimble_ownership, "~> 0.3"}, {:castore, "~> 1.0", only: :test}, {:ex_doc, "~> 0.16", only: :docs}, {:excoveralls, "~> 0.18", only: :test} diff --git a/mix.lock b/mix.lock index b84eb11..aa7c948 100644 --- a/mix.lock +++ b/mix.lock @@ -7,6 +7,6 @@ "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, "makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, - "nimble_ownership": {:hex, :nimble_ownership, "0.3.0", "29514f8779b26f50f9c07109677c98c0cc0b8025e89f82964dafa9cf7d657ec0", [:mix], [], "hexpm", "76c605106bc1e60f5b028b20203a1e0c90b4350b08e4b8a33f68bb50dcb6e837"}, + "nimble_ownership": {:hex, :nimble_ownership, "0.3.1", "99d5244672fafdfac89bfad3d3ab8f0d367603ce1dc4855f86a1c75008bce56f", [:mix], [], "hexpm", "4bf510adedff0449a1d6e200e43e57a814794c8b5b6439071274d248d272a549"}, "nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"}, } From 758651db3d55587bba8b958df4f3767a289e3db3 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Tue, 12 Mar 2024 10:26:17 +0100 Subject: [PATCH 5/8] Silly cache --- .github/workflows/ci.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 998b538..7d1fce6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,17 +30,19 @@ jobs: - uses: erlef/setup-beam@v1 with: - otp-version: ${{matrix.pair.otp}} - elixir-version: ${{matrix.pair.elixir}} + otp-version: ${{ matrix.pair.otp }} + elixir-version: ${{ matrix.pair.elixir }} - uses: actions/cache@v4 with: path: | deps _build - key: ${{ runner.os }}-mix-${{matrix.pair.elixir}}-${{matrix.pair.otp}}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-mix- + key: | + ${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}-${{ hashFiles('**/mix.lock') }}-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}-${{ hashFiles('**/mix.lock') }}- + ${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}- - run: mix deps.get --check-locked From 582deadaf37d5a337b5bd5ebd438dc7115aa7436 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Tue, 12 Mar 2024 10:31:38 +0100 Subject: [PATCH 6/8] Better CI caching --- .github/workflows/ci.yml | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d1fce6..2c52594 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,14 +26,18 @@ jobs: lint: lint coverage: coverage steps: - - uses: actions/checkout@v4 + - name: Check out this repository + uses: actions/checkout@v4 - - uses: erlef/setup-beam@v1 + - name: Set up Erlang and Elixir + uses: erlef/setup-beam@v1 with: otp-version: ${{ matrix.pair.otp }} elixir-version: ${{ matrix.pair.elixir }} - - uses: actions/cache@v4 + - name: Restored cached Mix dependencies (downloaded and compiled) + uses: actions/cache/restore@v4 + id: restore-mix-deps-cache with: path: | deps @@ -44,20 +48,30 @@ jobs: ${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}-${{ hashFiles('**/mix.lock') }}- ${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}- - - run: mix deps.get --check-locked + - name: Fetch and compile Mix dependencies + run: mix do deps.get --check-locked, deps.compile - - run: mix format --check-formatted - if: ${{ matrix.lint }} + - name: Cache compiled Mix dependencies + uses: actions/cache/save@v4 + with: + path: | + deps + _build + key: ${{ steps.restore-mix-deps-cache.outputs.cache-primary-key }} - - run: mix deps.unlock --check-unused + - name: Check for formatted files + run: mix format --check-formatted if: ${{ matrix.lint }} - - run: mix deps.compile + - name: Check for unused dependencies + run: mix deps.unlock --check-unused + if: ${{ matrix.lint }} - - run: mix compile --warnings-as-errors + - name: Check compilation warnings + run: mix compile --warnings-as-errors if: ${{ matrix.lint }} - - name: mix test + - name: Run tests run: | if [ -z "${{ matrix.coverage }}" ]; then mix test From 56a577adbee00a4e64e95e2adfdc372a77018ed1 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Tue, 12 Mar 2024 10:33:02 +0100 Subject: [PATCH 7/8] WIP --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c52594..d4497ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,7 +74,10 @@ jobs: - name: Run tests run: | if [ -z "${{ matrix.coverage }}" ]; then + echo "Running tests without coverage." mix test else - mix coveralls.html + echo "Running tests with coverage." + mix test + # mix coveralls.html fi From 532103165bd5aed41ba0d5d6f5f29eeabb2ba926 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Tue, 12 Mar 2024 10:36:51 +0100 Subject: [PATCH 8/8] Now --- .github/workflows/ci.yml | 17 ++++++++--------- test/cluster_test.exs | 3 +++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d4497ae..2f52376 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,13 +71,12 @@ jobs: run: mix compile --warnings-as-errors if: ${{ matrix.lint }} + # We always need to run tests because code coverage forces us to skip some + # tests, so better to run normal tests on the whole matrix and the coverage + # only on the latest version. - name: Run tests - run: | - if [ -z "${{ matrix.coverage }}" ]; then - echo "Running tests without coverage." - mix test - else - echo "Running tests with coverage." - mix test - # mix coveralls.html - fi + run: mix test + + - name: Run tests with coverage + if: ${{ matrix.coverage }} + run: mix coveralls.github --exclude fails_on_coverage diff --git a/test/cluster_test.exs b/test/cluster_test.exs index e221e75..1984aae 100644 --- a/test/cluster_test.exs +++ b/test/cluster_test.exs @@ -10,6 +10,9 @@ if otp_release >= 25 do use ExUnit.Case import Mox + # These tests don't work if code coverage is enabled. + @moduletag :fails_on_coverage + setup_all do Task.start_link(fn -> System.cmd("epmd", [])