|
| 1 | +name: Linting & Tests |
| 2 | + |
| 3 | +# Define workflow that runs when changes are pushed to the |
| 4 | +# `master` branch or pushed to a PR branch that targets the `master` |
| 5 | +# branch. |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: [ "master" ] |
| 9 | + pull_request: |
| 10 | + branches: [ "master" ] |
| 11 | + |
| 12 | +# Sets the ENV `MIX_ENV` to `test` for running tests |
| 13 | +env: |
| 14 | + MIX_ENV: test |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +jobs: |
| 20 | + test: |
| 21 | + runs-on: ubuntu-22.04 |
| 22 | + name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} |
| 23 | + strategy: |
| 24 | + # Specify the OTP and Elixir versions to use when building |
| 25 | + # and running the workflow steps. |
| 26 | + matrix: |
| 27 | + otp: ['25.0.4', '27.2'] # Define the OTP version [required] |
| 28 | + elixir: ['1.14.1', '1.18.4'] # Define the elixir version [required] |
| 29 | + exclude: |
| 30 | + - otp: '27.2' |
| 31 | + elixir: '1.14.1' |
| 32 | + steps: |
| 33 | + # Step: Setup Elixir + Erlang image as the base. |
| 34 | + - name: Set up Elixir |
| 35 | + uses: erlef/setup-beam@v1 |
| 36 | + with: |
| 37 | + otp-version: ${{matrix.otp}} |
| 38 | + elixir-version: ${{matrix.elixir}} |
| 39 | + |
| 40 | + # Step: Check out the code. |
| 41 | + - name: Checkout code |
| 42 | + uses: actions/checkout@v4 |
| 43 | + |
| 44 | + # Step: Define how to cache deps. Restores existing cache if present. |
| 45 | + - name: Cache deps |
| 46 | + id: cache-deps |
| 47 | + uses: actions/cache@v4 |
| 48 | + env: |
| 49 | + cache-name: cache-elixir-deps |
| 50 | + with: |
| 51 | + path: deps |
| 52 | + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} |
| 53 | + restore-keys: | |
| 54 | + ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ env.cache-name }} |
| 55 | +
|
| 56 | + # Step: Define how to cache the `_build` directory. After the first run, |
| 57 | + # this speeds up test runs. This includes not re-compiling our deps every run. |
| 58 | + - name: Cache compiled build |
| 59 | + id: cache-build |
| 60 | + uses: actions/cache@v4 |
| 61 | + env: |
| 62 | + cache-name: cache-compiled-build |
| 63 | + with: |
| 64 | + path: _build |
| 65 | + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} |
| 66 | + restore-keys: | |
| 67 | + ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ env.cache-name }}- |
| 68 | + ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix- |
| 69 | +
|
| 70 | + # Step: Conditionally bust the cache when job is re-run. |
| 71 | + # Sometimes, we may have issues with incremental builds that are fixed by |
| 72 | + # doing a full recompile. In order to not waste dev time on such trivial |
| 73 | + # issues (while also reaping the time savings of incremental builds for |
| 74 | + # *most* day-to-day development), force a full recompile only on builds |
| 75 | + # that are retried. |
| 76 | + - name: Clean to rule out incremental build as a source of flakiness |
| 77 | + if: github.run_attempt != '1' |
| 78 | + run: | |
| 79 | + mix deps.clean --all |
| 80 | + mix clean |
| 81 | + shell: sh |
| 82 | + |
| 83 | + # Step: Download project dependencies. If unchanged, uses |
| 84 | + # the cached version. |
| 85 | + - name: Install dependencies |
| 86 | + run: mix deps.get |
| 87 | + |
| 88 | + # Step: Compile the project treating any warnings as errors. |
| 89 | + # Customize this step if a different behavior is desired. |
| 90 | + - name: Compiles without warnings |
| 91 | + run: mix compile --warnings-as-errors |
| 92 | + |
| 93 | + # Step: Check that the checked in code has already been formatted. |
| 94 | + # This step fails if something was found unformatted. |
| 95 | + # Customize this step as desired. |
| 96 | + - name: Check Formatting |
| 97 | + run: mix format --check-formatted |
| 98 | + |
| 99 | + # Step: Execute the tests. |
| 100 | + - name: Run tests |
| 101 | + run: mix test |
0 commit comments