Skip to content

Commit

Permalink
Report and score downgrade+analyze
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos committed May 14, 2024
1 parent 09a86c0 commit 5a8af86
Show file tree
Hide file tree
Showing 35 changed files with 454 additions and 484 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.22.4

- Report and score `pub downgrade` + `dart analyze`.

## 0.22.3

- Do not emit package names in `allDependencies` with trivial syntax issues.
Expand Down
35 changes: 35 additions & 0 deletions lib/src/package_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,41 @@ class PackageContext {
return errorMessage;
}();

/// Runs `pub downgrade` and then static analysis.
/// Returns `null` when no issues found or a String description of the issues.
late final downgradeAnalysisErrorMessage = () async {
try {
log.info('Analyzing pub downgrade...');
final pr = await toolEnvironment.runPub(
packageDir,
usesFlutter: usesFlutter,
command: 'downgrade',
);
if (pr.exitCode != 0) {
return '`pub downgrade` failed with:\n${pr.asTrimmedOutput}';
}

final problems = await _staticAnalysis(packageDir: packageDir);
final issues = problems.where((e) => e.isError).toList();
if (issues.isEmpty) {
// success returning `null`
return null;
} else {
return 'downgrade analysis failed with ${issues.length} ${issues.length == 1 ? 'issue' : 'issues'}.';
}
} on ToolException catch (e) {
return 'downgrade analysis failed with:\n${e.message}';
} finally {
try {
await toolEnvironment.runPub(packageDir,
usesFlutter: usesFlutter, command: 'upgrade');
} on ToolException catch (e, st) {
errors.add('`dart upgrade` failed');
log.warning('dart upgrade failed', e, st);
}
}
}();

