-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Expand file tree
/
Copy pathci_script.dart
More file actions
72 lines (63 loc) · 2.14 KB
/
ci_script.dart
File metadata and controls
72 lines (63 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import 'dart:io';
import 'package:path/path.dart' as path;
import 'package:yaml/yaml.dart';
Future<void> main() async {
final rootDir = Directory.current;
final pubspecFile = File(path.join(rootDir.path, 'pubspec.yaml'));
final pubspecContent = await pubspecFile.readAsString();
final pubspecYaml = loadYaml(pubspecContent);
final workspace = pubspecYaml['workspace'] as YamlList?;
if (workspace == null) {
print('No workspace found in pubspec.yaml');
exit(1);
}
final skipCiList = pubspecYaml['skip_ci'] as YamlList?;
// pub workspace, only run 'get' once
await _runCommand('flutter', ['pub', 'get'], workingDirectory: rootDir.path);
final packages = workspace
.where((e) => skipCiList == null || !skipCiList.contains(e))
.map((e) => e.toString())
.toList();
for (final package in packages) {
final packagePath = path.join(rootDir.path, package);
print('== Testing \'$package\' ==');
await _runCommand('dart', [
'analyze',
'--fatal-infos',
'--fatal-warnings',
], workingDirectory: packagePath);
await _runCommand('dart', ['format', '.'], workingDirectory: packagePath);
if (await Directory(path.join(packagePath, 'test')).exists()) {
final packagePubspecFile = File(path.join(packagePath, 'pubspec.yaml'));
final packagePubspecContent = await packagePubspecFile.readAsString();
if (packagePubspecContent.contains('flutter:')) {
await _runCommand('flutter', [
'test',
'--no-pub',
], workingDirectory: packagePath);
} else {
await _runCommand('dart', ['test'], workingDirectory: packagePath);
}
}
}
}
Future<void> _runCommand(
String executable,
List<String> arguments, {
String? workingDirectory,
}) async {
final process = await Process.start(
executable,
arguments,
workingDirectory: workingDirectory,
runInShell: true,
mode: ProcessStartMode.inheritStdio,
);
final exitCode = await process.exitCode;
if (exitCode != 0) {
print(
'Command "$executable ${arguments.join(' ')}" failed with exit code $exitCode in $workingDirectory',
);
exit(exitCode);
}
}