Skip to content

Latest commit

 

History

History
127 lines (88 loc) · 4.47 KB

README.md

File metadata and controls

127 lines (88 loc) · 4.47 KB

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

  • flutter_version
    The version of Flutter to use. If not set, version 3.13.9 will be used.
  • flutter_channel The channel of Flutter to use. If not set, the stable channel will be used.
  • 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: flutterings/dart-package-analyzer@v1
        with:
          # Optional:
          flutter_version: 3.16.0 # default: 3.13.9
          # Optional:
          flutter_channel: dev # default: stable
          # Optional:
          relativePath: packages/mypackage/

Outputs

There is an output for each of the six 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.

There is also an output containing the full pana output in JSON format if you need to parse it yourself.

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.

  • null_safety & null_safety_max
    Score for the category Support null-safety.

  • json_output The pana output in JSON format.

Usage example

name: Example workflow
on: [push, pull_request]

jobs:

  package-analysis:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - uses: flutterings/dart-package-analyzer@v1
        # set an id for the current step
        id: analysis

      # 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