diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml new file mode 100644 index 000000000..3d918d70f --- /dev/null +++ b/.github/workflows/elixir.yml @@ -0,0 +1,107 @@ +name: Elixir CI + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +env: + MIX_ENV: test + TEST_DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/postgres" + +permissions: + contents: read + +jobs: + test: + services: + db: + image: postgres:12 + ports: ["5432:5432"] + env: + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + runs-on: ubuntu-latest + name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} + strategy: + matrix: + otp: ["27.2"] + elixir: ["1.18.1"] + steps: + - name: Set up Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: ${{matrix.otp}} + elixir-version: ${{matrix.elixir}} + + - name: Checkout code + uses: actions/checkout@v3 + + - name: Cache deps + id: cache-deps + uses: actions/cache@v3 + env: + cache-name: cache-elixir-deps + with: + path: deps + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix-${{ env.cache-name }}- + + - name: Cache compiled build + id: cache-build + uses: actions/cache@v3 + env: + cache-name: cache-compiled-build + with: + path: _build + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix-${{ env.cache-name }}- + ${{ runner.os }}-mix- + + - name: Install dependencies + run: mix deps.get + + - name: Compile without warnings + run: mix compile --warnings-as-errors + + - name: Check formatting + run: mix format --check-formatted + + - name: Run tests + run: mix test + + - name: Restore PLT cache + id: plt_cache + uses: actions/cache/restore@v3 + with: + key: | + plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}- + path: | + priv/plts + + - name: Create PLTs + if: steps.plt_cache.outputs.cache-hit != 'true' + run: mix dialyzer --plt + + - name: Save PLT cache + id: plt_cache_save + uses: actions/cache/save@v3 + if: steps.plt_cache.outputs.cache-hit != 'true' + with: + key: | + plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }} + path: | + priv/plts + + - name: Run dialyzer + run: mix dialyzer --format github --format dialyxir diff --git a/mix.exs b/mix.exs index 6e556b792..b3b737b5c 100644 --- a/mix.exs +++ b/mix.exs @@ -58,7 +58,7 @@ defmodule Algora.MixProject do {:dns_cluster, "~> 0.1.1"}, {:bandit, "~> 1.2"}, {:credo, "~> 1.7", only: [:dev, :test], runtime: false}, - {:dialyxir, "~> 1.3", only: [:dev], runtime: false}, + {:dialyxir, "~> 1.3", only: [:dev, :test], runtime: false}, {:joken, "~> 2.5"}, {:nanoid, "~> 2.1.0"}, {:ex_cldr, "~> 2.0"},