Skip to content

Commit

Permalink
Don't check licenses of generated files (#326)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mosuem authored Dec 16, 2024
1 parent 3339020 commit d2dd4ce
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions pkgs/firehose/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.2-wip

- Don't check licenses of generated files in PR health workflow.

## 0.10.1

- Small fixes to the PR health checker.
Expand Down
4 changes: 3 additions & 1 deletion pkgs/firehose/lib/src/health/coverage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ class Coverage {
.where((file) => file.status != FileStatus.removed)
.where((file) => isInSomePackage(packages, file.filename))
.where((file) => isNotATest(packages, file.filename))
.where(
(file) => ignoredFiles.none((glob) => glob.matches(file.filename)))
.toList();
print('The files of interest are $filesOfInterest');

var baseRepository = Repository(base);
var basePackages = baseRepository.locatePackages(ignore: ignoredFiles);
var basePackages = baseRepository.locatePackages(ignore: ignoredPackages);
print('Found packages $basePackages at $base');

var changedPackages = packages
Expand Down
14 changes: 12 additions & 2 deletions pkgs/firehose/lib/src/health/license.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Future<List<String>> getFilesWithoutLicenses(
if (ignoredFiles.none((glob) =>
glob.matches(path.relative(file.path, from: repositoryDir.path)))) {
var fileContents = File(file.path).readAsStringSync();
var fileContainsCopyright = fileContents.contains('// Copyright (c)');
if (!fileContainsCopyright) {
if (!fileIsGenerated(fileContents, file.path) &&
!fileContainsCopyright(fileContents)) {
print(relativePath);
return relativePath;
}
Expand All @@ -40,3 +40,13 @@ Future<List<String>> getFilesWithoutLicenses(
Done, found ${filesWithoutLicenses.length} files without license headers''');
return filesWithoutLicenses;
}

bool fileIsGenerated(String fileContents, String path) =>
path.endsWith('g.dart') ||
fileContents
.split('\n')
.takeWhile((line) => line.startsWith('//') || line.isEmpty)
.any((line) => line.toLowerCase().contains('generate'));

bool fileContainsCopyright(String fileContents) =>
fileContents.contains('// Copyright (c)');
2 changes: 1 addition & 1 deletion pkgs/firehose/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: firehose
description: A tool to automate publishing of Pub packages from GitHub actions.
version: 0.10.1
version: 0.10.2-wip
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose

environment:
Expand Down
1 change: 0 additions & 1 deletion pkgs/firehose/test_data/golden/comment_license.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
| Files |
| :--- |
|pkgs/package1/bin/package1.dart|
|pkgs/package2/lib/anotherLib.dart|
|pkgs/package5/lib/src/package5_base.dart|

All source files should start with a [license header](https://github.com/dart-lang/ecosystem/wiki/License-Header).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
|pkgs/package1/bin/package1.dart|
|pkgs/package1/lib/package1.dart|
|pkgs/package1/test/package1_test.dart|
|pkgs/package2/lib/anotherLib.dart|
|pkgs/package2/lib/package2.dart|
|pkgs/package2/test/package2_test.dart|
|pkgs/package3/bin/package3.dart|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
| Files |
| :--- |
|pkgs/package1/bin/package1.dart|
|pkgs/package2/lib/anotherLib.dart|
|pkgs/package5/lib/src/package5_base.dart|

All source files should start with a [license header](https://github.com/dart-lang/ecosystem/wiki/License-Header).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

| Files |
| :--- |
|pkgs/package2/lib/anotherLib.dart|
|pkgs/package5/lib/src/package5_base.dart|

All source files should start with a [license header](https://github.com/dart-lang/ecosystem/wiki/License-Header).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SOME COMMENT
// THIS IS A GENERATED FILE

int calculateUnused() {
return 6 * 7;
}

0 comments on commit d2dd4ce

Please sign in to comment.