name: Elixir CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    name: Build and test
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up Elixir
      uses: erlef/setup-elixir@885971a72ed1f9240973bd92ab57af8c1aa68f24
      with:
        elixir-version: '1.12.2' # Define the elixir version [required]
        otp-version: '24.0.4' # Define the OTP version [required]
    - name: Restore dependencies cache
      uses: actions/cache@v2
      with:
        working-directory: ./backend
        path: deps
        key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
        restore-keys: ${{ runner.os }}-mix-
    - name: Install dependencies
      working-directory: ./backend
      run: |
        mix local.hex --force
        mix local.rebar --force
        mix deps.get
    - name: Compile dependencies
      working-directory: ./backend
      run: mix deps.compile
    - name: Run Credo
      working-directory: ./backend
      run: mix credo --strict
    - name: Run sobelow
      working-directory: ./backend
      run: mix sobelow --config
