Skip to content
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

improve ci utils and fix analyzer lower bound #197

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading