diff --git a/pkgs/firehose/CHANGELOG.md b/pkgs/firehose/CHANGELOG.md index 9db228f7..51cefaab 100644 --- a/pkgs/firehose/CHANGELOG.md +++ b/pkgs/firehose/CHANGELOG.md @@ -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. diff --git a/pkgs/firehose/lib/src/health/coverage.dart b/pkgs/firehose/lib/src/health/coverage.dart index c4d76781..e128d611 100644 --- a/pkgs/firehose/lib/src/health/coverage.dart +++ b/pkgs/firehose/lib/src/health/coverage.dart @@ -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 diff --git a/pkgs/firehose/lib/src/health/license.dart b/pkgs/firehose/lib/src/health/license.dart index 18a1e433..ae39d2e5 100644 --- a/pkgs/firehose/lib/src/health/license.dart +++ b/pkgs/firehose/lib/src/health/license.dart @@ -26,8 +26,8 @@ Future> 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; } @@ -40,3 +40,13 @@ Future> 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)'); diff --git a/pkgs/firehose/pubspec.yaml b/pkgs/firehose/pubspec.yaml index 069929f6..0d545f27 100644 --- a/pkgs/firehose/pubspec.yaml +++ b/pkgs/firehose/pubspec.yaml @@ -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: diff --git a/pkgs/firehose/test_data/golden/comment_license.md b/pkgs/firehose/test_data/golden/comment_license.md index c671aa72..dad0bda3 100644 --- a/pkgs/firehose/test_data/golden/comment_license.md +++ b/pkgs/firehose/test_data/golden/comment_license.md @@ -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). diff --git a/pkgs/firehose/test_data/golden/comment_license_healthchanged.md b/pkgs/firehose/test_data/golden/comment_license_healthchanged.md index 16e04cb8..e6665d9f 100644 --- a/pkgs/firehose/test_data/golden/comment_license_healthchanged.md +++ b/pkgs/firehose/test_data/golden/comment_license_healthchanged.md @@ -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| diff --git a/pkgs/firehose/test_data/golden/comment_license_ignore_license.md b/pkgs/firehose/test_data/golden/comment_license_ignore_license.md index 3903f9e1..e8a133df 100644 --- a/pkgs/firehose/test_data/golden/comment_license_ignore_license.md +++ b/pkgs/firehose/test_data/golden/comment_license_ignore_license.md @@ -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). diff --git a/pkgs/firehose/test_data/golden/comment_license_ignore_package.md b/pkgs/firehose/test_data/golden/comment_license_ignore_package.md index 8a6f79a2..abe5b046 100644 --- a/pkgs/firehose/test_data/golden/comment_license_ignore_package.md +++ b/pkgs/firehose/test_data/golden/comment_license_ignore_package.md @@ -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). diff --git a/pkgs/firehose/test_data/test_repo/pkgs/package2/lib/anotherLib.dart b/pkgs/firehose/test_data/test_repo/pkgs/package2/lib/anotherLib.dart index af52fa18..5bee8739 100644 --- a/pkgs/firehose/test_data/test_repo/pkgs/package2/lib/anotherLib.dart +++ b/pkgs/firehose/test_data/test_repo/pkgs/package2/lib/anotherLib.dart @@ -1,3 +1,6 @@ +// SOME COMMENT +// THIS IS A GENERATED FILE + int calculateUnused() { return 6 * 7; }