2022-10-10
GithubTestsContinous integration

Setup Github Actions

The SAAS Starter Kit comes with Github action from the start. That means that there are already a file in the boilerplate that will run tests on Github as soon as your project is pushed.

This provides a very easy way to setup and get started with a continuous integration and continuous delivery (CI/CD) process that allows you to automate your build, test, and deployment pipeline.

Github will pick up the actions that is stored as YML files in a specific folder structure:

.github/workflows/ci.yml

The name of the file is arbitrary and doesnt matter. You can have several. However, the folder structure is required.

Env Variables

You can set any ENV variables here that are required for tests to run. The only thing required from the start is to set MIX_ENV to test. Otherwise you might end up with unexpected behaviour.

env:
  MIX_ENV: test

Configure versions

This part sets up the versions that you run the test suit on. The versions you can specify are Elixir, OTP and Postgres. Make sure that you stay close to the versions you run both in development but especially in production.

jobs:
  deps:
    name: Dependencies
    runs-on: ubuntu-18.04
    strategy:
      matrix:
        elixir: [1.13]
        otp: [24.1]

    services:
      db:
        image: postgres:13
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: my_app_test
        ports: ["5432:5432"]
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

Run commands

Last in the file there are the actual elixir commands that is run. Note that --warnings-as-errors is set during compile. That means that the test will

- name: Install Dependencies
  run: |
    mix local.rebar --force
    mix local.hex --force
    mix deps.get
    mix deps.compile --warnings-as-errors
    mix credo diff --from-git-merge-base origin/main
    mix test

Deployment

What is not in the file from the start, is setting up deployment. That depends on your deployment setup and is very individual to each project.