Skip to content
message-square

GitHub Action

Elixir Coverage

v1.1.0 Latest version

Elixir Coverage

message-square

Elixir Coverage

Action to run tests, check coverage, and send a feedback message to the pull request

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Elixir Coverage

uses: josecfreittas/elixir-coverage-feedback-action@v1.1.0

Learn more about this action in josecfreittas/elixir-coverage-feedback-action

Choose a version

Elixir coverage feedback comment

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.

image image

Inputs

The action accepts the following inputs:

  • github_token (required): GitHub token to be able to create/edit comments on PRs.
  • coverage_threshold (optional): Coverage threshold percentage. Default is 90.
  • working_directory (optional): Working directory for the Elixir project. Default is the root directory (".").

Example of a complete test workflow using the action

.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