|
| 1 | +# This is a basic workflow to help you get started with Actions |
| 2 | + |
| 3 | +name: CI |
| 4 | + |
| 5 | +# Define workflow that runs when changes are pushed to the |
| 6 | +# `main` branch or pushed to a PR branch that targets the `main` |
| 7 | +# branch. Change the branch name if your project uses a |
| 8 | +# different name for the main branch like "master" or "production". |
| 9 | +on: |
| 10 | + push: |
| 11 | + branches: [ "main" ] # adapt branch for project |
| 12 | + pull_request: |
| 13 | + branches: [ "main" ] # adapt branch for project |
| 14 | + |
| 15 | +# Sets the ENV `MIX_ENV` to `test` for running tests |
| 16 | +env: |
| 17 | + MIX_ENV: test |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + |
| 22 | +jobs: |
| 23 | + test: |
| 24 | + # Set up a Postgres DB service. By default, Phoenix applications |
| 25 | + # use Postgres. This creates a database for running tests. |
| 26 | + # Additional services can be defined here if required. |
| 27 | + # services: |
| 28 | +# db: |
| 29 | +# image: postgres:12 |
| 30 | +# ports: ['5432:5432'] |
| 31 | +# env: |
| 32 | +# POSTGRES_PASSWORD: postgres |
| 33 | +# options: >- |
| 34 | +# --health-cmd pg_isready |
| 35 | +# --health-interval 10s |
| 36 | +# --health-timeout 5s |
| 37 | +# --health-retries 5 |
| 38 | + |
| 39 | + runs-on: ubuntu-latest |
| 40 | + name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} |
| 41 | + strategy: |
| 42 | + # Specify the OTP and Elixir versions to use when building |
| 43 | + # and running the workflow steps. |
| 44 | + matrix: |
| 45 | + otp: ['27.3.3'] # Define the OTP version [required] |
| 46 | + elixir: ['1.18.3'] # Define the elixir version [required] |
| 47 | + steps: |
| 48 | + # Step: Setup Elixir + Erlang image as the base. |
| 49 | + - name: Set up Elixir |
| 50 | + uses: erlef/setup-beam@v1 |
| 51 | + with: |
| 52 | + otp-version: ${{matrix.otp}} |
| 53 | + elixir-version: ${{matrix.elixir}} |
| 54 | + |
| 55 | + # Step: Check out the code. |
| 56 | + - name: Checkout code |
| 57 | + uses: actions/checkout@v3 |
| 58 | + |
| 59 | + # Step: Define how to cache deps. Restores existing cache if present. |
| 60 | + - name: Cache deps |
| 61 | + id: cache-deps |
| 62 | + uses: actions/cache@v3 |
| 63 | + env: |
| 64 | + cache-name: cache-elixir-deps |
| 65 | + with: |
| 66 | + path: deps |
| 67 | + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} |
| 68 | + restore-keys: | |
| 69 | + ${{ runner.os }}-mix-${{ env.cache-name }}- |
| 70 | +
|
| 71 | + # Step: Define how to cache the `_build` directory. After the first run, |
| 72 | + # this speeds up tests runs a lot. This includes not re-compiling our |
| 73 | + # project's downloaded deps every run. |
| 74 | + - name: Cache compiled build |
| 75 | + id: cache-build |
| 76 | + uses: actions/cache@v3 |
| 77 | + env: |
| 78 | + cache-name: cache-compiled-build |
| 79 | + with: |
| 80 | + path: _build |
| 81 | + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} |
| 82 | + restore-keys: | |
| 83 | + ${{ runner.os }}-mix-${{ env.cache-name }}- |
| 84 | + ${{ runner.os }}-mix- |
| 85 | +
|
| 86 | + # Step: Cache dev build for Dialyzer |
| 87 | + - name: Cache dev build |
| 88 | + id: cache-dev-build |
| 89 | + uses: actions/cache@v3 |
| 90 | + env: |
| 91 | + cache-name: cache-dev-build |
| 92 | + with: |
| 93 | + path: _build/dev |
| 94 | + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} |
| 95 | + restore-keys: | |
| 96 | + ${{ runner.os }}-mix-${{ env.cache-name }}- |
| 97 | +
|
| 98 | + # Step: Conditionally bust the cache when job is re-run. |
| 99 | + # Sometimes, we may have issues with incremental builds that are fixed by |
| 100 | + # doing a full recompile. In order to not waste dev time on such trivial |
| 101 | + # issues (while also reaping the time savings of incremental builds for |
| 102 | + # *most* day-to-day development), force a full recompile only on builds |
| 103 | + # that are retried. |
| 104 | + - name: Clean to rule out incremental build as a source of flakiness |
| 105 | + if: github.run_attempt != '1' |
| 106 | + run: | |
| 107 | + mix deps.clean --all |
| 108 | + mix clean |
| 109 | + shell: sh |
| 110 | + |
| 111 | + # Step: Download project dependencies. If unchanged, uses |
| 112 | + # the cached version. |
| 113 | + - name: Install dependencies |
| 114 | + run: mix deps.get |
| 115 | + |
| 116 | + # Step: Compile the project treating any warnings as errors. |
| 117 | + # Customize this step if a different behavior is desired. |
| 118 | + - name: Compiles without warnings |
| 119 | + run: mix compile --warnings-as-errors |
| 120 | + |
| 121 | + # Step: Check that the checked in code has already been formatted. |
| 122 | + # This step fails if something was found unformatted. |
| 123 | + # Customize this step as desired. |
| 124 | + - name: Check Formatting |
| 125 | + run: mix format --check-formatted |
| 126 | + |
| 127 | + # Step: Cache PLT files for Dialyzer |
| 128 | + - name: Cache PLT |
| 129 | + uses: actions/cache@v3 |
| 130 | + env: |
| 131 | + cache-name: cache-plt |
| 132 | + with: |
| 133 | + path: priv/plts |
| 134 | + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt-dev-${{ hashFiles('**/mix.lock') }} |
| 135 | + restore-keys: | |
| 136 | + ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt-dev- |
| 137 | + ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plt- |
| 138 | +
|
| 139 | + # Step: Run Dialyzer for static analysis |
| 140 | + - name: Compile for Dialyzer |
| 141 | + env: |
| 142 | + MIX_ENV: dev |
| 143 | + run: mix compile |
| 144 | + |
| 145 | + - name: Run Dialyzer |
| 146 | + env: |
| 147 | + MIX_ENV: dev |
| 148 | + run: mix dialyzer |
| 149 | + |
| 150 | + # Step: Execute the tests. |
| 151 | + - name: Run tests |
| 152 | + run: mix test |
0 commit comments