Skip to content

Commit

Permalink
Add ignore flag to health workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Jan 8, 2024
1 parent f87e6f4 commit 0c31c59
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/health_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ on:
type: boolean
required: false
use-flutter:
description: >-
Whether to setup Flutter in this workflow.
description: Whether to setup Flutter in this workflow.
default: false
required: false
type: boolean
ignore:
description: The files to ignore for this check.
required: false
type: string

jobs:
health:
Expand Down Expand Up @@ -109,7 +112,14 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_NUMBER: ${{ github.event.number }}
PR_LABELS: "${{ join(github.event.pull_request.labels.*.name) }}"
run: cd current_repo/ && dart pub global run firehose:health --check ${{ inputs.check }} ${{ fromJSON('{"true":"--coverage_web","false":""}')[inputs.coverage_web] }} --fail_on ${{ inputs.fail_on }} --warn_on ${{ inputs.warn_on }}
run: |
cd current_repo/ && \
dart pub global run firehose:health \
--check ${{ inputs.check }} \
${{ fromJSON('{"true":"--coverage_web","false":""}')[inputs.coverage_web] }} \
--fail_on ${{ inputs.fail_on }} \
--warn_on ${{ inputs.warn_on }} \
--ignore ${{ inputs.ignore }}
- name: Upload coverage to Coveralls
if: ${{ inputs.upload_coverage }}
Expand Down
7 changes: 6 additions & 1 deletion pkgs/firehose/bin/health.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ void main(List<String> arguments) async {
allowed: checkTypes,
help: 'Check PR health.',
)
..addMultiOption(
'ignore',
help: 'Check PR health.',
)
..addMultiOption(
'warn_on',
allowed: checkTypes,
Expand All @@ -32,11 +36,12 @@ void main(List<String> arguments) async {
var check = parsedArgs['check'] as String;
var warnOn = parsedArgs['warn_on'] as List<String>;
var failOn = parsedArgs['fail_on'] as List<String>;
var ignore = parsedArgs['ignore'] as List<String>;
var coverageWeb = parsedArgs['coverage_web'] as bool;
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)
await Health(Directory.current, check, warnOn, failOn, coverageWeb, ignore)
.healthCheck();
}
7 changes: 5 additions & 2 deletions pkgs/firehose/lib/src/health/health.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ class Health {
this.warnOn,
this.failOn,
this.coverageweb,
);
List<String> ignored,
) : ignoredFiles = ignored.map(RegExp.new).toList();
final github = GithubApi();

final String check;
final List<String> warnOn;
final List<String> failOn;
final bool coverageweb;
final List<RegExp> ignoredFiles;

Future<void> healthCheck() async {
// Do basic validation of our expected env var.
Expand Down Expand Up @@ -206,7 +208,8 @@ ${changeForPackage.entries.map((e) => '|${e.key.name}|${e.value.toMarkdownRow()}

Future<HealthCheckResult> licenseCheck() async {
var files = await github.listFilesForPR();
var allFilePaths = await getFilesWithoutLicenses(Directory.current);
var allFilePaths =
await getFilesWithoutLicenses(Directory.current, ignoredFiles);

var groupedPaths = allFilePaths
.groupListsBy((path) => files.any((f) => f.relativePath == path));
Expand Down
10 changes: 7 additions & 3 deletions pkgs/firehose/lib/src/health/license.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

import 'dart:io';

import 'package:collection/collection.dart';
import 'package:path/path.dart' as path;

final license = '''
// Copyright (c) ${DateTime.now().year}, 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.''';

Future<List<String>> getFilesWithoutLicenses(Directory repositoryDir) async {
Future<List<String>> getFilesWithoutLicenses(
Directory repositoryDir, List<RegExp> ignoredFiles) async {
var dartFiles = await repositoryDir
.list(recursive: true)
.where((f) => f.path.endsWith('.dart'))
Expand All @@ -24,8 +26,10 @@ Future<List<String>> getFilesWithoutLicenses(Directory repositoryDir) async {
if (!fileContainsCopyright) {
var relativePath =
path.relative(file.path, from: Directory.current.path);
print(relativePath);
return relativePath;
if (ignoredFiles.none((regex) => regex.hasMatch(relativePath))) {
print(relativePath);
return relativePath;
}
}
})
.whereType<String>()
Expand Down
2 changes: 1 addition & 1 deletion pkgs/firehose/test/license_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {

test('Check for licenses', () async {
var filesWithoutLicenses =
await getFilesWithoutLicenses(Directory('test/'));
await getFilesWithoutLicenses(Directory('test/'), []);
expect(filesWithoutLicenses, [fileWithoutLicense.path]);
});

Expand Down

0 comments on commit 0c31c59

Please sign in to comment.