From 4ef7de81bdb8dd261e32705467988173822d69f4 Mon Sep 17 00:00:00 2001 From: Martin Paulucci Date: Thu, 3 Aug 2023 16:50:02 +0200 Subject: [PATCH 1/8] Add basic CI and dialyzer. --- .github/workflows/ci.yml | 58 ++++++++++++++++++++++++++++++++ .gitignore | 4 +++ Makefile | 3 ++ lib/lambda_ethereum_consensus.ex | 1 + mix.exs | 15 +++++++-- mix.lock | 4 +++ 6 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 mix.lock diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..6f7880382 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,58 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + MIX_ENV: test + +permissions: + contents: read + +jobs: + build: + name: Build and test + runs-on: ubuntu-latest + strategy: + matrix: + elixir: [1.15.4] + otp: [25.3.2.5] + steps: + - uses: actions/checkout@v3 + - name: Set up Elixir + uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f + with: + elixir-version: ${{ matrix.elixir }} # Define the elixir version [required] + otp-version: ${{ matrix.otp }} # Define the OTP version [required] + 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: Check Formatting + run: mix format --check-formatted + - name: Run Credo + run: mix credo --strict + - name: Retrieve PLT Cache + uses: actions/cache@v1 + id: plt-cache + with: + path: priv/plts + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-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 --halt-exit-status + - 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/Makefile b/Makefile index 32f899108..5f9ef2daf 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,9 @@ iex: deps: mix deps.get +lint: + mix credo --strict + # Run tests test: mix test 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 b9aa7a504..a0d507991 100644 --- a/mix.exs +++ b/mix.exs @@ -7,7 +7,11 @@ defmodule LambdaEthereumConsensus.MixProject do version: "0.1.0", elixir: "~> 1.14", 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"}, +} From 897a5f6051415dd2b434f30781a46d45fe7ccfff Mon Sep 17 00:00:00 2001 From: Martin Paulucci Date: Thu, 3 Aug 2023 16:52:25 +0200 Subject: [PATCH 2/8] Remove credo for now. --- .github/workflows/ci.yml | 4 ---- Makefile | 3 --- 2 files changed, 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f7880382..6ac836737 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,10 +37,6 @@ jobs: restore-keys: ${{ runner.os }}-mix- - name: Install dependencies run: mix deps.get - - name: Check Formatting - run: mix format --check-formatted - - name: Run Credo - run: mix credo --strict - name: Retrieve PLT Cache uses: actions/cache@v1 id: plt-cache diff --git a/Makefile b/Makefile index 5f9ef2daf..32f899108 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,6 @@ iex: deps: mix deps.get -lint: - mix credo --strict - # Run tests test: mix test From b38a4db12714a552be0b2f80d7257495e400085c Mon Sep 17 00:00:00 2001 From: Martin Paulucci Date: Thu, 3 Aug 2023 17:22:02 +0200 Subject: [PATCH 3/8] Separate Build and Test jobs. --- .github/workflows/ci.yml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ac836737..78ccd5df1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,12 +14,12 @@ permissions: jobs: build: - name: Build and test + name: Build runs-on: ubuntu-latest strategy: matrix: - elixir: [1.15.4] - otp: [25.3.2.5] + elixir: [1.15] + otp: [25] steps: - uses: actions/checkout@v3 - name: Set up Elixir @@ -50,5 +50,21 @@ jobs: mix dialyzer --plt - name: Run dialyzer run: mix dialyzer --no-check --halt-exit-status + test: + name: Build + runs-on: ubuntu-latest + strategy: + matrix: + elixir: [1.15] + otp: [25] + steps: + - uses: actions/checkout@v3 + - name: Set up Elixir + uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f + with: + elixir-version: ${{ matrix.elixir }} # Define the elixir version [required] + otp-version: ${{ matrix.otp }} # Define the OTP version [required] + env: + ImageOS: ubuntu20 - name: Run tests run: mix test From e6eed9881d5e783d9f5d13dbb34cdf95cd2983d7 Mon Sep 17 00:00:00 2001 From: Martin Paulucci Date: Thu, 3 Aug 2023 17:23:04 +0200 Subject: [PATCH 4/8] Rename job. --- .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 78ccd5df1..f6e07b62c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: - name: Run dialyzer run: mix dialyzer --no-check --halt-exit-status test: - name: Build + name: Test runs-on: ubuntu-latest strategy: matrix: From 2d371008b567086f364cb69f6df7c2ec58601553 Mon Sep 17 00:00:00 2001 From: Martin Paulucci Date: Thu, 3 Aug 2023 17:24:33 +0200 Subject: [PATCH 5/8] Fix test job. --- .github/workflows/ci.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6e07b62c..90d358d40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,6 +65,14 @@ jobs: elixir-version: ${{ matrix.elixir }} # Define the elixir version [required] otp-version: ${{ matrix.otp }} # Define the OTP version [required] env: - ImageOS: ubuntu20 + 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 From 7bd61de88b0b326bbe4c633b5ee557611b1d0fc8 Mon Sep 17 00:00:00 2001 From: Martin Paulucci Date: Thu, 3 Aug 2023 17:40:10 +0200 Subject: [PATCH 6/8] Use tool versions in CI. --- .github/workflows/ci.yml | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90d358d40..62c60b309 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,17 +16,12 @@ jobs: build: name: Build runs-on: ubuntu-latest - strategy: - matrix: - elixir: [1.15] - otp: [25] steps: - uses: actions/checkout@v3 - name: Set up Elixir - uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f + uses: erlef/setup-beam@v1 with: - elixir-version: ${{ matrix.elixir }} # Define the elixir version [required] - otp-version: ${{ matrix.otp }} # Define the OTP version [required] + version-file: .tool-versions env: ImageOS: ubuntu20 - name: Restore dependencies cache @@ -42,7 +37,7 @@ jobs: id: plt-cache with: path: priv/plts - key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + key: ${{ runner.os }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} - name: Create PLTs if: steps.plt-cache.outputs.cache-hit != 'true' run: | @@ -53,17 +48,12 @@ jobs: test: name: Test runs-on: ubuntu-latest - strategy: - matrix: - elixir: [1.15] - otp: [25] steps: - uses: actions/checkout@v3 - name: Set up Elixir - uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f + uses: erlef/setup-beam@v1 with: - elixir-version: ${{ matrix.elixir }} # Define the elixir version [required] - otp-version: ${{ matrix.otp }} # Define the OTP version [required] + version-file: .tool-versions env: ImageOS: ubuntu20 - name: Restore dependencies cache From 33a8fa6068fb2358f893ef71c1482f637ebbaea8 Mon Sep 17 00:00:00 2001 From: Martin Paulucci Date: Thu, 3 Aug 2023 17:42:05 +0200 Subject: [PATCH 7/8] Add version type scrict. --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 62c60b309..f87923ecd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,7 @@ jobs: - name: Set up Elixir uses: erlef/setup-beam@v1 with: + version-type: strict version-file: .tool-versions env: ImageOS: ubuntu20 @@ -44,7 +45,7 @@ jobs: mkdir -p priv/plts mix dialyzer --plt - name: Run dialyzer - run: mix dialyzer --no-check --halt-exit-status + run: mix dialyzer --no-check test: name: Test runs-on: ubuntu-latest @@ -53,6 +54,7 @@ jobs: - name: Set up Elixir uses: erlef/setup-beam@v1 with: + version-type: strict version-file: .tool-versions env: ImageOS: ubuntu20 From 361549be2f5e95470bc1c4c16b3a043b1096a6f3 Mon Sep 17 00:00:00 2001 From: Martin Paulucci Date: Thu, 3 Aug 2023 17:43:55 +0200 Subject: [PATCH 8/8] Add ci for every branch. --- .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 f87923ecd..126c10e94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: push: branches: [ main ] pull_request: - branches: [ main ] + branches: [ '*' ] env: MIX_ENV: test