Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
axel-op committed Oct 8, 2019
2 parents 862b98d + f3450e0 commit 2c09fb0
Show file tree
Hide file tree
Showing 10 changed files with 321 additions and 207 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM google/dart:2.5
FROM google/dart:2

COPY app/ /app/

Expand All @@ -13,4 +13,4 @@ RUN apt-get update \
&& git clone -b stable --depth 1 https://github.com/flutter/flutter.git /flutter \
&& /flutter/bin/flutter --version

ENTRYPOINT ["dartaotruntime", "/main.dart.aot", "-f", "/flutter", "-r", "/github/workspace"]
ENTRYPOINT ["dartaotruntime", "/main.dart.aot"]
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Dart/Flutter package analyzer

This action uses the [pana (Package ANAlysis) package](https://pub.dev/packages/pana) to compute the score that your Dart or Flutter package will have on the [Pub site](https://pub.dev), and post it as a commit comment, with suggestions for improvements.
This action uses the [pana (Package ANAlysis) package](https://pub.dev/packages/pana) to compute the score that your Dart or Flutter package will have on the [Pub site](https://pub.dev/help), and posts it as a commit comment, with suggestions for improvements.

This package, amongst other things:
* checks code formatting with `dartfmt` or `flutter format` (detected automatically),
* checks code formatting with [`dartfmt`](https://dart.dev/tools/dartfmt) or [`flutter format`](https://flutter.dev/docs/development/tools/formatting#automatically-formatting-code-with-the-flutter-command) (detected automatically),
* validates the code by performing static analysis with [dartanalyzer](https://dart.dev/tools/dartanalyzer),
* checks for outdated dependencies,
* validates the `pubscpec.yaml` file (dependencies, description's length...),
Expand All @@ -28,11 +28,11 @@ jobs:
- uses: actions/checkout@v1 # required
- uses: axel-op/dart_package_analyzer@stable
with:
githubToken: ${{ secrets.GITHUB_TOKEN }} # required
eventPayload: ${{ toJson(github.event) }} # required
commitSha: ${{ github.sha }} # required
# Required:
githubToken: ${{ secrets.GITHUB_TOKEN }}
# Optional:
maxScoreToComment: 99.99
relativePath: 'mypackage/v1'
relativePath: 'packages/mypackage/'
```
* `githubToken`, `eventPayload`, and `commitSha` inputs are required to post a comment on GitHub.
Expand Down
17 changes: 0 additions & 17 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ inputs:
githubToken:
description: 'Token to connect to Github. Use secrets.GITHUB_TOKEN'
required: true
eventPayload:
description: 'Use toJson(github.event)'
required: true
commitSha:
description: 'Use github.sha'
required: true
maxScoreToComment:
description: 'No comment will be posted if both scores are over this max'
required: false
Expand All @@ -25,14 +19,3 @@ inputs:
runs:
using: 'docker'
image: 'Dockerfile'
args:
- --github_token
- ${{ inputs.githubToken }}
- --commit_sha
- ${{ inputs.commitSha }}
- --max_score
- ${{ inputs.maxScoreToComment }}
- --package_path
- ${{ inputs.relativePath }}
- --event_payload
- ${{ inputs.eventPayload }}
139 changes: 53 additions & 86 deletions app/bin/main.dart
Original file line number Diff line number Diff line change
@@ -1,109 +1,74 @@
import 'dart:convert';
import 'dart:io';

import 'package:app/event.dart';
import 'package:app/github.dart';
import 'package:app/inputs.dart';
import 'package:app/result.dart';
import 'package:app/utils.dart';
import 'package:args/args.dart';
import 'package:meta/meta.dart';

class _Argument {
final String fullName;
final String abbreviation;
final bool nullable;
const _Argument(this.fullName, this.abbreviation, {@required this.nullable});
}

const List<_Argument> arguments = <_Argument>[
_Argument('repo_path', 'r', nullable: false),
_Argument('github_token', 't', nullable: false),
_Argument('event_payload', 'e', nullable: false),
_Argument('fluttersdk_path', 'f', nullable: false),
_Argument('commit_sha', 'c', nullable: false),
_Argument('max_score', 'm', nullable: true),
_Argument('package_path', 'p', nullable: true),
];

dynamic main(List<String> args) async {
exitCode = 1;

// Parse command arguments
final ArgParser argparser = ArgParser();
arguments.forEach((_Argument arg) =>
argparser.addOption(arg.fullName, abbr: arg.abbreviation));
final ArgResults argresults = argparser.parse(args);
arguments.forEach((_Argument arg) {
if (argresults[arg.fullName] == null && !arg.nullable) {
stderr.writeln(
'No value were given for the argument \'${arg.fullName}\'. Exiting.');
exit(1);
}
});
final String repoPath = argresults['repo_path'];
final String flutterPath = argresults['fluttersdk_path'];
final String eventPayload = argresults['event_payload'];
final String githubToken = argresults['github_token'];
final String commitSha = argresults['commit_sha'];
final dynamic maxScoreUnknownType = argresults['max_score'];
final num maxScore =
maxScoreUnknownType != null && maxScoreUnknownType is String
? num.parse(maxScoreUnknownType)
: maxScoreUnknownType;
String packagePathUnformatted = argresults['package_path'] ?? '';
if (!packagePathUnformatted.startsWith('/') && !repoPath.endsWith('/')) {
packagePathUnformatted = '/' + packagePathUnformatted;
}
final String sourcePath = repoPath + packagePathUnformatted;
final Inputs arguments = getInputs();

// Install pana package
await _runCommand('pub', <String>['global', 'activate', 'pana'],
exitOnError: true);
await _runCommand(
'pub',
const <String>['global', 'activate', 'pana'],
exitOnError: true,
);

// Command to disable analytics reporting, and also to prevent a warning from the next command due to Flutter welcome screen
await _runCommand(
'$flutterPath/bin/flutter', <String>['config', '--no-analytics']);
'${arguments.flutterPath}/bin/flutter',
const <String>['config', '--no-analytics'],
);

// Execute the analysis
final String outputPana = await _runCommand(
'pub',
<String>[
'global',
'run',
'pana',
'--scores',
'--no-warning',
'--flutter-sdk',
flutterPath,
'--source',
'path',
sourcePath,
],
exitOnError: true);
'pub',
<String>[
'global',
'run',
'pana',
'--scores',
'--no-warning',
'--flutter-sdk',
arguments.flutterPath,
'--source',
'path',
arguments.sourcePath,
],
exitOnError: true,
);

if (outputPana == null) throw ArgumentError.notNull('outputPana');
if (outputPana == null) {
stderr.writeln('The pana command has returned no valid output. Exiting.');
exit(1);
}
final Map<String, dynamic> resultPana = jsonDecode(outputPana);
final Event event = getEvent(jsonDecode(eventPayload));
final Result result = processOutput(resultPana);
final String comment = buildComment(result, event, commitSha);
final String comment = buildComment(
result: result,
commitSha: arguments.commitSha,
);

const String noComment =
'Health score and maintenance score are both higher than the maximum score, so no general commit comment will be made.';

// Post a comment on GitHub
if (maxScore != null &&
result.healthScore > maxScore &&
result.maintenanceScore > maxScore) {
stdout.writeln(
'Health score and maintenance score are both higher than the maximum score, so no general commit comment will be made.' +
(result.lineSuggestions.isNotEmpty
? ' However, specific comments are still posted under each line where static analysis has found an issue.'
: ''));
if (result.healthScore > arguments.maxScoreToComment &&
result.maintenanceScore > arguments.maxScoreToComment) {
stdout.writeln(noComment);
exitCode = 0;
} else {
exitCode = 0;
await postCommitComment(
comment,
event: event,
githubToken: githubToken,
commitSha: commitSha,
repositorySlug: arguments.repositorySlug,
githubToken: arguments.githubToken,
commitSha: arguments.commitSha,
onError: (dynamic e, dynamic s) async {
_writeErrors(e, s);
exitCode = 1;
Expand All @@ -112,15 +77,14 @@ dynamic main(List<String> args) async {
}

// Post file-specific comments on GitHub
/* Deactivated for now, as the API deprecated the line parameter, and should now be given the diff's position
for (final LineSuggestion suggestion in results.lineSuggestions) {
/*for (final LineSuggestion suggestion in result.lineSuggestions) {
await postCommitComment(
suggestion.description,
event: event,
githubToken: githubToken,
commitSha: commitSha,
repositorySlug: arguments.repositorySlug,
githubToken: arguments.githubToken,
commitSha: arguments.commitSha,
lineNumber: suggestion.lineNumber,
fileRelativePath: suggestion.relativePath,
fileRelativePath: '${arguments.packagePath}/${suggestion.relativePath}',
onError: (dynamic e, dynamic s) async {
_writeErrors(e, s);
exitCode = 1;
Expand All @@ -131,8 +95,11 @@ dynamic main(List<String> args) async {

/// Runs a command and prints its outputs to stderr and stdout while running.
/// Returns the sdtout output in a String.
Future<String> _runCommand(String executable, List<String> arguments,
{bool exitOnError = false}) async {
Future<String> _runCommand(
String executable,
List<String> arguments, {
bool exitOnError = false,
}) async {
Future<List<String>> output;
Future<dynamic> addStreamOut;
Future<dynamic> addStreamErr;
Expand All @@ -141,7 +108,7 @@ Future<String> _runCommand(String executable, List<String> arguments,
try {
final int code =
await Process.start(executable, arguments, runInShell: true)
.then((Process process) {
.then((final Process process) {
addStreamErr = stderr.addStream(process.stderr);
final Stream<List<int>> outBrStream = process.stdout.asBroadcastStream();
addStreamOut = stdout.addStream(outBrStream);
Expand Down
45 changes: 0 additions & 45 deletions app/lib/event.dart

This file was deleted.

Loading

1 comment on commit 2c09fb0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package analysis results for commit 2c09fb0

(version of pana used: 0.12.21)

  • Health score is 96.55 / 100.0
  • Maintenance score is 50.0 / 100.0

Please note that 50% of the overall score of your package on the Pub site will be based on its popularity ; 30% on its health score ; and 20% on its maintenance score.

Issues

Health

  • Fix lib/test_package.dart (3.45 points): Analysis of lib/test_package.dart reported 7 hints, including:
    • line 6 col 22: 'valueTest' is deprecated and shouldn't be used.
    • line 13 col 22: 'value4' is deprecated and shouldn't be used.
    • line 26 col 32: 'value' is deprecated and shouldn't be used.
    • line 31 col 9: The value of the local variable 'sum' isn't used.
    • line 31 col 18: 'value' is deprecated and shouldn't be used.

Maintenance

  • Homepage URL isn't helpful (10.0 points): Update the homepage field from pubspec.yaml: link to a website about the package or use the source repository URL.
  • The package description is too short (20.0 points): Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.
  • Maintain an example (10.0 points): Create a short demo in the example/ directory to show how to use this package.
    • Common filename patterns include main.dart, example.dart, and test_package.dart. Packages with multiple examples should provide example/README.md.
    • For more information see the pub package layout conventions.
  • Package is pre-v0.1 release (10.0 points): While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Please sign in to comment.