Skip to content

Commit

Permalink
improve ci utils and fix analyzer lower bound (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmil authored Nov 27, 2024
1 parent 4c6014b commit 5801c26
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Global Codeowners
* @devmil @adamgic @fwagner @fabiomcarneiro @klink182
* @devmil @adamgic @fwagner @fabiomcarneiro @klink182 @marafelismino
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ environment:
sdk: ">=3.0.0 <4.0.0"

dependencies:
analyzer: ^6.5.0
analyzer: ^6.7.0
args: ^2.3.1
collection: ^1.17.0
colorize: ^3.0.0
Expand Down
54 changes: 41 additions & 13 deletions scripts/ci_util/lib/src/check_lower_bound_dependencies_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';

import 'package:args/command_runner.dart';
import 'package:path/path.dart' as path;
import 'package:pool/pool.dart';
import 'package:pubspec_manager/pubspec_manager.dart';

class CheckLowerBoundDependenciesCommand extends Command {
Expand All @@ -21,20 +22,40 @@ class CheckLowerBoundDependenciesCommand extends Command {
final pubspec =
PubSpec.loadFromPath(path.join(apiToolRootPath, 'pubspec.yaml'));

final testFutures = pubspec.dependencies.list
final testExecutions = pubspec.dependencies.list
.whereType<DependencyVersioned>()
.map((d) async {
try {
await _testWithFixedDependency((d as Dependency).name);
} catch (e) {
return LowerBoundCheckResult(
dependencyName: (d as Dependency).name, error: e.toString());
}
return LowerBoundCheckResult(dependencyName: (d as Dependency).name);
});
final failedDependencies = (await Future.wait(testFutures))
.where((element) => element.error != null)
.toList();
.map((d) async => () async {
final dependencyName = (d as Dependency).name;
stdout.writeln('Testing lower bound of $dependencyName');
try {
await _testWithFixedDependency(dependencyName);
} catch (e) {
return LowerBoundCheckResult(
dependencyName: dependencyName, error: e.toString());
}
return LowerBoundCheckResult(dependencyName: dependencyName);
})
.toList(growable: true);

final numberOfParallelTasks = (Platform.numberOfProcessors / 2).ceil();

final pool = Pool(numberOfParallelTasks);
final failedDependencies = <LowerBoundCheckResult>[];

try {
final results = await Future.wait(
testExecutions.map((run) => pool.withResource(() async {
return (await run)();
})),
);

failedDependencies.addAll(
results.where((element) => element.error != null),
);
} finally {
pool.close();
}

if (failedDependencies.isNotEmpty) {
final errorMessage = StringBuffer();
errorMessage.writeln(
Expand All @@ -53,10 +74,15 @@ class CheckLowerBoundDependenciesCommand extends Command {
final String apiToolRootPath = _getApiToolRootPath();
final tempDir = await Directory.systemTemp.createTemp();
try {
stdout
.writeln('[$dependencyName] Copying api tool to temporary directory');
await _copyPath(apiToolRootPath, tempDir.path);
stdout.writeln('[$dependencyName] Fixing dependency');
await _fixDependency(
path.join(tempDir.path, 'pubspec.yaml'), dependencyName);
stdout.writeln('[$dependencyName] Running pub get');
await _executePubGet(tempDir.path);
stdout.writeln('[$dependencyName] Running build');
await _executeBuild(tempDir.path);
} finally {
await tempDir.delete(recursive: true);
Expand Down Expand Up @@ -116,6 +142,8 @@ class CheckLowerBoundDependenciesCommand extends Command {
castedDependency.versionConstraint =
castedDependency.versionConstraint.replaceFirst('^', '');
adaptedOne = true;
stdout.writeln(
'[$dependencyName] Fixing dependency to ${castedDependency.versionConstraint}');
}
}
if (!adaptedOne) {
Expand Down
1 change: 1 addition & 0 deletions scripts/ci_util/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ environment:
dependencies:
args: ^2.4.2
path: ^1.9.0
pool: ^1.5.1
pubspec_manager: ^1.0.0

dev_dependencies:
Expand Down

0 comments on commit 5801c26

Please sign in to comment.