GitHub Action that uses the Dart Package Analyzer to compute the Pub score of Dart/Flutter packages

Last update: May 17, 2022

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/[email protected] # required

      - uses: axel-op/[email protected]
        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).

  • 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/[email protected]

      - uses: axel-op/[email protected]
        # 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

GitHub

https://github.com/axel-op/dart-package-analyzer
Comments
  • 1. Run dartanalyzer directly

    Background Pana is currently ignoring package's own analysis_options.yaml, instead using pedantic. pedantic:1.9.0 has introduced some controversial rules.

    Proposal In addition to running pana, which gives a good feel of how the package will look if published, also run dartanalyzer to give feedback on conformance to package's own rules even if a package not supposed to be published.

    Reviewed by klavs at 2020-02-09 10:09
  • 2. Request for workaround for cross-fork reporter issue

    As seen in #2, when running this action on cross-fork PR's, the job succeeds but is not able to publish a formatted report due to security issues. As a workaround, perhaps the relevant logs from the job output itself could be captured and published either as a formatted report or a downloadable job artifact?

    Filed separately from #2 per request.

    Reviewed by GroovinChip at 2021-04-19 20:18
  • 3. Can't load Kernel binary: Invalid SDK hash.

    First of, so much love maintaining this action @axel-op ❤️


    Using v3, the action fails immediately with:

    Running pana
      Can't load Kernel binary: Invalid SDK hash.
      No active package pana.
    Error: Pana exited with code 65
    

    See https://github.com/creativecreatorormaybenot/wakelock/pull/137/checks?check_run_id=3564162097 for example.

    Reviewed by creativecreatorormaybenot at 2021-09-10 05:53
  • 4. "Invalid argument(s): Provided content does not align with expectations"

    Last five days dart-package-analyzer crashes on every run.

    https://github.com/dart-code-checker/dart-code-metrics/runs/2168640802

    2021-03-22T17:54:25.2056965Z ##[group]Running pana 2021-03-22T17:54:25.5128260Z {"logName":"pana","level":"INFO","message":"Running /flutter/bin/cache/dart-sdk/bin/dart --version..."} 2021-03-22T17:54:25.5715632Z {"logName":"pana","level":"INFO","message":"Running flutter --no-version-check --version --machine..."} 2021-03-22T17:54:26.3455792Z {"logName":"pana","level":"INFO","message":"Running /flutter/bin/cache/dart-sdk/bin/pub upgrade --verbosity io --no-precompile..."} 2021-03-22T17:54:29.9193345Z {"logName":"pana","level":"INFO","message":"Analyzing package..."} 2021-03-22T17:54:29.9696760Z {"logName":"pana","level":"INFO","message":"Running /flutter/bin/cache/dart-sdk/bin/dartanalyzer --options /github/workspace/pana_analysis_options_1616435669958881.g.yaml --format machine bin lib..."} 2021-03-22T17:54:42.7434141Z {"level":"SHOUT","message":"Problem analyzing /github/workspace","error":"Invalid argument(s): Provided content does not align with expectations.\nNo dart files found at: /github/workspace/lib","stackTrace":"#0 parseCodeProblem (package:pana/src/code_problem.dart:52:5)\n#1 PackageContext.staticAnalysis. (package:pana/src/package_context.dart:121:23)\n#2 MappedIterator.moveNext (dart:_internal/iterable.dart:390:20)\n#3 WhereIterator.moveNext (dart:_internal/iterable.dart:436:22)\n#4 SetMixin.addAll (dart:collection/set.dart:57:23)\n#5 new LinkedHashSet.of (dart:collection/linked_hash_set.dart:111:27)\n#6 Iterable.toSet (dart:core/iterable.dart:376:21)\n#7 PackageContext.staticAnalysis (package:pana/src/package_context.dart:123:12)\n\n#8 PackageAnalyzer._inspect (package:pana/src/package_analyzer.dart:147:27)\n\n#9 main (file:///root/.pub-cache/hosted/pub.dartlang.org/pana-0.15.4/bin/pana.dart:163:19)\n\n"} 2021-03-22T17:54:42.8798897Z ##[endgroup] 2021-03-22T17:54:42.8803460Z ##[error]Pana exited with code 1

    Reviewed by dkrutskikh at 2021-03-23 06:10
  • 5. Use custom Git credentials

    Hi, I know this is probably not the most common use case ever, but I guess it shouldn't be hard to implement. I don't know how custom github actions work, otherwise I could have give it a shot myself.

    I'm basically defining my custom git config --global credential.helper to send credentials to git to be able to use some private repos as dependencies. This works just fine when building but with the action using this analyzer, I get an error when it runs pub get complaining that the private repos don't exist. I see it uses docker to run the stuff, so I guess the $HOME directory is not mapped inside the container, so the ~/.gitconfig file is not available inside the container. I even try without the --global, because I guess the source code should be mapped inside the container, but it doesn't work either, not sure if not all the code in the repo is present.

    Anyway, if you add support to be able to do this, it will be much appreciated. Thanks for the great action!

    Reviewed by llucax at 2020-10-23 13:56
  • 6. Change in the example if scores are not 100

    During my use it seems that the step to fail if scores were not 100 was not working properly. I made an adjustment which is working as expected. Great action by the way. Thanks!

    Reviewed by leoafarias at 2020-07-17 21:18
  • 7. Can't load Kernel binary: Invalid kernel binary format version. No active package pana.

    Hey, I'm getting this error since today:

    Running pana Can't load Kernel binary: Invalid kernel binary format version. No active package pana. Error: Pana exited with code 65

    The script is as simple as that:

      package-analysis:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/[email protected]
          - uses: axel-op/[email protected]
            id: analysis
            with:
              githubToken: ${{ secrets.GITHUB_TOKEN }}
              relativePath: dart/
          - name: Check scores
            env:
              TOTAL: ${{ steps.analysis.outputs.total }}
              TOTAL_MAX: ${{ steps.analysis.outputs.total_max }}
            run: |
              PERCENTAGE=$(( $TOTAL * 100 / $TOTAL_MAX ))
              if (( $PERCENTAGE < 100 ))
              then
                echo Score too low!
                exit 1
              fi
    

    it was working normally, not sure if the ubuntu-latest or something else changed.

    PR with the error is here: https://github.com/getsentry/sentry-dart/pull/245/checks?check_run_id=1564311109

    Reviewed by marandaneto at 2020-12-16 15:09
  • 8. Pana analysis suddenly failing

    I'm getting strange SDK errors in my pana analysis, please see this action log. from what I can see this started to happen when pana move up form 0.13.8-dev although this may not be the cause, also I'm not sure what the 'github#L1' errors mean.

    Reviewed by shamblett at 2020-06-23 07:36
  • 9. MacOS support

    Hey @axel-op , I've tried to use this action on a macOS runner and it fails with ##[error]Container action is only supported on Linux. Do I make something wrong? Can you make it run on macOS too, I supposed it should work since MacOS is a Unix based OS? I've tried it with your example: - uses: axel-op/[email protected] # 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 < 80 )) then echo Score too low! exit 1 fi

    Reviewed by dacianf at 2020-09-03 07:09
  • 10. Using custom Flutter channel (beta, master, dev)

    I am trying to use dart-package-analyzer in github actions with a beta version of flutter but I am getting the following issue:

    Issues

    General

    • Fix dependencies in pubspec.yaml Running flutter pub upgrade failed with the following output:
      • ERR: The current Flutter SDK version is 1.12.13+hotfix.9.
      • Because boo_app requires Flutter SDK version ^1.17.0, version solving failed.

    and I also get

    • No valid SDK 20.0 points The analysis could not detect a valid SDK that can use this package.

    and this is my workflow file

    jobs:
      package-analysis:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/[email protected]
    
          - uses: axel-op/[email protected]
            id: analysis # set an id for the current step
            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 a score is below 100:
          - name: Check scores
            # NB: "analysis" is the id set above. Replace it with the one you used if different.
            run: |
              MAINTENANCE_SCORE=${{ steps.analysis.outputs.maintenance }}
              HEALTH_SCORE=${{ steps.analysis.outputs.health }}
              if (( $(echo "$MAINTENANCE_SCORE < 50" | bc) )) || (( $(echo "$HEALTH_SCORE < 50" | bc) ))
              then
                echo "Scores are less than 50"
                exit 1
              fi
    

    This is not much different from the default version. Can you help me with this?

    Reviewed by Dogacel at 2020-04-27 11:22
  • 11. Error code 65 - Can't load Kernel binary: Invalid kernel binary format version.

    The action fails with exit code 65. Here's action logs: https://github.com/hivedb/hive/runs/1798886741

    2021-01-30T21:49:16.8480259Z Analytics reporting disabled.
    2021-01-30T21:49:16.8486736Z 
    2021-01-30T21:49:16.8487437Z You may need to restart any open editors for them to read new settings.
    2021-01-30T21:49:16.8776796Z ##[endgroup]
    2021-01-30T21:49:17.1121542Z ##[group]Running pana
    2021-01-30T21:49:17.1840827Z Can't load Kernel binary: Invalid kernel binary format version.
    2021-01-30T21:49:17.3124500Z No active package pana.
    2021-01-30T21:49:17.3539451Z ##[endgroup]
    2021-01-30T21:49:17.3544364Z ##[error]Pana exited with code 65
    2021-01-30T21:49:32.8081063Z Cleaning up orphan processes
    
    Reviewed by themisir at 2021-01-30 21:53
  • 12. No report on pull requests from forks

    Description

    When the action is triggered by the pull_request event, if the pull request is from a different repository (a fork), the action fails with the error "Resource not accessible by integration".

    EDIT: this behavior has changed. See the comment below.

    Why is this happening

    This action uses the GITHUB_TOKEN you provide to call the GitHub API and to post the result of its analysis. As explained here, here, or here, GitHub for now reduces the permissions of this token when the action is triggered by another repository. Therefore an error is thrown when this action tries to call the API in this situation.

    Permissions for the GITHUB_TOKEN

    Current workaround

    A possible workaround is to edit your workflow to trigger this action only when pull requests come from the same repository. This can be done by adding an if-condition, as illustrated below:

    name: Example workflow
    on: [push, pull_request]
    
    jobs:
    
      package-analysis:
        if: github.event_name != 'pull_request' || github.actor == '[username]' # Replace [username] by the username of your repo
        runs-on: ubuntu-latest
        steps:
          - ...
    

    I will update this issue if there is new information on this.

    Reviewed by axel-op at 2020-01-09 15:30

