Skip to content

Commit

Permalink
Fix name
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Dec 3, 2024
1 parent d770d53 commit 05f6311
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ecosystem_test_internal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
test_ecosystem:
uses: ./.github/workflows/ecosystem_test.yaml
with:
repos_file: .github/test_repos/intl.json
repos_file: .github/test_repos/repos.json
86 changes: 54 additions & 32 deletions pkgs/quest/bin/quest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Future<void> main(List<String> arguments) async {
.where((line) => line.startsWith('ecosystem-test'));
print('Labels: $labels');
final packages = fire.Repository().locatePackages();
//TODO: Possibly run for all packages, not just the first.
final package = packages.firstWhereOrNull((package) =>
labels.any((label) => label == 'ecosystem-test-${package.name}'));
if (package != null) {
Expand All @@ -37,46 +38,56 @@ Future<void> main(List<String> arguments) async {
final comment = createComment(chronicles);
await writeComment(comment);
print(chronicles);
exitCode = chronicles.success ? 0 : 1;
}
}

enum Level { solve, analyze, test }
enum Level {
solve,
analyze,
test;
}

/// The result of embarking on a quest. Stores the [package] which was tested
/// with its new [version] as well as the [chapters] of the chronicles, each
/// storing the result of testing a single [Application].
class Chronicles {
final String package;
final String version;
final List<Chapter> chapters;
final Map<Application, Chapter> chapters;

Chronicles(this.package, this.version, this.chapters);

bool get success => chapters.values.every((chapter) => chapter.success);

@override
String toString() {
return '''
Chronicles(package: $package, version: $version, chapters: $chapters)''';
}
}

/// An individual chapter in the [Chronicles]. This stores the result of testing
/// against an individual [Application].
class Chapter {
final Repository repository;
final Map<Level, CheckResult> before;
final Map<Level, CheckResult> after;

Chapter(
{required this.repository, required this.before, required this.after});
Chapter({required this.before, required this.after});

bool get success => failure == null;

Level? get failure => Level.values.firstWhereOrNull((level) =>
before[level]?.success == true && after[level]?.success == false);

String toRow() => '''
| ${repository.name} | ${Level.values.map((l) => '${before[l]?.success.toEmoji ?? '-'}/${after[l]?.success.toEmoji ?? '-'}').join(' | ')} |''';
String toRow(Application application) => '''
| ${application.name} | ${Level.values.map((l) => '${before[l]?.success.toEmoji ?? '-'}/${after[l]?.success.toEmoji ?? '-'}').join(' | ')} |''';

@override
String toString() =>
'Chapter(repository: $repository, before: $before, after: $after)';
String toString() => 'Chapter(before: $before, after: $after)';
}

/// A success bool paired with the stdout and stderr for easier debugging.
class CheckResult {
final bool success;
final String stdout;
Expand All @@ -93,25 +104,28 @@ class CheckResult {
'ChapterLevel(success: $success, stdout: $stdout, stderr: $stderr)';
}

class Repository {
/// An application to test against, specified by the [url] where it can be
/// cloned from, its [name] for display purposes, and the maximum [level] it
/// should be tested to.
class Application {
final String url;
final String name;
final Level level;

const Repository({
const Application({
required this.url,
required this.name,
required this.level,
});

static Future<Iterable<Repository>> listFromFile(String path) async {
static Future<Iterable<Application>> listFromFile(String path) async {
final s = await File(path).readAsString();
return (jsonDecode(s) as Map)
.entries
.where((e) => e.key != r'$schema')
.map((e) => MapEntry(e.key as String, e.value as Map))
.map((e) {
return Repository(
return Application(
url: e.key,
name: (e.value['name'] as String?) ?? p.basename(e.key),
level: Level.values.firstWhere((l) => l.name == e.value['level']),
Expand All @@ -123,18 +137,21 @@ class Repository {
String toString() => 'Repository(url: $url, name: $name, level: $level)';
}

/// Contains the logic to fill [Chronicles] with the [Chapter]s of testing the
/// [candidatePackage] at [version] against the [Application]s listed in the
/// [applicationFile].
class Quest {
final String candidatePackage;
final String version;
final String repositoriesFile;
final String applicationFile;

Quest(this.candidatePackage, this.version, this.repositoriesFile);
Quest(this.candidatePackage, this.version, this.applicationFile);

Future<Chronicles> embark() async {
final chapters = <Chapter>[];
for (var repository in await Repository.listFromFile(repositoriesFile)) {
final path = await cloneRepo(repository.url);
print('Cloned $repository');
final chapters = <Application, Chapter>{};
for (var application in await Application.listFromFile(applicationFile)) {
final path = await cloneRepo(application.url);
print('Cloned $application');
final processResult = await Process.run(
'flutter',
[
Expand All @@ -152,33 +169,33 @@ class Quest {
print(depsPackages);
if (depsPackages.any((p) => (p as Map)['name'] == candidatePackage)) {
print('Run checks for vanilla package');
final resultBefore = await runChecks(path, repository.level);
final resultBefore = await runChecks(path, application.level);

print('Clean repo');
await runFlutter(['clean'], path);

print('Rev package:$candidatePackage to version $version $repository');
print('Rev package:$candidatePackage to version $version $application');
final revSuccess =
await runFlutter(['pub', 'add', version], path, true);

print('Run checks for modified package');
final resultAfter = await runChecks(path, repository.level);
final resultAfter = await runChecks(path, application.level);

// flutter pub add runs an implicit pub get
resultAfter[Level.solve] = revSuccess;

chapters.add(Chapter(
repository: repository,
chapters[application] = Chapter(
before: resultBefore,
after: resultAfter,
));
);
} else {
print('No package:$candidatePackage found in $repository');
print('No package:$candidatePackage found in $application');
}
}
return Chronicles(candidatePackage, version, chapters);
}

/// Uses `gh` to clone the Github repo at [url].
Future<String> cloneRepo(String url) async {
var path = url.split('/').last;
if (Directory(path).existsSync()) {
Expand All @@ -188,6 +205,7 @@ class Quest {
return path;
}

/// Uses `gh` to clone the Github repo at [url].
Future<Map<Level, CheckResult>> runChecks(String path, Level level) async {
final result = <Level, CheckResult>{};
result[Level.solve] = await runFlutter(['pub', 'get'], path);
Expand Down Expand Up @@ -241,20 +259,23 @@ String createComment(Chronicles chronicles) {
| Package | Solve | Analyze | Test |
| ------- | ----- | ------- | ---- |
${chronicles.chapters.map((chapter) => chapter.toRow()).join('\n')}
${chronicles.chapters.entries.map((chapter) => chapter.value.toRow(chapter.key)).join('\n')}
<details>
<summary>
<strong>Details per app</strong>
</summary>
${chronicles.chapters.map((chapter) => '''
${chronicles.chapters.entries.map((entry) {
final application = entry.key;
final chapter = entry.value;
return '''
<details>
<summary>
<strong>${chapter.repository.name}</strong> ${chapter.success ? '✅' : '❌'}
<strong>${application.name}</strong> ${chapter.success ? '✅' : '❌'}
</summary>
${chapter.success ? 'The app tests passed!' : '''
The failure occured at ${chapter.failure!.name}, this is the error output of that step:
The failure occured at the "${chapter.failure!.name}" step, this is the error output of that step:
```
${chapter.after[chapter.failure!]?.stderr}
```
Expand All @@ -265,7 +286,7 @@ The complete list of logs is:
${chapter.before.keys.map((level) => '''
<details>
<summary>
<strong>Logs for ${level.name}</strong>
<strong>Logs for step: ${level.name}</strong>
</summary>
Expand Down Expand Up @@ -298,7 +319,8 @@ ${chapter.after[level]?.stderr}
</details>
''').join('\n')}
''';
}).join('\n')}
</details>
Expand Down

0 comments on commit 05f6311

Please sign in to comment.