diff --git a/.dialyzerignore b/.dialyzerignore new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 911454d..3c251f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,9 +12,12 @@ jobs: lint: runs-on: ubuntu-latest + env: + MIX_ENV: test + strategy: matrix: - elixir: [1.17.0] + elixir: [1.18.1] otp: [27.0] steps: @@ -27,8 +30,30 @@ jobs: elixir-version: ${{ matrix.elixir }} otp-version: ${{ matrix.otp }} - - name: Install dependencies - run: mix deps.get + - name: Cache Elixir deps + uses: actions/cache@v1 + id: deps-cache + with: + path: deps + key: ${{ runner.os }}-mix-${{ env.MIX_ENV }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + + - name: Cache Elixir _build + uses: actions/cache@v1 + id: build-cache + with: + path: _build + key: ${{ runner.os }}-build-${{ env.MIX_ENV }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + + - name: Install deps + if: steps.deps-cache.outputs.cache-hit != 'true' + run: | + mix local.rebar --force + mix local.hex --force + mix deps.get --only ${{ env.MIX_ENV }} + + - name: Compile deps + if: steps.build-cache.outputs.cache-hit != 'true' + run: mix deps.compile --warnings-as-errors - name: Clean build run: mix clean @@ -38,3 +63,127 @@ jobs: - name: Run Credo run: mix credo --strict + + static-analisys: + runs-on: ubuntu-latest + + env: + MIX_ENV: test + + strategy: + matrix: + elixir: [1.18.1] + otp: [27.0] + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Elixir + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + + - name: Cache Elixir deps + uses: actions/cache@v1 + id: deps-cache + with: + path: deps + key: ${{ runner.os }}-mix-${{ env.MIX_ENV }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + + - name: Cache Elixir _build + uses: actions/cache@v1 + id: build-cache + with: + path: _build + key: ${{ runner.os }}-build-${{ env.MIX_ENV }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + + - name: Install deps + if: steps.deps-cache.outputs.cache-hit != 'true' + run: | + mix local.rebar --force + mix local.hex --force + mix deps.get --only ${{ env.MIX_ENV }} + + - name: Compile deps + if: steps.build-cache.outputs.cache-hit != 'true' + run: mix deps.compile --warnings-as-errors + + # Don't cache PLTs based on mix.lock hash, as Dialyzer can incrementally update even old ones + # Cache key based on Elixir & Erlang version (also useful when running in matrix) + - name: Restore PLT cache + uses: actions/cache/restore@v3 + id: plt_cache + with: + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt + restore-keys: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt + path: priv/plts + + # Create PLTs if no cache was found + - name: Create PLTs + if: steps.plt_cache.outputs.cache-hit != 'true' + run: mix dialyzer --plt + + - name: Save PLT cache + uses: actions/cache/save@v3 + if: steps.plt_cache.outputs.cache-hit != 'true' + id: plt_cache_save + with: + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt + path: priv/plts + + - name: Run dialyzer + run: mix dialyzer --format github + + test: + runs-on: ubuntu-latest + + env: + MIX_ENV: test + + strategy: + matrix: + elixir: [1.18.1] + otp: [27.0] + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Elixir + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + + - name: Cache Elixir deps + uses: actions/cache@v1 + id: deps-cache + with: + path: deps + key: ${{ runner.os }}-mix-${{ env.MIX_ENV }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + + - name: Cache Elixir _build + uses: actions/cache@v1 + id: build-cache + with: + path: _build + key: ${{ runner.os }}-build-${{ env.MIX_ENV }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + + - name: Install deps + if: steps.deps-cache.outputs.cache-hit != 'true' + run: | + mix local.rebar --force + mix local.hex --force + mix deps.get --only ${{ env.MIX_ENV }} + + - name: Compile deps + if: steps.build-cache.outputs.cache-hit != 'true' + run: mix deps.compile --warnings-as-errors + + - name: Clean build + run: mix clean + + - name: Run tests + run: mix test diff --git a/.gitignore b/.gitignore index ea0e15f..bf32c41 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,5 @@ result /.elixir_ls/ /.elixir-tools/ + +/priv/plts diff --git a/mix.exs b/mix.exs index 14a7cca..a6acd3f 100644 --- a/mix.exs +++ b/mix.exs @@ -13,7 +13,8 @@ defmodule Supabase.Storage.MixProject do deps: deps(), package: package(), description: description(), - docs: docs() + docs: docs(), + dialyzer: [plt_local_path: "priv/plts", ignore_warnings: ".dialyzerignore"] ] end @@ -27,9 +28,9 @@ defmodule Supabase.Storage.MixProject do [ {:ecto, "~> 3.10"}, {:supabase_potion, path: "../supabase-ex"}, - {:ex_doc, ">= 0.0.0", runtime: false}, + {:ex_doc, ">= 0.0.0", only: :dev, runtime: false}, {:credo, "~> 1.7", only: [:dev, :test], runtime: false}, - {:dialyxir, "~> 1.3", only: [:dev], runtime: false} + {:dialyxir, "~> 1.3", only: [:dev, :test], runtime: false} ] end