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

Overview

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 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: 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

Comments
  • Run dartanalyzer directly

    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.

    enhancement 
    opened by klavs 14
  • Request for workaround for cross-fork reporter issue

    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.

    enhancement 
    opened by GroovinChip 12
  • Can't load Kernel binary: Invalid SDK hash.

    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.

    opened by creativecreatorormaybenot 11
  • "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

    opened by dkrutskikh 9
  • Use custom Git credentials

    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!

    opened by llucax 9
  • Change in the example if scores are not 100

    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!

    opened by leoafarias 8
  • Can't load Kernel binary: Invalid kernel binary format version. No active package pana.

    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/checkout@v2
          - uses: axel-op/dart-package-analyzer@v3
            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

    opened by marandaneto 7
  • Pana analysis suddenly failing

    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.

    opened by shamblett 7
  • MacOS support

    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/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 < 80 )) then echo Score too low! exit 1 fi

    opened by dacianf 6
  • Using custom Flutter channel (beta, master, dev)

    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/checkout@v2
    
          - uses: axel-op/dart-package-analyzer@stable
            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?

    opened by Dogacel 6
  • Error code 65 - Can't load Kernel binary: Invalid kernel binary format version.

    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
    
    opened by themisir 5
  • No report on pull requests from forks

    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.

    opened by axel-op 7
Releases(v3)
Owner
Axel Ogereau-Peltier
I'm a fan of statically typed languages like Dart and Java, but I often end up coding in Python or JavaScript.
Axel Ogereau-Peltier
An app to explore and bookmark packages hosted on pub.dev.

pub.dev explorer An app to explore and bookmark packages hosted on pub.dev. Web App Packages are shown in descending order starting from the most rece

Kabo 2 Nov 11, 2022
Github-search - Allows users to search users on github Uses flutter

Github Search Github Search is a cross-platform mobile application powered by Flutter Framework and Github API. The application was built with simplic

Saul 3 Sep 13, 2022
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.

Irvan Lutfi Gunawan 18 Apr 14, 2022
This package helps developer to sort the flutter/dart packages and plugins alphabetically, This makes it easier when managing too many packages and when working with teams

Package helps to sort the flutter/dart packages and plugins alphabetically, This makes it easier when managing too many packages and when working with

DANCHE 7 Dec 21, 2022
Text analyzer that extracts tokens from text for use in full-text search queries and indexes.

Tokenize text, compute document readbility and compare terms in Natural Language Processing. THIS PACKAGE IS PRE-RELEASE, and SUBJECT TO DAILY BREAKIN

GM Consult Pty Ltd 5 Dec 12, 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

dartside.dev 6 Nov 10, 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

Iandi Santulus 30 Nov 11, 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

Isaque Santos Paixão 0 Jan 7, 2022
Sport-pluse - A live score and blogging flutter mobile app

sport-pluse A live score and blogging flutter mobile app

Marshal Greatness 0 Jan 1, 2022
Flutter agenda - Flutter Agenda View Package (pub.dev)

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

Iliyass Zamouri 3 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

null 3 May 22, 2022
Helper pub package for flutter_icons

flutter_icons_helper An helper implementing utility methods for package flutter_

Nicolò Sonnino 3 Jun 22, 2022
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

Mohammad Rahmani 110 Dec 23, 2022
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

Naman Shergill 401 Jan 4, 2023
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

WenJingRui 261 Jan 7, 2023
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

Mariano Cordoba 198 Jan 5, 2023
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

MindInventory 11 Oct 10, 2022
Floating Action Button Widget For Flutter

Flutter Tutorial - FloatingActionButton Widget (FAB) Embed the FloatingActionBut

Behruz Hurramov 0 Dec 27, 2021
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

null 17 Sep 16, 2022