Future<List<CodeProblem>> staticAnalysis() async {
if (_codeProblems != null) return _codeProblems!;
try {
Expand Down
28 changes: 26 additions & 2 deletions lib/src/report/dependencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,37 @@ Future<ReportSection> trustworthyDependency(PackageContext context) async {
);
}

Future<Subsection> downgrade() async {
final message = await context.downgradeAnalysisErrorMessage;
final isPassed = message == null;
final issues = isPassed
? [
RawParagraph(
'`pub downgrade` does not expose any static analysis error.'),
]
: [
Issue(
'`pub downgrade` finds static analysis issue(s):\n\n$message'),
RawParagraph(
'You may run `dart pub upgrade --tighten` to update your dependency constraints.'),
];
return Subsection(
'Dependency constraint lower bounds are not breaking',
issues,
isPassed ? 20 : 0,
20,
isPassed ? ReportStatus.passed : ReportStatus.failed,
);
}

final dependencySection = await dependencies();
final sdkSection = await sdkSupport();
final subsections = [dependencySection, sdkSection];
final downgradeSection = await downgrade();
final subsections = [dependencySection, sdkSection, downgradeSection];
return makeSection(
id: ReportSectionId.dependency,
title: 'Support up-to-date dependencies',
maxPoints: 20,
maxPoints: subsections.map((e) => e.maxPoints).fold(0, (a, b) => a + b),
subsections: subsections,
basePath: packageDir,
);
Expand Down
69 changes: 25 additions & 44 deletions lib/src/sdk_env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'dart:io';
import 'package:cli_util/cli_util.dart' as cli;
import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';
import 'package:retry/retry.dart';

import 'analysis_options.dart';
import 'internal_model.dart';
Expand Down Expand Up @@ -305,54 +304,36 @@ class ToolEnvironment {
Future<PanaProcessResult> runUpgrade(
String packageDir,
bool usesFlutter, {
int retryCount = 3,
@Deprecated('retryCount is ignored') int retryCount = 3,
}) async {
return await _withStripAndAugmentPubspecYaml(packageDir, () async {
final retryOptions = const RetryOptions(maxAttempts: 3);
bool retryIf(PanaProcessResult result) {
final errOutput = result.stderr.asString;
// find cases where retrying is not going to help – and short-circuit
if (errOutput.contains('Could not get versions for flutter from sdk')) {
return false;
}
if (errOutput.contains('FINE: Exception type: NoVersionException')) {
return false;
}
return true;
}
return await runPub(
packageDir,
usesFlutter: usesFlutter,
command: 'upgrade',
);
}

if (usesFlutter) {
return await runConstrained(
[
Future<PanaProcessResult> runPub(
String packageDir, {
required bool usesFlutter,
required String command,
}) async {
return await _withStripAndAugmentPubspecYaml(packageDir, () async {
return await runConstrained(
[
if (usesFlutter) ...[
..._flutterSdk.flutterCmd,
'packages',
'pub',
'upgrade',
'--no-example',
'--verbose',
],
workingDirectory: packageDir,
environment:
usesFlutter ? _flutterSdk.environment : _dartSdk.environment,
retryIf: retryIf,
retryOptions: retryOptions,
);
} else {
return await runConstrained(
[
] else
..._dartSdk.dartCmd,
'pub',
'upgrade',
'--no-example',
'--verbose',
],
workingDirectory: packageDir,
environment:
usesFlutter ? _flutterSdk.environment : _dartSdk.environment,
retryIf: retryIf,
retryOptions: retryOptions,
);
}
'pub',
command,
'--no-example',
],
workingDirectory: packageDir,
environment:
usesFlutter ? _flutterSdk.environment : _dartSdk.environment,
);
});
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pana
description: PAckage aNAlyzer - produce a report summarizing the health and quality of a Dart package.
version: 0.22.3
version: 0.22.4-dev
repository: https://github.com/dart-lang/pana
topics:
- tool
Expand Down
6 changes: 3 additions & 3 deletions test/goldens/end2end/_dummy_pkg-1.0.0-null-safety.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@
"id": "dependency",
"title": "Support up-to-date dependencies",
"grantedPoints": 0,
"maxPoints": 20,
"maxPoints": 40,
"status": "failed",
"summary": "### [x] 0/10 points: All of the package dependencies are supported in the latest version\n\n<details>\n<summary>\nSdk constraint doesn't support current Dart version {{sdk-version}}. Cannot run `dart pub outdated`.\n</summary>\n\n`pubspec.yaml:6:8`\n\n```\n\n6 │ sdk: \">=2.12.0-0 <2.12.0\"\n │ ^^^^^^^^^^^^^^^^^^^^\n\n```\n\n</details>\n\n### [x] 0/10 points: Package supports latest stable Dart and Flutter SDKs\n\n<details>\n<summary>\nSdk constraint doesn't support current Dart version {{sdk-version}}.\n</summary>\n\n`pubspec.yaml:6:8`\n\n```\n\n6 │ sdk: \">=2.12.0-0 <2.12.0\"\n │ ^^^^^^^^^^^^^^^^^^^^\n\n```\n\nTry widening the upper boundary of the constraint.\n</details>"
"summary": "### [x] 0/10 points: All of the package dependencies are supported in the latest version\n\n<details>\n<summary>\nSdk constraint doesn't support current Dart version {{sdk-version}}. Cannot run `dart pub outdated`.\n</summary>\n\n`pubspec.yaml:6:8`\n\n```\n ╷\n6 │ sdk: \">=2.12.0-0 <2.12.0\"\n │ ^^^^^^^^^^^^^^^^^^^^\n ╵\n```\n\n</details>\n\n### [x] 0/10 points: Package supports latest stable Dart and Flutter SDKs\n\n<details>\n<summary>\nSdk constraint doesn't support current Dart version {{sdk-version}}.\n</summary>\n\n`pubspec.yaml:6:8`\n\n```\n ╷\n6 │ sdk: \">=2.12.0-0 <2.12.0\"\n │ ^^^^^^^^^^^^^^^^^^^^\n ╵\n```\n\nTry widening the upper boundary of the constraint.\n</details>\n\n### [x] 0/20 points: Dependency constraint lower bounds are not breaking\n\n* `pub downgrade` finds static analysis issue(s):\n\n`pub downgrade` failed with:\nOUT:\nResolving dependencies...\nERR:\nThe current Dart SDK version is {{sdk-version}}.\n\nBecause _dummy_pkg requires SDK version >=2.12.0-0 <2.12.0, version solving failed.\nYou may run `dart pub upgrade --tighten` to update your dependency constraints."
}
]
},
"screenshots": [],
"result": {
"homepageUrl": "https://github.com/dart-lang/pub-dev",
"grantedPoints": 15,
"maxPoints": 140
"maxPoints": 160
},
"urlProblems": [],
"errorMessage": "Running `dart pub outdated` failed with the following output:\n\n```\nThe current Dart SDK version is {{sdk-version}}.\nBecause _dummy_pkg requires SDK version >=2.12.0-0 <2.12.0, version solving failed.\n```"
Expand Down
17 changes: 15 additions & 2 deletions test/goldens/end2end/_dummy_pkg-1.0.0-null-safety.1.json_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Because _dummy_pkg requires SDK version >=2.12.0-0 <2.12.0, version solving fail
```


## 0/20 Support up-to-date dependencies
## 0/40 Support up-to-date dependencies

### [x] 0/10 points: All of the package dependencies are supported in the latest version

Expand Down Expand Up @@ -134,4 +134,17 @@ Sdk constraint doesn't support current Dart version {{sdk-version}}.
```

Try widening the upper boundary of the constraint.
</details>
</details>

### [x] 0/20 points: Dependency constraint lower bounds are not breaking

* `pub downgrade` finds static analysis issue(s):

`pub downgrade` failed with:
OUT:
Resolving dependencies...
ERR:
The current Dart SDK version is {{sdk-version}}.

Because _dummy_pkg requires SDK version >=2.12.0-0 <2.12.0, version solving failed.
You may run `dart pub upgrade --tighten` to update your dependency constraints.
10 changes: 5 additions & 5 deletions test/goldens/end2end/async-2.11.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@
{
"id": "dependency",
"title": "Support up-to-date dependencies",
"grantedPoints": 20,
"maxPoints": 20,
"grantedPoints": 40,
"maxPoints": 40,
"status": "passed",
"summary": "### [*] 10/10 points: All of the package dependencies are supported in the latest version\n\n|Package|Constraint|Compatible|Latest|\n|:-|:-|:-|:-|\n|[`collection`]|`^1.15.0`|1.18.0|1.18.0|\n|[`meta`]|`^1.1.7`|1.11.0|1.11.0|\n\nTo reproduce run `dart pub outdated --no-dev-dependencies --up-to-date --no-dependency-overrides`.\n\n[`collection`]: https://pub.dev/packages/collection\n[`meta`]: https://pub.dev/packages/meta\n\n\n### [*] 10/10 points: Package supports latest stable Dart and Flutter SDKs\n"
"summary": "### [*] 10/10 points: All of the package dependencies are supported in the latest version\n\n|Package|Constraint|Compatible|Latest|\n|:-|:-|:-|:-|\n|[`collection`]|`^1.15.0`|1.18.0|1.18.0|\n|[`meta`]|`^1.1.7`|1.11.0|1.11.0|\n\nTo reproduce run `dart pub outdated --no-dev-dependencies --up-to-date --no-dependency-overrides`.\n\n[`collection`]: https://pub.dev/packages/collection\n[`meta`]: https://pub.dev/packages/meta\n\n\n### [*] 10/10 points: Package supports latest stable Dart and Flutter SDKs\n\n\n### [*] 20/20 points: Dependency constraint lower bounds are not breaking\n\n`pub downgrade` does not expose any static analysis error."
}
]
},
Expand All @@ -118,8 +118,8 @@
"branch": "master"
},
"contributingUrl": "https://github.com/dart-lang/async/blob/master/CONTRIBUTING.md",
"grantedPoints": 130,
"maxPoints": 140
"grantedPoints": 150,
"maxPoints": 160
},
"urlProblems": []
}
7 changes: 6 additions & 1 deletion test/goldens/end2end/async-2.11.0.json_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ See [package layout](https://dart.dev/tools/pub/package-layout#examples) guideli
### [*] 50/50 points: code has no errors, warnings, lints, or formatting issues


## 20/20 Support up-to-date dependencies
## 40/40 Support up-to-date dependencies

### [*] 10/10 points: All of the package dependencies are supported in the latest version

Expand All @@ -61,3 +61,8 @@ To reproduce run `dart pub outdated --no-dev-dependencies --up-to-date --no-depe


### [*] 10/10 points: Package supports latest stable Dart and Flutter SDKs


### [*] 20/20 points: Dependency constraint lower bounds are not breaking

`pub downgrade` does not expose any static analysis error.
Loading

0 comments on commit 5a8af86

Please sign in to comment.