From fa49b830aec23f4ce5ba40143652e70cec9672d5 Mon Sep 17 00:00:00 2001 From: Moritz Date: Fri, 29 Nov 2024 10:54:28 +0100 Subject: [PATCH] Update commenting --- pkgs/quest/bin/quest.dart | 124 +++++++++++++++++++++++++++++++------- 1 file changed, 101 insertions(+), 23 deletions(-) diff --git a/pkgs/quest/bin/quest.dart b/pkgs/quest/bin/quest.dart index aaf19e43..2937a2bf 100644 --- a/pkgs/quest/bin/quest.dart +++ b/pkgs/quest/bin/quest.dart @@ -1,8 +1,8 @@ import 'dart:convert'; import 'dart:io'; + import 'package:collection/collection.dart'; import 'package:firehose/firehose.dart' as fire; - import 'package:path/path.dart' as p; Future main(List arguments) async { @@ -46,16 +46,36 @@ Chronicles(package: $package, version: $version, chapters: $chapters)'''; class Chapter { final Repository repository; - final Map successBefore; - final Map successAfter; + bool get success => !Level.values.any((level) => + before[level]?.success == true && after[level]?.success == false); + final Map before; + final Map after; - Chapter(this.repository, this.successBefore, this.successAfter); + Chapter( + {required this.repository, required this.before, required this.after}); + + String toRow() => ''' +| ${repository.name} | ${Level.values.map((l) => '${before[l]?.success.toEmoji ?? '-'}/${after[l]?.success.toEmoji ?? '-'}').join(' | ')} |'''; @override - String toString() { - return ''' -Chapter(packageName: ${repository.name}, packageUri: ${repository.url}, successBefore: $successBefore, successAfter: $successAfter)'''; - } + String toString() => + 'Chapter(repository: $repository, before: $before, after: $after)'; +} + +class CheckResult { + final bool success; + final String stdout; + final String stderr; + + CheckResult({ + required this.success, + required this.stdout, + required this.stderr, + }); + + @override + String toString() => + 'ChapterLevel(success: $success, stdout: $stdout, stderr: $stderr)'; } class Repository { @@ -117,7 +137,7 @@ class Quest { print(depsPackages); if (depsPackages.any((p) => (p as Map)['name'] == candidatePackage)) { print('Run checks for vanilla package'); - final successBefore = await runChecks(path, repository.level); + final resultBefore = await runChecks(path, repository.level); print('Clean repo'); await runFlutter(['clean'], path); @@ -130,13 +150,16 @@ class Quest { ], path); print('Run checks for modified package'); - final successAfter = await runChecks(path, repository.level); - successAfter.update( - Level.solve, - (value) => value ? revSuccess : value, - ifAbsent: () => revSuccess, - ); - chapters.add(Chapter(repository, successBefore, successAfter)); + final resultAfter = await runChecks(path, repository.level); + + // flutter pub add runs an implicit pub get + resultAfter[Level.solve] = revSuccess; + + chapters.add(Chapter( + repository: repository, + before: resultBefore, + after: resultAfter, + )); } else { print('No package:$candidatePackage found in $repository'); } @@ -153,8 +176,8 @@ class Quest { return path; } - Future> runChecks(String path, Level level) async { - final success = {}; + Future> runChecks(String path, Level level) async { + final success = {}; success[Level.solve] = await runFlutter(['pub', 'get'], path); if (level.index >= Level.analyze.index) { success[Level.analyze] = await runFlutter(['analyze'], path); @@ -165,15 +188,17 @@ class Quest { return success; } - Future runFlutter(List arguments, String path) async { + Future runFlutter(List arguments, String path) async { final processResult = await Process.run( 'flutter', arguments, workingDirectory: path, ); - print('${processResult.stdout}'); - print('${processResult.stderr}'); - return processResult.exitCode == 0; + return CheckResult( + success: processResult.exitCode == 0, + stdout: processResult.stdout as String, + stderr: processResult.stderr as String, + ); } } @@ -187,10 +212,63 @@ String createComment(Chronicles chronicles) { final contents = ''' ## Ecosystem testing +| Package | Solve | Analyze | Test | +| ------- | ----- | ------- | ---- | +${chronicles.chapters.map((chapter) => chapter.toRow()).join('\n')} + +
+ +Logs per app + +${chronicles.chapters.map((chapter) => ''' +
+ +${chapter.repository.name} ${chapter.success ? '✅' : '❌'}; + | Package | Solve | Analyze | Test | | ------- | ----- | ------- | ---- | -${chronicles.chapters.map((e) => '| ${e.repository.name} | ${Level.values.map((l) => '${e.successBefore[l]?.toEmoji ?? '-'}/${e.successAfter[l]?.toEmoji ?? '-'}').join(' | ')} |').join('\n')} +${chapter.toRow()} + +${chapter.before.keys.map((level) => ''' +
+ +Logs for ${level.name} + + + +### Before: + +StdOut: +``` +${chapter.before[level]?.stdout} +``` + +StdErr: +``` +${chapter.before[level]?.stderr} +``` + +### After: + +StdOut: +``` +${chapter.after[level]?.stdout} +``` + +StdErr: +``` +${chapter.after[level]?.stderr} +``` + +
+''').join('\n')}; + +
+ +''').join('\n')}; + +
'''; return contents;