|
| 1 | +name: Elixir CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + pull_request: |
| 7 | + branches: ["main"] |
| 8 | + |
| 9 | +env: |
| 10 | + MIX_ENV: test |
| 11 | + TEST_DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/postgres" |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +jobs: |
| 17 | + test: |
| 18 | + services: |
| 19 | + db: |
| 20 | + image: postgres:12 |
| 21 | + ports: ["5432:5432"] |
| 22 | + env: |
| 23 | + POSTGRES_PASSWORD: postgres |
| 24 | + options: >- |
| 25 | + --health-cmd pg_isready |
| 26 | + --health-interval 10s |
| 27 | + --health-timeout 5s |
| 28 | + --health-retries 5 |
| 29 | +
|
| 30 | + runs-on: ubuntu-latest |
| 31 | + name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} |
| 32 | + strategy: |
| 33 | + matrix: |
| 34 | + otp: ["27.2"] |
| 35 | + elixir: ["1.18.1"] |
| 36 | + steps: |
| 37 | + - name: Set up Elixir |
| 38 | + uses: erlef/setup-beam@v1 |
| 39 | + with: |
| 40 | + otp-version: ${{matrix.otp}} |
| 41 | + elixir-version: ${{matrix.elixir}} |
| 42 | + |
| 43 | + - name: Checkout code |
| 44 | + uses: actions/checkout@v3 |
| 45 | + |
| 46 | + - name: Cache deps |
| 47 | + id: cache-deps |
| 48 | + uses: actions/cache@v3 |
| 49 | + env: |
| 50 | + cache-name: cache-elixir-deps |
| 51 | + with: |
| 52 | + path: deps |
| 53 | + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} |
| 54 | + restore-keys: | |
| 55 | + ${{ runner.os }}-mix-${{ env.cache-name }}- |
| 56 | +
|
| 57 | + - name: Cache compiled build |
| 58 | + id: cache-build |
| 59 | + uses: actions/cache@v3 |
| 60 | + env: |
| 61 | + cache-name: cache-compiled-build |
| 62 | + with: |
| 63 | + path: _build |
| 64 | + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} |
| 65 | + restore-keys: | |
| 66 | + ${{ runner.os }}-mix-${{ env.cache-name }}- |
| 67 | + ${{ runner.os }}-mix- |
| 68 | +
|
| 69 | + - name: Install dependencies |
| 70 | + run: mix deps.get |
| 71 | + |
| 72 | + - name: Compile without warnings |
| 73 | + run: mix compile --warnings-as-errors |
| 74 | + |
| 75 | + - name: Check formatting |
| 76 | + run: mix format --check-formatted |
| 77 | + |
| 78 | + - name: Run tests |
| 79 | + run: mix test |
| 80 | + |
| 81 | + - name: Restore PLT cache |
| 82 | + id: plt_cache |
| 83 | + uses: actions/cache/restore@v3 |
| 84 | + with: |
| 85 | + key: | |
| 86 | + plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }} |
| 87 | + restore-keys: | |
| 88 | + plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}- |
| 89 | + path: | |
| 90 | + priv/plts |
| 91 | +
|
| 92 | + - name: Create PLTs |
| 93 | + if: steps.plt_cache.outputs.cache-hit != 'true' |
| 94 | + run: mix dialyzer --plt |
| 95 | + |
| 96 | + - name: Save PLT cache |
| 97 | + id: plt_cache_save |
| 98 | + uses: actions/cache/save@v3 |
| 99 | + if: steps.plt_cache.outputs.cache-hit != 'true' |
| 100 | + with: |
| 101 | + key: | |
| 102 | + plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }} |
| 103 | + path: | |
| 104 | + priv/plts |
| 105 | +
|
| 106 | + - name: Run dialyzer |
| 107 | + run: mix dialyzer --format github --format dialyxir |
0 commit comments