Giter Site home page Giter Site logo

elixir_run_tests_action's Introduction

Elixir Test Github Action

This github action will run tests using the official Elixir 1.10 docker container. If the project is an umbrella app, it will cd into all of the apps and run all of the tests in each app, even if the tests in one of the apps fails. This means you will be able to see all of the test failures in one go, avoiding the need for multiple runs.

We:

  • Set MIX_ENV=test
  • mix deps.get
  • mix deps.compile --force
  • mix compile --force --warnings-as-errors
  • Run mix test.ci

Adding the mix task

NOTE this action runs a mix task called mix test.ci so you need to add that alias in your mix.exs. This allows you to add flags to the test command, or setup the database etc.

  defp aliases do
    [
      ...
      "test.ci": ["test --color --max-cases=10"],
      ...
    ]
end

In an umbrella you should define a command in each app, they can do different things if you wish.

You may also want to set the preferred CLI env for the task alias. When this action runs the mix env is automatically set and so everything is fine, but if you add a mix test.ci command and try to run that locally it will by default be in the :dev env, which is not what you want for test running. So you can either do this: MIX_ENV=test mix test.ci or set this in the project in the mix.exs

def project do
  [
    ...
    preferred_cli_env: ["test.ci": :test],
    ...
  ]
end

Example usage

In a simple library (no database)

Add this to your mix.exs

  defp aliases do
    [
      ...
      "test.ci": ["test --color --max-cases=10"],
      ...
    ]
end

Add a .github/workflows/main.yaml file to the root of the project you want to include it in then inside that you can configure like so:

On the open of a pull request

on: [pull_request]

jobs:
  run_tests:
    runs-on: ubuntu-latest
    steps:
    # This is an action from github that checks out the code in the repo.
    - uses: actions/checkout@v2
    # Give it any name you like
    - name: "run dem tests"
      uses: Adzz/[email protected]

On push

on: [push]

jobs:
  run_tests:
    runs-on: ubuntu-latest
    steps:
    # This is an action from github that checks out the code in the repo.
    - uses: actions/checkout@v2
    # Give it any name you like
    - name: "run dem tests"
      uses: Adzz/[email protected]

App with a database

Add this to the relevant mix.exs

  defp aliases do
    [
      ...
      "test.ci": ["ecto.drop", "ecto.create --quiet", "ecto.migrate", "test"],
      ...
    ]
end

Or if you have a seeds file:

  defp aliases do
    [
      ...
      "test.ci": ["ecto.drop", "ecto.create --quiet", "ecto.migrate", "run priv/repo/seeds.exs", "test"],
      ...
    ]
end

On the open of a pull request

on: [pull_request]

jobs:
  run_tests:
    runs-on: ubuntu-latest
    steps:
    # This is an action from github that checks out the code in the repo.
    - uses: actions/checkout@v2
    # Give it any name you like
    - name: "run dem tests"
      uses: Adzz/[email protected]

On push

on: [push]

jobs:
  run_tests:
    runs-on: ubuntu-latest
    steps:
    # This is an action from github that checks out the code in the repo.
    - uses: actions/checkout@v2
    # Give it any name you like
    - name: "run dem tests"
      uses: Adzz/[email protected]

More info available in the workflow docs

elixir_run_tests_action's People

Contributors

adzz avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.