Skip to content
bar-chart

GitHub Action

Dart Coverage Assistant

v1.1 Latest version

Dart Coverage Assistant

bar-chart

Dart Coverage Assistant

Magically generates code coverage for all your dart projects

Installation

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

              

- name: Dart Coverage Assistant

uses: whynotmake-it/dart-coverage-assistant@v1.1

Learn more about this action in whynotmake-it/dart-coverage-assistant

Choose a version

Dart Coverage Assistant ๐ŸŽฏ๐Ÿงช

A no-brainer tool to generate coverage reports for your Dart projects. Plug and play, both for your existing CI, or in a new project.

Empowered by whynotmake.it License: MIT Test coverage

Features

๐Ÿ”Œ Plug and Play

  • No configuration needed, just add the action to your workflow
  • Automatically finds all projects in your repository
  • Doesn't run any tests by default, so it works with your existing CI
  • Can run tests for you (good if you have no CI yet)

๐Ÿ’ฌ Keep an eye on your coverage

  • Post a sticky comment on every PR
  • Updates automatically if you make changes
  • Shows coverage for every project in your repository
  • Can show differences between the current and the base branch

๐Ÿ‘ฎโ€โ™‚๏ธ Enforce rules

  • Choose between multiple rules:
    • Fail the action if total repo coverage drops below threshold
    • Fail the action if any single project coverage drops below threshold
    • Fail the action if total repo coverage decreases in PR
    • Fail the action if any single project coverage decreases in PR

๐Ÿ”ฐ Generate Badges

  • Show off your coverage in your README or on your website, without signing up to a third party service
  • Generate badges on push events
  • Can be configured to either push new badges to the current branch, or open a PR with them.

Get Started

Getting started with dart-coverage-assistant is easy. It works out of the box with your existing CI pipeline to give you the power of coverage reporting. If you don't have a CI yet, it can also run your tests for you.

For CI Aficionados

jobs:
  flutter-check:
    name: Build Check
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      # ---
      # Your existing steps...
      # ---
      - name: ๐Ÿ“Š Generate Coverage
        id: coverage-report
        uses: whynotmake-it/dart-coverage-assistant@v1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          lower_threshold: 50
          upper_threshold: 90
          generate_badges: pr

[!IMPORTANT] With this setup, this action will assume, that your projects have up-to-date coverage. This can be achieved by either running the tests like flutter test --coverage in the steps before this action, or always running them locally. Check the section below for more information about configuration options.

For CI Newbies

If you just want a drop-in CI pipeline, just copy the following into your .github/workflows/main.yml file. This will run your tests and generate a coverage report for you.

name: Continuous Integration

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  flutter-check:
    name: Build Check
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - name: ๐Ÿ“š Checkout
        uses: actions/checkout@v4

      - name: ๐Ÿฆ Setup Flutter
        uses: subosito/flutter-action@v2
        with:
          sdk: 'stable'

      - name: ๐Ÿ“Š Generate Coverage
        id: coverage-report
        uses: whynotmake-it/dart-coverage-assistant@v1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          testing_command: flutter test --coverage
          lower_threshold: 50
          upper_threshold: 90
          generate_badges: pr

Configuration

Below you will find a short list of all available configuration options, and what they do.

  • lower_threshold (optional, default: 0): The lower threshold for code coverage, anything below this is considered a failure.
  • upper_threshold (optional, default: 0): The threshold for the coverage to be considered 'good', anything below this is considered critical.
  • compare_against_base (optional, default: true): Whether to compare against the base when running in a PR.
  • enforce_threshold (optional, default: 'total'): Whether the action should fail if the coverage is below the lower threshold. Can be set to "none", "single", or "total".
  • enforce_forbidden_decrease (optional, default: 'none'): Whether the action should fail if the coverage decreases. Can be set to "none", "single", or "total".
  • generate_badges (optional, default: none): Whether to generate badges for the coverage on "push" workflow triggers. Can be set to "push" (push new badges, make sure your branch is not protected), "pr" (open a pull request with the changes, make sure you allow Actions to open PRs on your Repo), or "none" (no badge generation).

Honorable mentions

  • Big thanks to @JohannSchramm for his help and being an inspiration for this project.