Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

Dart Package Analyzer to compute the Pub score of Dart/Flutter packages

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:

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

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 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).

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

Dart/Flutter package analyzer source code on GitHub

https://github.com/axel-op/dart-package-analyzer
Exit mobile version