diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..126c10e94 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,70 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ '*' ] + +env: + MIX_ENV: test + +permissions: + contents: read + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Elixir + uses: erlef/setup-beam@v1 + with: + version-type: strict + version-file: .tool-versions + env: + ImageOS: ubuntu20 + - name: Restore dependencies cache + uses: actions/cache@v3 + with: + path: deps + key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-mix- + - name: Install dependencies + run: mix deps.get + - name: Retrieve PLT Cache + uses: actions/cache@v1 + id: plt-cache + with: + path: priv/plts + key: ${{ runner.os }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + - name: Create PLTs + if: steps.plt-cache.outputs.cache-hit != 'true' + run: | + mkdir -p priv/plts + mix dialyzer --plt + - name: Run dialyzer + run: mix dialyzer --no-check + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Elixir + uses: erlef/setup-beam@v1 + with: + version-type: strict + version-file: .tool-versions + env: + ImageOS: ubuntu20 + - name: Restore dependencies cache + uses: actions/cache@v3 + with: + path: deps + key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-mix- + - name: Install dependencies + run: mix deps.get + - name: Run tests + run: mix test diff --git a/.gitignore b/.gitignore index 71f58e1c4..dd2cb66e7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,10 @@ # If you run "mix test --cover", coverage assets end up here. /cover/ +# mix dialyzer artifacts +/priv/plts/*.plt +/priv/plts/*.plt.hash + # The directory Mix downloads your dependencies sources to. /deps/ diff --git a/lib/lambda_ethereum_consensus.ex b/lib/lambda_ethereum_consensus.ex index d36e512fe..36dea310d 100644 --- a/lib/lambda_ethereum_consensus.ex +++ b/lib/lambda_ethereum_consensus.ex @@ -12,6 +12,7 @@ defmodule LambdaEthereumConsensus do :world """ + @spec hello() :: :world def hello do :world end diff --git a/mix.exs b/mix.exs index c132a684d..3c1d95b55 100644 --- a/mix.exs +++ b/mix.exs @@ -7,7 +7,11 @@ defmodule LambdaEthereumConsensus.MixProject do version: "0.1.0", elixir: "~> 1.15", start_permanent: Mix.env() == :prod, - deps: deps() + deps: deps(), + dialyzer: dialyzer(), + preferred_cli_env: [ + dialyzer: :test + ], ] end @@ -22,8 +26,13 @@ defmodule LambdaEthereumConsensus.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - # {:dep_from_hexpm, "~> 0.3.0"}, - # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + {:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false}, + ] + end + + defp dialyzer() do + [ + plt_file: {:no_warn, "priv/plts/project.plt"} ] end end diff --git a/mix.lock b/mix.lock new file mode 100644 index 000000000..1d5ea5427 --- /dev/null +++ b/mix.lock @@ -0,0 +1,4 @@ +%{ + "dialyxir": {:hex, :dialyxir, "1.3.0", "fd1672f0922b7648ff9ce7b1b26fcf0ef56dda964a459892ad15f6b4410b5284", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "00b2a4bcd6aa8db9dcb0b38c1225b7277dca9bc370b6438715667071a304696f"}, + "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, +}