Related

Github-apps-flutter - Github Apps Build Using bloc 8.0 and Github API
Github-apps-flutter - Github Apps Build Using bloc 8.0 and Github API

Github_apps Inspiration This app is made to build using bloc 8.0 and github API.

Apr 14, 2022
Teach you some of the popular sensor controlling packages that are available in pub.dev
Teach you some of the popular sensor controlling packages that are available in pub.dev

Sensor Packages Introduction to sensor packages: This repo will teach you some of the popular sensor controlling packages that are available in pub.de

Jul 16, 2022
Flutter's compute function made available for all non-Flutter Dart programs

compute Flutter's compute function made available for all non-Flutter Dart programs The compute package takes Flutter's compute function and makes it

Mar 31, 2022
An isolated worker for Flutter (Isolate) and Web (Web Worker). Behaves almost the same as the compute function, except it is not a one-off worker.

A singleton isolated worker for all platforms. On most platforms, it uses Flutter's Isolate, except on the web, since Isolate is not available, it use

Aug 8, 2022
App de teste que executa uma função de fibonacci em background utilizando compute.

app_isolate_compute A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you star

Jan 7, 2022
Sport-pluse - A live score and blogging flutter mobile app
Sport-pluse - A live score and blogging flutter mobile app

sport-pluse A live score and blogging flutter mobile app

