Skip to content

yorifuji/flutter-analyze-commenter

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flutter Analyze Commenter

Flutter Analyze Commenter is a GitHub Action that posts comments on pull requests with results from both flutter analyze and dart run custom_lint.


Potential issues not included in your pull request, or changes in differences due to updates to the base branch, will be displayed as a summary in the following way:

Usage

Example workflow

name: flutter-analyze-commenter example

on: pull_request  # Only supports run by pull request

jobs:
  flutter-analyze:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write # Write permission is required to add comments on a PR
    steps:
      - uses: actions/checkout@v4

      - uses: subosito/flutter-action@v2

      - run: flutter pub get

      # Run flutter analyze with --write option
      - run: flutter analyze --write=flutter_analyze.log

      # (Optional)Run custom lint with --format=json option
      - if: ${{ !cancelled() }}
        run: dart run custom_lint --format=json > custom_lint.log

      # Use flutter-analyze-commenter
      - if: ${{ !cancelled() }}               # Required to run this step even if failure
        uses: yorifuji/flutter-analyze-commenter@v1
        with:
          analyze-log: flutter_analyze.log    # file path for analyze log
          custom-lint-log: custom_lint.log    # file path for custom lint log (optional)
          verbose: false                      # verbose output (optional)

Features

  • Support for flutter analyze and custom_lint results
    • This action is compatible with both flutter analyze and custom_lint results.
  • Easy to Use
    • Just set the path to your Flutter analyze log file, and the action handles the rest.
  • Direct Integration with GitHub Actions
    • Designed as a native GitHub Action, it directly utilizes the GitHub ecosystem.
  • Small Footprint
    • Designed to be minimalistic, only doing what is necessary to comment on the PR based on analysis results.

How it works

If you wrote code like the following in VSCode,

diff --git a/lib/main.dart b/lib/main.dart
index dda5554..0456e5b 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -1,6 +1,8 @@
 import 'package:flutter/material.dart';

 void main() {
+  final String y1 = 1;
+
   runApp(const MyApp());
 }

problems will be shown.

image

These are based on the output from the Dart Analyze Server, but essentially, they are the same as what flutter analyze would produce.

% flutter analyze
Analyzing flutter_application...

   info • Use 'const' for final variables initialized to a constant value • lib/main.dart:4:3 • prefer_const_declarations
warning • The value of the local variable 'y1' isn't used • lib/main.dart:4:16 • unused_local_variable
  error • A value of type 'int' can't be assigned to a variable of type 'String' • lib/main.dart:4:21 • invalid_assignment

3 issues found. (ran in 0.9s)

This GitHub Action parses the log and posts it as comments directly on the pull request. This ensures that all the issues that would appear in your local Problems pane are now visible to reviewers directly in the PR, thus streamlining the review process and making it easier to address issues before merging code changes.

  1. Reads the log file generated by flutter analyze.
  2. Parses the results using a custom JavaScript script within the actions/github-script action.
  3. Posts comments on the pull request with any issues found, directly through the GitHub API.
  4. Ensures that duplicate comments are not posted for unchanged issues and that outdated comments are removed.

Motivation

Running flutter analyze within GitHub Actions is a commendable CI practice that significantly improves code quality.

However, trawling through Action execution logs to find flutter analyze results can be quite inconvenient. While utilizing a combination of Danger and danger-flutter_lint can facilitate displaying these results as PR comments — and these tools are indeed powerful — they also introduce a considerable overhead due to their multifunctionality and numerous dependencies.

There was a clear need for a more streamlined tool, one that's solely focused on presenting flutter analyze results within pull requests, without the extra baggage.

This is where Flutter Analyze Commenter comes in: a minimalistic, easy-to-use solution that seamlessly integrates with your CI/CD workflow.

Known issues

Currently, there are no reported issues. If you encounter any problems, please open an issue in the repository.

License

MIT