-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhealth.dart
88 lines (84 loc) · 2.73 KB
/
health.dart
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:args/args.dart';
import 'package:firehose/src/github.dart';
import 'package:firehose/src/health/health.dart';
void main(List<String> arguments) async {
var checkTypes = Check.values.map((c) => c.name);
var argParser = ArgParser()
..addOption(
'check',
allowed: checkTypes,
help: 'Check PR health.',
)
..addMultiOption(
'ignore_packages',
defaultsTo: [],
help: 'Which packages to ignore.',
)
..addMultiOption(
'ignore_license',
defaultsTo: [],
help: 'Which files to ignore for the license check.',
)
..addMultiOption(
'ignore_coverage',
defaultsTo: [],
help: 'Which files to ignore for the coverage check.',
)
..addMultiOption(
'warn_on',
allowed: checkTypes,
help: 'Which checks to display warnings on',
)
..addMultiOption(
'fail_on',
allowed: checkTypes,
help: 'Which checks should lead to workflow failure',
)
..addMultiOption(
'experiments',
help: 'Which experiments should be enabled for Dart',
)
..addFlag(
'coverage_web',
help: 'Whether to run web tests for coverage',
)
..addMultiOption(
'flutter_packages',
defaultsTo: [],
help: 'The Flutter packages in this repo',
);
final parsedArgs = argParser.parse(arguments);
final checkStr = parsedArgs.option('check');
final check = Check.values.firstWhere((c) => c.name == checkStr);
final warnOn = parsedArgs.multiOption('warn_on');
final failOn = parsedArgs.multiOption('fail_on');
final flutterPackages = _listNonEmpty(parsedArgs, 'flutter_packages');
final ignorePackages = _listNonEmpty(parsedArgs, 'ignore_packages');
final ignoreLicense = _listNonEmpty(parsedArgs, 'ignore_license');
final ignoreCoverage = _listNonEmpty(parsedArgs, 'ignore_coverage');
final experiments = _listNonEmpty(parsedArgs, 'experiments');
final coverageWeb = parsedArgs.flag('coverage_web');
if (warnOn.toSet().intersection(failOn.toSet()).isNotEmpty) {
throw ArgumentError('The checks for which warnings are displayed and the '
'checks which lead to failure must be disjoint.');
}
await Health(
Directory.current,
check,
warnOn,
failOn,
coverageWeb,
ignorePackages,
ignoreLicense,
ignoreCoverage,
experiments,
GithubApi(),
flutterPackages,
).healthCheck();
}
List<String> _listNonEmpty(ArgResults parsedArgs, String key) =>
(parsedArgs[key] as List<String>).where((e) => e.isNotEmpty).toList();