Skip to content
feather

GitHub Action

Dart/Flutter Package Analyzer

v3 Latest version

Dart/Flutter Package Analyzer

feather

Dart/Flutter Package Analyzer

Performs static analysis, linting, formatting, to compute the Pub score of your Dart/Flutter package

Installation

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

              

- name: Dart/Flutter Package Analyzer

uses: axel-op/dart-package-analyzer@v3

Learn more about this action in axel-op/dart-package-analyzer

Choose a version

Dart/Flutter package analyzer

This action uses the pana (Package ANAlysis) package to compute the score that your Dart or Flutter package will have on the Pub site.

This package, amongst other things:

  • validates the code by performing static analysis with dartanalyzer,
  • checks code formatting with dartfmt or flutter format (detected automatically),
  • checks for outdated dependencies,
  • validates the pubspec.yaml file (dependencies, description's length...),
  • checks for required files (CHANGELOG, README, example folder...)
  • ...

The pana package gives scores in five categories and sum them up to get your total score.

Usage

You must include the actions/checkout step in your workflow. You don't need to run pub get or build a Dart container before.

This action uses its own Dart container. I recommend you to run it in a separate job, as jobs run in parallel.

Inputs

  • githubToken
    Required to post a report on GitHub. Note: the secret GITHUB_TOKEN is already provided by GitHub and you don't have to set it up yourself.
  • relativePath
    If your package isn't at the root of the repository, set this input to indicate its location.

Example:

name: Example workflow
on: [push, pull_request]

jobs:

  package-analysis:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2 # required

      - uses: axel-op/dart-package-analyzer@v3
        with:
          # Required:
          githubToken: ${{ secrets.GITHUB_TOKEN }}
          # Optional:
          relativePath: packages/mypackage/

Outputs

There is an output for each of the five categories that are evaluated by the pana package, whose value is the score obtained by your package, plus an output for the total score of your package.

For each of these outputs, there is also a ..._max output corresponding to the maximum score that a package can have in the category.

You can use the outputs in the next steps of your workfow by associating an id to this action. In the following steps, you can retrieve an output with ${{ steps.the_id.outputs.name_of_output }} (see the example below).

  • total & total_max
    The total score of your package, and the maximum score that it can get.

  • conventions & conventions_max
    Score for the category Follow Dart file conventions.

  • documentation & documentation_max
    Score for the category Provide documentation.

  • platforms & platforms_max
    Score for the category Support multiple platforms.

  • analysis & analysis_max
    Score for the category Pass static analysis.

  • dependencies & dependencies_max
    Score for the category Support up-to-date dependencies.

Usage example

name: Example workflow
on: [push, pull_request]

jobs:

  package-analysis:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - uses: axel-op/dart-package-analyzer@v3
        # set an id for the current step
        id: analysis
        with:
          githubToken: ${{ secrets.GITHUB_TOKEN }}

      # You can then use this id to retrieve the outputs in the next steps.
      # The following step shows how to exit the workflow with an error if the total score in percentage is below 50:
      - name: Check scores
        env:
          # NB: "analysis" is the id set above. Replace it with the one you used if different.
          TOTAL: ${{ steps.analysis.outputs.total }}
          TOTAL_MAX: ${{ steps.analysis.outputs.total_max }}
        run: |
          PERCENTAGE=$(( $TOTAL * 100 / $TOTAL_MAX ))
          if (( $PERCENTAGE < 50 ))
          then
            echo Score too low!
            exit 1
          fi

Example

Example report