This action gets the output of mix test --cover
, treats it, and creates a feedback message in the pull request of origin. It also checks if the coverage reaches the minimum configured in the action, and exits with an error if it doesn't.
Additionally, this action supports setting a working_directory
as an input if your Elixir project is not at the root of the repository.
.github/workflows/test.yml
on:
pull_request:
push:
branches:
- main
jobs:
test:
name: Tests & Checks
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
env:
MIX_ENV: test
services:
db:
image: postgres:15-alpine
ports: ["5432:5432"]
env:
POSTGRES_DB: project_test
POSTGRES_USER: project
POSTGRES_PASSWORD: mycoolpassword
steps:
- uses: actions/checkout@v4
- name: Setup Erlang and Elixir
uses: erlef/setup-beam@v1.17
with:
elixir-version: "1.16.0-otp-26"
otp-version: "26.0"
- name: Mix and build cache
uses: actions/cache@v4
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Get dependencies
run: mix deps.get
- name: Code analyzers
run: |
mix format --check-formatted
mix compile --warnings-as-errors
- name: Tests & Coverage
uses: josecfreittas/elixir-coverage-feedback-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
coverage_threshold: 80
# working_directory: ./your_project_directory