Skip to content

Commit d2dd4ce

Browse files
authored
Don't check licenses of generated files (#326)
To avoid having to exclude many files, don't check the licenses of auto generated files. These are recognized by the word `generate` appearing somewhere in the leading comment lines. --- - [x] I’ve reviewed the contributor guide and applied the relevant portions to this PR. <details> <summary>Contribution guidelines:</summary><br> - See our [contributor guide](https://github.com/dart-lang/.github/blob/main/CONTRIBUTING.md) for general expectations for PRs. - Larger or significant changes should be discussed in an issue before creating a PR. - Contributions to our repos should follow the [Dart style guide](https://dart.dev/guides/language/effective-dart) and use `dart format`. - Most changes should add an entry to the changelog and may need to [rev the pubspec package version](https://github.com/dart-lang/sdk/blob/main/docs/External-Package-Maintenance.md#making-a-change). - Changes to packages require [corresponding tests](https://github.com/dart-lang/.github/blob/main/CONTRIBUTING.md#Testing). Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback. </details>
1 parent 3339020 commit d2dd4ce

File tree

9 files changed

+23
-8
lines changed

9 files changed

+23
-8
lines changed

pkgs/firehose/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.10.2-wip
2+
3+
- Don't check licenses of generated files in PR health workflow.
4+
15
## 0.10.1
26

37
- Small fixes to the PR health checker.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ class Coverage {
4141
.where((file) => file.status != FileStatus.removed)
4242
.where((file) => isInSomePackage(packages, file.filename))
4343
.where((file) => isNotATest(packages, file.filename))
44+
.where(
45+
(file) => ignoredFiles.none((glob) => glob.matches(file.filename)))
4446
.toList();
4547
print('The files of interest are $filesOfInterest');
4648

4749
var baseRepository = Repository(base);
48-
var basePackages = baseRepository.locatePackages(ignore: ignoredFiles);
50+
var basePackages = baseRepository.locatePackages(ignore: ignoredPackages);
4951
print('Found packages $basePackages at $base');
5052

5153
var changedPackages = packages

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Future<List<String>> getFilesWithoutLicenses(
2626
if (ignoredFiles.none((glob) =>
2727
glob.matches(path.relative(file.path, from: repositoryDir.path)))) {
2828
var fileContents = File(file.path).readAsStringSync();
29-
var fileContainsCopyright = fileContents.contains('// Copyright (c)');
30-
if (!fileContainsCopyright) {
29+
if (!fileIsGenerated(fileContents, file.path) &&
30+
!fileContainsCopyright(fileContents)) {
3131
print(relativePath);
3232
return relativePath;
3333
}
@@ -40,3 +40,13 @@ Future<List<String>> getFilesWithoutLicenses(
4040
Done, found ${filesWithoutLicenses.length} files without license headers''');
4141
return filesWithoutLicenses;
4242
}
43+
44+
bool fileIsGenerated(String fileContents, String path) =>
45+
path.endsWith('g.dart') ||
46+
fileContents
47+
.split('\n')
48+
.takeWhile((line) => line.startsWith('//') || line.isEmpty)
49+
.any((line) => line.toLowerCase().contains('generate'));
50+
51+
bool fileContainsCopyright(String fileContents) =>
52+
fileContents.contains('// Copyright (c)');

pkgs/firehose/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: firehose
22
description: A tool to automate publishing of Pub packages from GitHub actions.
3-
version: 0.10.1
3+
version: 0.10.2-wip
44
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose
55

66
environment:

pkgs/firehose/test_data/golden/comment_license.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
| Files |
1313
| :--- |
1414
|pkgs/package1/bin/package1.dart|
15-
|pkgs/package2/lib/anotherLib.dart|
1615
|pkgs/package5/lib/src/package5_base.dart|
1716

1817
All source files should start with a [license header](https://github.com/dart-lang/ecosystem/wiki/License-Header).

pkgs/firehose/test_data/golden/comment_license_healthchanged.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
|pkgs/package1/bin/package1.dart|
1515
|pkgs/package1/lib/package1.dart|
1616
|pkgs/package1/test/package1_test.dart|
17-
|pkgs/package2/lib/anotherLib.dart|
1817
|pkgs/package2/lib/package2.dart|
1918
|pkgs/package2/test/package2_test.dart|
2019
|pkgs/package3/bin/package3.dart|

pkgs/firehose/test_data/golden/comment_license_ignore_license.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
| Files |
1313
| :--- |
1414
|pkgs/package1/bin/package1.dart|
15-
|pkgs/package2/lib/anotherLib.dart|
1615
|pkgs/package5/lib/src/package5_base.dart|
1716

1817
All source files should start with a [license header](https://github.com/dart-lang/ecosystem/wiki/License-Header).

pkgs/firehose/test_data/golden/comment_license_ignore_package.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
| Files |
1313
| :--- |
14-
|pkgs/package2/lib/anotherLib.dart|
1514
|pkgs/package5/lib/src/package5_base.dart|
1615

1716
All source files should start with a [license header](https://github.com/dart-lang/ecosystem/wiki/License-Header).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// SOME COMMENT
2+
// THIS IS A GENERATED FILE
3+
14
int calculateUnused() {
25
return 6 * 7;
36
}

0 commit comments

Comments
 (0)