Jan 1, 2022
A flutter UI package provides a cell widget that has leading and trailing swipe action menu.
A flutter UI package provides a cell widget that has leading and trailing swipe action menu.

Language: English |中文简体 flutter_swipe_action_cell A package that can give you a cell that can be swiped ,effect is like iOS native If you like this pa

Aug 11, 2022
A Flutter package to create a nice circular menu using a Floating Action Button.
A Flutter package to create a nice circular menu using a Floating Action Button.

FAB Circular Menu A Flutter package to create a nice circular menu using a Floating Action Button. Inspired by Mayur Kshirsagar's great FAB Microinter

Jul 27, 2022
This package will animate a floating action button at the center and icons at the bottomNavigationBar using AnimatedContainer and SlideTransition respectively.
This package will animate a floating action button at the center and icons at the bottomNavigationBar using AnimatedContainer and SlideTransition respectively.

floating_bottom_bar This package will animate a floating action button at the center and icons at the bottomNavigationBar using AnimatedContainer and

Aug 11, 2022
Flutter Github Following Application, Using Flutter Provider and Flutter HTTP to get data from Github API.
Flutter Github Following Application, Using Flutter Provider and Flutter HTTP to get data from Github API.

Flutter Github Following Application Watch it on Youtube Previous Designs Checkout my Youtube channel Installation Please remember, after cloning this

