-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add api tool call for testing #153
Changes from all commits
b2d4ff7
29cc8b6
22fbb6c
d14f30e
c893a6f
54b00b7
ed7c17c
597f95d
1602049
d04f966
e6d2c5d
11c1093
e694a6f
42f750d
5a30607
ea62622
ab4cdb4
36aac52
7c6d881
2cbfdc8
459b25c
ada4234
5542840
0ad660a
510abf9
dab1b08
6f8bdc4
078566c
7fd83a7
bdf61fa
9ebdbab
bf6746a
b88a2d1
f4e9682
f0e944c
26c1ba9
ca1d300
2538134
14c9a94
82c2a4f
a2c044c
8702ab8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.3.31 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just fyi there are a few PRs underway rev'ing firehose - |
||
|
||
- Add PR Health checks for breaking changes. | ||
|
||
## 0.3.30 | ||
|
||
- Improve support for `-dev` and `-wip` package versions. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,17 @@ | |
|
||
// ignore_for_file: always_declare_return_types | ||
|
||
import 'dart:convert'; | ||
import 'dart:io'; | ||
import 'dart:math'; | ||
|
||
import 'package:collection/collection.dart'; | ||
import 'package:path/path.dart' as path; | ||
import 'package:pub_semver/pub_semver.dart'; | ||
|
||
import '../../firehose.dart'; | ||
import '../github.dart'; | ||
import '../repo.dart'; | ||
import '../utils.dart'; | ||
import 'changelog.dart'; | ||
import 'coverage.dart'; | ||
|
@@ -28,6 +32,8 @@ const String _changelogBotTag = '### Changelog Entry'; | |
|
||
const String _coverageBotTag = '### Coverage'; | ||
|
||
const String _breakingBotTag = '### Breaking changes'; | ||
|
||
const String _prHealthTag = '## PR Health'; | ||
|
||
class Health { | ||
|
@@ -63,6 +69,9 @@ class Health { | |
if (args.contains('coverage') && | ||
!github.prLabels.contains('skip-coverage-check')) | ||
(Github github) => coverageCheck(github, coverageweb), | ||
if (args.contains('breaking') && | ||
!github.prLabels.contains('skip-breaking-check')) | ||
breakingCheck, | ||
]; | ||
|
||
var checked = | ||
|
@@ -92,6 +101,80 @@ Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automati | |
); | ||
} | ||
|
||
Future<HealthCheckResult> breakingCheck(Github github) async { | ||
final repo = Repository(); | ||
final packages = repo.locatePackages(); | ||
var changeForPackage = <Package, BreakingChange>{}; | ||
var baseDirectory = Directory('../base_repo'); | ||
for (var package in packages) { | ||
var currentPath = | ||
path.relative(package.directory.path, from: Directory.current.path); | ||
var basePackage = path.relative( | ||
path.join(baseDirectory.absolute.path, currentPath), | ||
from: currentPath, | ||
); | ||
print('Look for changes in $currentPath with base $basePackage'); | ||
var runApiTool = Process.runSync( | ||
'dart', | ||
[ | ||
...['pub', 'global', 'run'], | ||
'dart_apitool:main', | ||
'diff', | ||
...['--old', basePackage], | ||
...['--new', '.'], | ||
...['--report-format', 'json'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this run finds breaking changes, should we re-run this report in another format and dump the results to stdout? |
||
...['--report-file-path', 'report.json'], | ||
], | ||
workingDirectory: currentPath, | ||
); | ||
print(runApiTool.stderr); | ||
print(runApiTool.stdout); | ||
|
||
final reportFile = File(path.join(currentPath, 'report.json')); | ||
var fullReportString = reportFile.readAsStringSync(); | ||
var decoded = jsonDecode(fullReportString) as Map<String, dynamic>; | ||
var report = decoded['report'] as Map<String, dynamic>; | ||
|
||
var formattedChanges = const JsonEncoder.withIndent(' ').convert(report); | ||
print('Breaking change report:\n$formattedChanges'); | ||
|
||
BreakingLevel breakingLevel; | ||
if ((report['noChangesDetected'] as bool?) ?? false) { | ||
breakingLevel = BreakingLevel.none; | ||
} else { | ||
if ((report['breakingChanges'] as Map? ?? {}).isNotEmpty) { | ||
breakingLevel = BreakingLevel.breaking; | ||
} else if ((report['nonBreakingChanges'] as Map? ?? {}).isNotEmpty) { | ||
breakingLevel = BreakingLevel.nonBreaking; | ||
} else { | ||
breakingLevel = BreakingLevel.none; | ||
} | ||
} | ||
|
||
var oldPackage = Package( | ||
Directory(path.join(baseDirectory.path, currentPath)), | ||
package.repository, | ||
); | ||
changeForPackage[package] = BreakingChange( | ||
level: breakingLevel, | ||
oldVersion: oldPackage.version!, | ||
newVersion: package.version!, | ||
); | ||
} | ||
return HealthCheckResult( | ||
'breaking', | ||
_breakingBotTag, | ||
changeForPackage.values.any((element) => !element.versionIsFine) | ||
? Severity.warning | ||
: Severity.info, | ||
''' | ||
| Package | Change | Current Version | New Version | Needed Version | Looking good? | | ||
| :--- | :--- | ---: | ---: | ---: | ---: | | ||
${changeForPackage.entries.map((e) => '|${e.key.name}|${e.value.toMarkdownRow()}|').join('\n')} | ||
''', | ||
); | ||
} | ||
|
||
Future<HealthCheckResult> licenseCheck(Github github) async { | ||
var files = await github.listFilesForPR(); | ||
var allFilePaths = await getFilesWithoutLicenses(Directory.current); | ||
|
@@ -237,6 +320,24 @@ Saving existing comment id $existingCommentId to file ${idFile.path}'''); | |
} | ||
} | ||
|
||
Version getNewVersion(BreakingLevel level, Version oldVersion) { | ||
return switch (level) { | ||
BreakingLevel.none => oldVersion, | ||
BreakingLevel.nonBreaking => oldVersion.nextMinor, | ||
BreakingLevel.breaking => oldVersion.nextBreaking, | ||
}; | ||
} | ||
|
||
enum BreakingLevel { | ||
none('None'), | ||
nonBreaking('Non-Breaking'), | ||
breaking('Breaking'); | ||
|
||
final String name; | ||
|
||
const BreakingLevel(this.name); | ||
} | ||
|
||
class HealthCheckResult { | ||
final String name; | ||
final String tag; | ||
|
@@ -245,3 +346,27 @@ class HealthCheckResult { | |
|
||
HealthCheckResult(this.name, this.tag, this.severity, this.markdown); | ||
} | ||
|
||
class BreakingChange { | ||
final BreakingLevel level; | ||
final Version oldVersion; | ||
final Version newVersion; | ||
|
||
BreakingChange({ | ||
required this.level, | ||
required this.oldVersion, | ||
required this.newVersion, | ||
}); | ||
|
||
Version get suggestedNewVersion => getNewVersion(level, oldVersion); | ||
|
||
bool get versionIsFine => newVersion == suggestedNewVersion; | ||
|
||
String toMarkdownRow() => [ | ||
level.name, | ||
oldVersion, | ||
newVersion, | ||
versionIsFine ? suggestedNewVersion : '**$suggestedNewVersion**', | ||
versionIsFine ? ':heavy_check_mark:' : ':warning:' | ||
].map((e) => e.toString()).join('|'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it that this tool isn't published to pub?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is - the version I want is just not published yet.