forked from dart-lang/ecosystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
222 additions
and
29 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
https://github.com/mosuem/my_app_old_web | ||
https://github.com/mosuem/my_app_new_web |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# https://dart.dev/guides/libraries/private-files | ||
# Created by `dart pub` | ||
.dart_tool/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 1.0.0 | ||
|
||
- Initial version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
A sample command-line application with an entrypoint in `bin/`, library code | ||
in `lib/`, and example unit test in `test/`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include: package:dart_flutter_team_lints/analysis_options.yaml | ||
|
||
linter: | ||
rules: | ||
- prefer_final_locals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
Future<void> main(List<String> arguments) async { | ||
final candidatePackage = arguments.first; | ||
final version = arguments[1]; | ||
final level = Level.values.firstWhere((l) => l.name == arguments[2]); | ||
final chronicles = await Quest(candidatePackage, version, level).embark(); | ||
print(chronicles); | ||
} | ||
|
||
enum Level { solve, analyze, test } | ||
|
||
class Chronicles { | ||
final String package; | ||
final String version; | ||
final Level level; | ||
final List<Chapter> chapters; | ||
|
||
Chronicles(this.package, this.version, this.level, this.chapters); | ||
|
||
@override | ||
String toString() { | ||
return ''' | ||
Chronicles(package: $package, version: $version, level: $level, chapters: $chapters)'''; | ||
} | ||
} | ||
|
||
class Chapter { | ||
final String packageName; | ||
final String packageUri; | ||
final Map<Level, bool> successBefore; | ||
final Map<Level, bool> successAfter; | ||
|
||
Chapter( | ||
this.packageName, | ||
this.packageUri, | ||
this.successBefore, | ||
this.successAfter, | ||
); | ||
|
||
@override | ||
String toString() { | ||
return ''' | ||
Chapter(packageName: $packageName, packageUri: $packageUri, successBefore: $successBefore, successAfter: $successAfter)'''; | ||
} | ||
} | ||
|
||
class Quest { | ||
final String candidatePackage; | ||
final String version; | ||
final Level level; | ||
|
||
Quest(this.candidatePackage, this.version, this.level); | ||
|
||
Future<Chronicles> embark() async { | ||
final chapters = <Chapter>[]; | ||
for (var repository in await getRepositories()) { | ||
final applicationName = await cloneRepo(repository); | ||
print('Cloned $repository'); | ||
final processResult = await Process.run('flutter', [ | ||
'pub', | ||
'deps', | ||
'--json', | ||
], workingDirectory: applicationName); | ||
final depsListResult = processResult.stdout as String; | ||
final depsJson = jsonDecode(depsListResult) as Map<String, dynamic>; | ||
final depsPackages = depsJson['packages'] as List; | ||
print(depsPackages); | ||
if (depsPackages.any((p) => (p as Map)['name'] == candidatePackage)) { | ||
print('Run checks for vanilla package'); | ||
final successBefore = await runChecks(applicationName, level); | ||
|
||
print('Clean repo'); | ||
await runFlutter(['clean'], applicationName); | ||
|
||
print('Rev package:$candidatePackage to version $version $repository'); | ||
final revSuccess = await runFlutter([ | ||
'pub', | ||
'add', | ||
"$candidatePackage:'$version'", | ||
], applicationName); | ||
|
||
print('Run checks for modified package'); | ||
final successAfter = await runChecks(applicationName, level); | ||
successAfter.update( | ||
Level.solve, | ||
(value) => value ? revSuccess : value, | ||
ifAbsent: () => revSuccess, | ||
); | ||
chapters.add( | ||
Chapter(applicationName, repository, successBefore, successAfter), | ||
); | ||
} else { | ||
print('No package:$candidatePackage found in $repository'); | ||
} | ||
} | ||
return Chronicles(candidatePackage, version, level, chapters); | ||
} | ||
|
||
Future<Iterable<String>> getRepositories() async => | ||
await File( | ||
const String.fromEnvironment('REPOSITORIES_FILE'), | ||
).readAsLines(); | ||
|
||
Future<String> cloneRepo(String repository) async { | ||
var applicationName = repository.split('/').last; | ||
if (Directory(applicationName).existsSync()) { | ||
applicationName = '${applicationName}_${repository.hashCode}'; | ||
} | ||
await Process.run('gh', [ | ||
'repo', | ||
'clone', | ||
repository, | ||
'--', | ||
applicationName, | ||
]); | ||
return applicationName; | ||
} | ||
|
||
Future<Map<Level, bool>> runChecks(String currentPackage, Level level) async { | ||
final success = <Level, bool>{}; | ||
success[Level.solve] = await runFlutter(['pub', 'get'], currentPackage); | ||
if (level.index >= Level.analyze.index) { | ||
success[Level.analyze] = await runFlutter(['analyze'], currentPackage); | ||
} | ||
if (level.index >= Level.test.index) { | ||
success[Level.test] = await runFlutter(['test'], currentPackage); | ||
} | ||
return success; | ||
} | ||
|
||
Future<bool> runFlutter(List<String> arguments, String currentPackage) async { | ||
final processResult = await Process.run( | ||
'flutter', | ||
arguments, | ||
workingDirectory: currentPackage, | ||
); | ||
print('${processResult.stdout}'); | ||
print('${processResult.stderr}'); | ||
return processResult.exitCode == 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: quest | ||
description: A sample command-line application. | ||
version: 1.0.0 | ||
# repository: https://github.com/my_org/my_repo | ||
|
||
environment: | ||
sdk: ^3.7.0-129.0.dev | ||
|
||
# Add regular dependencies here. | ||
dependencies: | ||
|
||
dev_dependencies: | ||
dart_flutter_team_lints: ^3.0.0 | ||
test: ^1.24.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:test/test.dart'; | ||
|
||
import '../bin/quest.dart'; | ||
|
||
void main() { | ||
test('test name', () async { | ||
final chronicles = | ||
await FakeQuest('intl', '^0.20.0', Level.analyze).embark(); | ||
print(chronicles); | ||
}, timeout: const Timeout(Duration(minutes: 5))); | ||
} | ||
|
||
class FakeQuest extends Quest { | ||
final locations = { | ||
'https://github.com/mosuem/my_app_old_web': | ||
'/home/mosum/projects/ecosystem_testing/my_app_old_web/', | ||
'https://github.com/mosuem/my_app_new_web': | ||
'/home/mosum/projects/ecosystem_testing/my_app_new_web/', | ||
}; | ||
|
||
FakeQuest(super.candidatePackage, super.version, super.level); | ||
|
||
@override | ||
Future<String> cloneRepo(String repository) async { | ||
return locations[repository]!; | ||
} | ||
|
||
@override | ||
Future<Iterable<String>> getRepositories() async => <String>[ | ||
'https://github.com/mosuem/my_app_old_web', | ||
'https://github.com/mosuem/my_app_new_web', | ||
]; | ||
} |