From 65b2b0ba099ee5d9e11138263c7cb8d96f34127f Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Mon, 16 Oct 2023 11:28:58 +0200 Subject: [PATCH 1/5] Run Dialyzer in CI --- .github/workflows/main.yml | 58 +++++++++++++++++++++++++++++++++++++- mix.exs | 6 ++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1374103..9b3ee38 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,7 +26,7 @@ jobs: otp-version: ${{ env.OTP_VERSION }} elixir-version: ${{ env.ELIXIR_VERSION}} - - name: Cache /_build and /deps + - name: Cache Mix compiled stuff uses: actions/cache@v3 id: cache-mix with: @@ -48,6 +48,62 @@ jobs: - name: Check for formatted code run: mix format --check-formatted + dialyzer: + name: Dialyze + runs-on: ubuntu-20.04 + + env: + ELIXIR_VERSION: "1.15" + OTP_VERSION: "26.1" + + steps: + - name: Check out this repository + uses: actions/checkout@v4 + + - name: Install Erlang and Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: ${{ env.OTP_VERSION }} + elixir-version: ${{ env.ELIXIR_VERSION}} + + - name: Cache Mix compiled stuff + uses: actions/cache@v3 + id: cache-mix + with: + path: | + _build + deps + key: | + mix-elixir${{ env.ELIXIR_VERSION }}-otp${{ env.OTP_VERSION }}-${{ hashFiles('mix.lock') }}-${{ github.run_id }}-${{ github.run_attempt }} + restore-keys: | + mix-elixir${{ env.ELIXIR_VERSION }}-otp${{ env.OTP_VERSION }}-${{ hashFiles('mix.lock') }}-${{ github.run_id }}- + mix-elixir${{ env.ELIXIR_VERSION }}-otp${{ env.OTP_VERSION }}-${{ hashFiles('mix.lock') }}- + + # Don't cache PLTs based on mix.lock hash, as Dialyzer can incrementally update even old + # ones. Cache key based on Elixir and Erlang version (also useful when running in matrix). + - name: Cache Dialyzer's PLT + uses: actions/cache@v3 + id: cache-plt + with: + path: priv/plts + key: | + plt-otp${{ env.OTP_VERSION }}-elixir${{ env.ELIXIR_VERSION }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + plt-otp${{ env.OTP_VERSION }}-elixir${{ env.ELIXIR_VERSION }}- + + # Create PLTs if no cache was found + - name: Create PLTs + if: steps.cache-plt.outputs.cache-hit != 'true' + run: | + mkdir -p priv/plts + mix dialyzer --plt + + - name: Install dependencies + run: mix deps.get + + - name: Run Dialyzer + run: mix dialyzer --format github + test: name: Test (Erlang ${{ matrix.otp }}, Elixir ${{ matrix.elixir }}, Toxiproxy ${{ matrix.toxiproxy }}) diff --git a/mix.exs b/mix.exs index ee1abed..00e6916 100644 --- a/mix.exs +++ b/mix.exs @@ -12,6 +12,12 @@ defmodule ToxiproxyEx.MixProject do start_permanent: Mix.env() == :prod, deps: deps(), + # Dialyzer + dialyzer: [ + plt_local_path: "priv/plts", + plt_core_path: "priv/plts" + ], + # Hex description: "Elixir Client for Toxiproxy", package: package(), From 60b54c9632a2eb013463e9fff6c1969b3244d17a Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Mon, 16 Oct 2023 11:31:06 +0200 Subject: [PATCH 2/5] FIXUP --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 00e6916..a7fd997 100644 --- a/mix.exs +++ b/mix.exs @@ -41,7 +41,7 @@ defmodule ToxiproxyEx.MixProject do {:castore, "~> 1.0.3"}, {:mint, "~> 1.0"}, {:ex_doc, "~> 0.23", only: :dev, runtime: false}, - {:dialyxir, "~> 1.4", only: [:dev], runtime: false} + {:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false} ] end From d0ba7f3b4abb4449f3fe4390e9a4941a8df2d8eb Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Mon, 16 Oct 2023 11:33:23 +0200 Subject: [PATCH 3/5] Oopsie --- mix.exs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mix.exs b/mix.exs index a7fd997..aa425df 100644 --- a/mix.exs +++ b/mix.exs @@ -40,9 +40,13 @@ defmodule ToxiproxyEx.MixProject do {:jason, ">= 1.0.0"}, {:castore, "~> 1.0.3"}, {:mint, "~> 1.0"}, - {:ex_doc, "~> 0.23", only: :dev, runtime: false}, - {:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false} - ] + {:ex_doc, "~> 0.23", only: :dev, runtime: false} + ] ++ + if Version.match?(System.version(), "~> 1.12") do + [{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false}] + else + [] + end end defp package do From a422ebfa39213d8fa2ac2579c5e8ae7542e01bea Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Mon, 16 Oct 2023 11:37:45 +0200 Subject: [PATCH 4/5] Add appds --- mix.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index aa425df..e5b85de 100644 --- a/mix.exs +++ b/mix.exs @@ -15,7 +15,8 @@ defmodule ToxiproxyEx.MixProject do # Dialyzer dialyzer: [ plt_local_path: "priv/plts", - plt_core_path: "priv/plts" + plt_core_path: "priv/plts", + plt_add_apps: [:ssl, :crypto, :mix, :ex_unit, :erts, :kernel, :stdlib], ], # Hex From c5be36f8d75740e0059dab54d21040d1ee1906d1 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Mon, 16 Oct 2023 11:41:26 +0200 Subject: [PATCH 5/5] Formatting --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index e5b85de..60fe287 100644 --- a/mix.exs +++ b/mix.exs @@ -16,7 +16,7 @@ defmodule ToxiproxyEx.MixProject do dialyzer: [ plt_local_path: "priv/plts", plt_core_path: "priv/plts", - plt_add_apps: [:ssl, :crypto, :mix, :ex_unit, :erts, :kernel, :stdlib], + plt_add_apps: [:ssl, :crypto, :mix, :ex_unit, :erts, :kernel, :stdlib] ], # Hex