|
| 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: |
| 10 | + - main |
| 11 | + pull_request: |
| 12 | + branches: |
| 13 | + - main |
| 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: ['25.0.4'] # Define the OTP version [required] |
| 46 | + elixir: ['1.14.1'] # 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: Download project dependencies. If unchanged, uses |
| 87 | + # the cached version. |
| 88 | + - name: Install dependencies |
| 89 | + run: mix deps.get |
| 90 | + |
| 91 | + # Step: Compile the project treating any warnings as errors. |
| 92 | + # Customize this step if a different behavior is desired. |
| 93 | + - name: Compiles without warnings |
| 94 | + run: mix compile --warnings-as-errors |
| 95 | + |
| 96 | + # Step: Check that the checked in code has already been formatted. |
| 97 | + # This step fails if something was found unformatted. |
| 98 | + # Customize this step as desired. |
| 99 | + - name: Check Formatting |
| 100 | + run: mix format --check-formatted |
| 101 | + |
| 102 | + # Step: Execute the tests. |
| 103 | + - name: Run tests |
| 104 | + run: mix test |
| 105 | + |
0 commit comments