Aug 10, 2022
An open-source unofficial GitHub mobile client, that aims to deliver the ultimate GitHub experience on mobile devices.
An open-source unofficial GitHub mobile client, that aims to deliver the ultimate GitHub experience on mobile devices.

DioHub for Github Summary Features Roadmap Support Screenshots Build Instructions Summary DioHub is an open-source unofficial GitHub mobile client, th

Jul 31, 2022
Flutter agenda - Flutter Agenda View Package (pub.dev)
Flutter agenda - Flutter Agenda View Package (pub.dev)

Flutter Agenda View Agenda Widget Package for Flutter Features Image Video Recor

Apr 15, 2022
package from pub.dev

posts A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this is

May 22, 2022
Helper pub package for flutter_icons

flutter_icons_helper An helper implementing utility methods for package flutter_

Jun 22, 2022
Floating Action Button Widget For Flutter
Floating Action Button Widget For Flutter

Flutter Tutorial - FloatingActionButton Widget (FAB) Embed the FloatingActionBut

Dec 27, 2021
A Contextual action bar workaround for flutter
A Contextual action bar workaround for flutter

Flutter contextual action bar(CAB) CAB & Flutter CAB is a top app bar that replace the application app bar to provide contextual actions to selected i

Jun 4, 2022
A action bottom sheet that adapts to the platform (Android/iOS).
A action bottom sheet that adapts to the platform (Android/iOS).

Adaptive action sheet A action bottom sheet that adapts to the platform (Android/iOS). iOS Android Getting Started Add the package to your pubspec.yam

Jul 18, 2022
Master Channel cannot use Glass Floating Action Button
Master Channel cannot use Glass Floating Action Button

Problem Master Channel cannot use GlassFloatingActionButton. About This package

Jan 21, 2022
Adaptive dialog - Show alert dialog or modal action sheet adaptively according to platform.
Adaptive dialog - Show alert dialog or modal action sheet adaptively according to platform.

adaptive_dialog Show alert dialog or modal action sheet adaptively according to platform. showOkAlertDialog Convenient wrapper of showAlertDialog. iOS

Aug 10, 2022