name: Elixir quality

on:
  push:
  pull_request:

jobs:
  quality:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgis/postgis:17-3.5
        env:
          POSTGRES_PASSWORD: postgres
          POSTGRES_USER: postgres
          POSTGRES_DB: aprsme_test
        ports:
          - 5432:5432
        options: >-
          --health-cmd "pg_isready -U postgres"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
    env:
      MIX_ENV: test
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: recursive
      - uses: erlef/setup-beam@v1
        with:
          otp-version: "29.0"
          elixir-version: "1.20"
      - uses: actions/cache@v4
        with:
          path: |
            deps
            _build
          key: ${{ runner.os }}-mix-${{ hashFiles('mix.lock') }}
      - run: mix local.hex --force
      - run: mix local.rebar --force
      - run: mix deps.get
      - run: mix format --check-formatted
      - run: mix compile --warnings-as-errors
      - run: mix credo --strict
      - run: mix test
      - run: mix sobelow --config
      - run: mix hex.audit

  dialyzer:
    runs-on: ubuntu-latest
    env:
      MIX_ENV: dev
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: recursive
      - uses: erlef/setup-beam@v1
        with:
          otp-version: "29.0"
          elixir-version: "1.20"
      - uses: actions/cache@v4
        with:
          path: |
            deps
            _build
          key: ${{ runner.os }}-dialyzer-${{ hashFiles('mix.lock') }}
      - run: mix local.hex --force
      - run: mix local.rebar --force
      - run: mix deps.get
      - run: mix dialyzer
