Skip to content

Commit 9ee08a4

Browse files
authored
Add ignore flag to health workflows (#218)
* Add `ignore` flag to health workflows * Switch to glob * Fix multiline * Add default glob * Delete multiline * Fix errors * Fix health commenting * Propagate ignore * Switch to specific ignores * Add defaults * Add test repos * Start adding health tests * Add golden files * Fix changelog * Fix coverage * Fix breaking * More fixes * Merge * Fixes * Move * Fix tests * Ignore test data licenses * Add golden without license * Fix license * Rename * Fix * Fix analyze issue * Add args printing * Add defaults * Add more defaults * Remove empty * Match recursive * Add docs * Add link to docs
1 parent a283d70 commit 9ee08a4

24 files changed

+454
-98
lines changed

.github/workflows/health.yaml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# A CI configuration to check PR health.
1+
# A CI configuration to check PR health. Check the docs at https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose#health.
22

33
name: Health
44

@@ -27,7 +27,13 @@ name: Health
2727
# coverage_web: false
2828
# upload_coverage: false
2929
# use-flutter: true
30-
30+
# use-flutter: true
31+
# use-flutter: true
32+
# ignore_license: "**.g.dart"
33+
# ignore_coverage: "**.mock.dart,**.g.dart"
34+
# ignore_packages: "pkgs/helper_package"
35+
# checkout_submodules: false
36+
# experiments: "native-assets"
3137

3238
on:
3339
workflow_call:
@@ -82,6 +88,21 @@ on:
8288
default: false
8389
required: false
8490
type: boolean
91+
ignore_license:
92+
description: Which files to ignore for the license check.
93+
default: "\"\""
94+
required: false
95+
type: string
96+
ignore_coverage:
97+
description: Which files to ignore for the coverage check.
98+
default: "\"\""
99+
required: false
100+
type: string
101+
ignore_packages:
102+
description: Which packages to ignore.
103+
default: "\"\""
104+
required: false
105+
type: string
85106
checkout_submodules:
86107
description: Whether to checkout submodules of git repositories.
87108
default: false
@@ -104,6 +125,7 @@ jobs:
104125
warn_on: ${{ inputs.warn_on }}
105126
local_debug: ${{ inputs.local_debug }}
106127
use-flutter: ${{ inputs.use-flutter }}
128+
ignore_packages: ${{ inputs.ignore_packages }}
107129
checkout_submodules: ${{ inputs.checkout_submodules }}
108130

109131
changelog:
@@ -116,6 +138,7 @@ jobs:
116138
warn_on: ${{ inputs.warn_on }}
117139
local_debug: ${{ inputs.local_debug }}
118140
use-flutter: ${{ inputs.use-flutter }}
141+
ignore_packages: ${{ inputs.ignore_packages }}
119142
checkout_submodules: ${{ inputs.checkout_submodules }}
120143

121144
license:
@@ -128,6 +151,8 @@ jobs:
128151
warn_on: ${{ inputs.warn_on }}
129152
local_debug: ${{ inputs.local_debug }}
130153
use-flutter: ${{ inputs.use-flutter }}
154+
ignore_license: ${{ inputs.ignore_license }}
155+
ignore_packages: ${{ inputs.ignore_packages }}
131156
checkout_submodules: ${{ inputs.checkout_submodules }}
132157

133158
coverage:
@@ -142,6 +167,8 @@ jobs:
142167
coverage_web: ${{ inputs.coverage_web }}
143168
local_debug: ${{ inputs.local_debug }}
144169
use-flutter: ${{ inputs.use-flutter }}
170+
ignore_coverage: ${{ inputs.ignore_coverage }}
171+
ignore_packages: ${{ inputs.ignore_packages }}
145172
checkout_submodules: ${{ inputs.checkout_submodules }}
146173
experiments: ${{ inputs.experiments }}
147174

@@ -155,6 +182,7 @@ jobs:
155182
warn_on: ${{ inputs.warn_on }}
156183
local_debug: ${{ inputs.local_debug }}
157184
use-flutter: ${{ inputs.use-flutter }}
185+
ignore_packages: ${{ inputs.ignore_packages }}
158186
checkout_submodules: ${{ inputs.checkout_submodules }}
159187

160188
do-not-submit:
@@ -167,6 +195,7 @@ jobs:
167195
warn_on: ${{ inputs.warn_on }}
168196
local_debug: ${{ inputs.local_debug }}
169197
use-flutter: ${{ inputs.use-flutter }}
198+
ignore_packages: ${{ inputs.ignore_packages }}
170199
checkout_submodules: ${{ inputs.checkout_submodules }}
171200

172201
comment:

.github/workflows/health_base.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ on:
4949
default: false
5050
required: false
5151
type: boolean
52+
ignore_license:
53+
description: Which files to ignore for the license check.
54+
default: "\"\""
55+
required: false
56+
type: string
57+
ignore_coverage:
58+
description: Which files to ignore for the coverage check.
59+
default: "\"\""
60+
required: false
61+
type: string
62+
ignore_packages:
63+
description: Which packages to ignore.
64+
default: "\"\""
65+
required: false
66+
type: string
5267
checkout_submodules:
5368
description: Whether to checkout submodules of git repositories.
5469
default: false
@@ -124,6 +139,9 @@ jobs:
124139
${{ fromJSON('{"true":"--coverage_web","false":""}')[inputs.coverage_web] }} \
125140
--fail_on ${{ inputs.fail_on }} \
126141
--warn_on ${{ inputs.warn_on }} \
142+
--ignore_license ${{ inputs.ignore_license }} \
143+
--ignore_coverage ${{ inputs.ignore_coverage }} \
144+
--ignore_packages ${{ inputs.ignore_packages }} \
127145
--experiments ${{ inputs.experiments }}
128146
129147
- run: test -f current_repo/output/comment.md || echo $'The ${{ inputs.check }} workflow has encountered an exception and did not complete.' >> current_repo/output/comment.md

.github/workflows/health_internal.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ jobs:
1515
checks: version,changelog,license,coverage,breaking,do-not-submit
1616
fail_on: version,changelog,do-not-submit
1717
warn_on: license,coverage,breaking
18+
ignore_license: 'pkgs/firehose/test_data'
19+
ignore_coverage: 'pkgs/firehose/bin'

pkgs/firehose/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.1
2+
3+
- Add `ignore` flags to the health workflow.
4+
15
## 0.6.0
26

37
- Make the health workflow testable with golden tests.

pkgs/firehose/README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,12 @@ This is a Github workflow to check PR health.
160160

161161
When run from a PR, this tool will check a configurable subset of the following
162162

163-
* If the package versioning is correct and consistent, see `firehose` description above.
164-
* If a changelog entry has been added.
165-
* If all `.dart` files have a license header.
163+
* The package versioning is correct and consistent, see `firehose` description above.
164+
* A changelog entry has been added.
165+
* All `.dart` files have a license header.
166166
* How the test coverage is affected by the PR.
167+
* The package versioning takes into account any breaking changes in the PR.
168+
* The PR contains `DO_NOT_SUBMIT` strings in the files or the description.
167169

168170
This tool can work with either single package repos or with mono-repos (repos
169171
containing several packages).
@@ -186,6 +188,22 @@ jobs:
186188
# checks: "version,changelog,license,coverage"
187189
```
188190

191+
### Options
192+
193+
| Name | Type | Description | Example |
194+
| ------------- | ------------- | ------------- | ------------- |
195+
| checks | List of strings | What to check for in the PR health check | `"version,changelog,license,coverage,breaking,do-not-submit"` |
196+
| fail_on | List of strings | Which checks should lead to failure | `"version,changelog,do-not-submit"` |
197+
| warn_on | List of strings | Which checks should not fail, but only warn | `"license,coverage,breaking"` |
198+
| upload_coverage | boolean | Whether to upload the coverage to [coveralls](https://coveralls.io/) | `true` |
199+
| coverage_web | boolean | Whether to run `dart test -p chrome` for coverage | `false` |
200+
| use-flutter | boolean | Whether to setup Flutter in this workflow | `false` |
201+
| ignore_license | List of globs | | `"**.g.dart"` |
202+
| ignore_coverage | List of globs | Which files to ignore for the license check | `"**.mock.dart,**.g.dart"` |
203+
| ignore_packages | List of globs | Which packages to ignore | `"pkgs/helper_package"` |
204+
| checkout_submodules | boolean | Whether to checkout submodules of git repositories | `false` |
205+
| experiments | List of strings | Which experiments should be enabled for Dart | `"native-assets"` |
206+
189207
### Workflow docs
190208

191209
The description of the common workflow for repos using this tool can be found at

pkgs/firehose/bin/health.dart

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ void main(List<String> arguments) async {
1515
allowed: checkTypes,
1616
help: 'Check PR health.',
1717
)
18+
..addMultiOption(
19+
'ignore_packages',
20+
defaultsTo: [],
21+
help: 'Which packages to ignore.',
22+
)
23+
..addMultiOption(
24+
'ignore_license',
25+
defaultsTo: [],
26+
help: 'Which files to ignore for the license check.',
27+
)
28+
..addMultiOption(
29+
'ignore_coverage',
30+
defaultsTo: [],
31+
help: 'Which files to ignore for the coverage check.',
32+
)
1833
..addMultiOption(
1934
'warn_on',
2035
allowed: checkTypes,
@@ -33,14 +48,15 @@ void main(List<String> arguments) async {
3348
'coverage_web',
3449
help: 'Whether to run web tests for coverage',
3550
);
36-
var parsedArgs = argParser.parse(arguments);
37-
var check = parsedArgs['check'] as String;
38-
var warnOn = parsedArgs['warn_on'] as List<String>;
39-
var failOn = parsedArgs['fail_on'] as List<String>;
40-
var experiments = (parsedArgs['experiments'] as List<String>)
41-
.where((name) => name.isNotEmpty)
42-
.toList();
43-
var coverageWeb = parsedArgs['coverage_web'] as bool;
51+
final parsedArgs = argParser.parse(arguments);
52+
final check = parsedArgs['check'] as String;
53+
final warnOn = parsedArgs['warn_on'] as List<String>;
54+
final failOn = parsedArgs['fail_on'] as List<String>;
55+
final ignorePackages = _listNonEmpty(parsedArgs, 'ignore_packages');
56+
final ignoreLicense = _listNonEmpty(parsedArgs, 'ignore_license');
57+
final ignoreCoverage = _listNonEmpty(parsedArgs, 'ignore_coverage');
58+
final experiments = _listNonEmpty(parsedArgs, 'experiments');
59+
final coverageWeb = parsedArgs['coverage_web'] as bool;
4460
if (warnOn.toSet().intersection(failOn.toSet()).isNotEmpty) {
4561
throw ArgumentError('The checks for which warnings are displayed and the '
4662
'checks which lead to failure must be disjoint.');
@@ -51,7 +67,13 @@ void main(List<String> arguments) async {
5167
warnOn,
5268
failOn,
5369
coverageWeb,
70+
ignorePackages,
71+
ignoreLicense,
72+
ignoreCoverage,
5473
experiments,
5574
GithubApi(),
5675
).healthCheck();
5776
}
77+
78+
List<String> _listNonEmpty(ArgResults parsedArgs, String key) =>
79+
(parsedArgs[key] as List<String>).where((e) => e.isNotEmpty).toList();

pkgs/firehose/lib/firehose.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import 'dart:io';
88
import 'dart:math';
99

10+
import 'package:glob/glob.dart';
11+
1012
import 'src/github.dart';
1113
import 'src/pub.dart';
1214
import 'src/repo.dart';
@@ -90,9 +92,12 @@ Saving existing comment id $existingCommentId to file ${idFile.path}''');
9092
github.close();
9193
}
9294

93-
Future<VerificationResults> verify(GithubApi github) async {
95+
Future<VerificationResults> verify(
96+
GithubApi github, [
97+
List<Glob> ignoredPackages = const [],
98+
]) async {
9499
var repo = Repository(directory);
95-
var packages = repo.locatePackages();
100+
var packages = repo.locatePackages(ignoredPackages);
96101

97102
var pub = Pub();
98103

pkgs/firehose/lib/src/github.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
import 'dart:io';
77

8+
import 'package:collection/collection.dart';
89
import 'package:github/github.dart';
10+
import 'package:glob/glob.dart';
911
import 'package:http/http.dart' as http;
1012
import 'package:path/path.dart' as path;
1113

@@ -107,14 +109,19 @@ class GithubApi {
107109
return matchingComment?.id;
108110
}
109111

110-
Future<List<GitFile>> listFilesForPR(Directory directory) async =>
112+
Future<List<GitFile>> listFilesForPR(
113+
Directory directory, [
114+
List<Glob> ignoredFiles = const [],
115+
]) async =>
111116
await _github.pullRequests
112117
.listFiles(repoSlug!, issueNumber!)
113118
.map((prFile) => GitFile(
114119
prFile.filename!,
115120
FileStatus.fromString(prFile.status!),
116121
directory,
117122
))
123+
.where((file) =>
124+
ignoredFiles.none((glob) => glob.matches(file.filename)))
118125
.toList();
119126

120127
/// Write a notice message to the github log.
@@ -135,9 +142,8 @@ class GitFile {
135142
final FileStatus status;
136143
final Directory directory;
137144

138-
bool isInPackage(Package package) {
139-
return path.isWithin(package.directory.path, pathInRepository);
140-
}
145+
bool isInPackage(Package package) =>
146+
path.isWithin(package.directory.path, pathInRepository);
141147

142148
String get pathInRepository => path.join(directory.path, filename);
143149

pkgs/firehose/lib/src/health/changelog.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44

55
import 'dart:io';
66

7+
import 'package:glob/glob.dart';
78
import 'package:path/path.dart' as path;
89

910
import '../github.dart';
1011
import '../repo.dart';
1112

1213
Future<Map<Package, List<GitFile>>> packagesWithoutChangelog(
1314
GithubApi github,
15+
List<Glob> ignoredPackages,
1416
Directory directory,
1517
) async {
1618
final repo = Repository(directory);
17-
final packages = repo.locatePackages();
19+
final packages = repo.locatePackages(ignoredPackages);
1820

19-
final files = await github.listFilesForPR(directory);
21+
final files = await github.listFilesForPR(directory, ignoredPackages);
2022

2123
var packagesWithoutChangedChangelog = collectPackagesWithoutChangelogChanges(
2224
packages,

0 commit comments

Comments
 (0)