|
| 1 | +name: Elixir CI |
| 2 | + |
| 3 | +# Define workflow that runs when changes are pushed to the |
| 4 | +# `main` branch or pushed to a PR branch that targets the `main` |
| 5 | +# branch. Change the branch name if your project uses a |
| 6 | +# different name for the main branch like "master" or "production". |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: [ "main" ] # adapt branch for project |
| 10 | + pull_request: |
| 11 | + branches: [ "main" ] # adapt branch for project |
| 12 | + |
| 13 | +# Sets the ENV `MIX_ENV` to `test` for running tests |
| 14 | +env: |
| 15 | + MIX_ENV: test |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +jobs: |
| 21 | + test: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} |
| 24 | + strategy: |
| 25 | + # Specify the OTP and Elixir versions to use when building |
| 26 | + # and running the workflow steps. |
| 27 | + matrix: |
| 28 | + otp: ['25.0.4'] # Define the OTP version [required] |
| 29 | + elixir: ['1.14.1'] # Define the elixir version [required] |
| 30 | + steps: |
| 31 | + # Step: Setup Elixir + Erlang image as the base. |
| 32 | + - name: Set up Elixir |
| 33 | + uses: erlef/setup-beam@v1 |
| 34 | + with: |
| 35 | + otp-version: ${{matrix.otp}} |
| 36 | + elixir-version: ${{matrix.elixir}} |
| 37 | + |
| 38 | + # Step: Check out the code. |
| 39 | + - name: Checkout code |
| 40 | + uses: actions/checkout@v3 |
| 41 | + |
| 42 | + # Step: Define how to cache deps. Restores existing cache if present. |
| 43 | + - name: Cache deps |
| 44 | + id: cache-deps |
| 45 | + uses: actions/cache@v3 |
| 46 | + env: |
| 47 | + cache-name: cache-elixir-deps |
| 48 | + with: |
| 49 | + path: deps |
| 50 | + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} |
| 51 | + restore-keys: | |
| 52 | + ${{ runner.os }}-mix-${{ env.cache-name }}- |
| 53 | +
|
| 54 | + # Step: Define how to cache the `_build` directory. After the first run, |
| 55 | + # this speeds up tests runs a lot. This includes not re-compiling our |
| 56 | + # project's downloaded deps every run. |
| 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 | + # Step: Download project dependencies. If unchanged, uses |
| 70 | + # the cached version. |
| 71 | + - name: Install dependencies |
| 72 | + run: mix deps.get |
| 73 | + |
| 74 | + # Step: Compile the project treating any warnings as errors. |
| 75 | + # Customize this step if a different behavior is desired. |
| 76 | + - name: Compiles without warnings |
| 77 | + run: mix compile --warnings-as-errors |
| 78 | + |
| 79 | + # Step: Check that the checked in code has already been formatted. |
| 80 | + # This step fails if something was found unformatted. |
| 81 | + # Customize this step as desired. |
| 82 | + - name: Check Formatting |
| 83 | + run: mix format --check-formatted |
| 84 | + |
| 85 | + # Step: Execute the tests. |
| 86 | + - name: Run tests |
| 87 | + run: mix test |
0 commit comments