Skip to content

Commit ffa1ecb

Browse files
authored
Health workflow updates (#134)
* Group unlicensed files into touched/not touched in PR * Add web test arg * Look only at packages with changelogs * Do not display unchanged license markdown conditionally * Test if `test_web` works - to be reverted * Revert "Test if `test_web` works - to be reverted" This reverts commit aa9fcf9. * Add changelog * Changes as per review * Change arg name * Propagate arg name change
1 parent 2052a4c commit ffa1ecb

File tree

10 files changed

+99
-29
lines changed

10 files changed

+99
-29
lines changed

.github/workflows/health.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ name: Health
1212
# jobs:
1313
# health:
1414
# uses: dart-lang/ecosystem/.github/workflows/health.yaml@main
15+
# with:
16+
# coverage_web: true #If the coverage should run browser tests
1517

1618
# Callers may optionally specify the version of the SDK to use when running the
1719
# health check. This can be useful if your package has a very recent minimum SDK
@@ -50,6 +52,16 @@ on:
5052
default: false
5153
type: boolean
5254
required: false
55+
upload_coverage:
56+
description: Whether to upload the coverage to coveralls
57+
default: true
58+
type: boolean
59+
required: false
60+
coverage_web:
61+
description: Whether to run `dart test -p chrome` for coverage
62+
default: false
63+
type: boolean
64+
required: false
5365

5466
jobs:
5567
health:
@@ -90,9 +102,10 @@ jobs:
90102
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91103
ISSUE_NUMBER: ${{ github.event.number }}
92104
PR_LABELS: "${{ join(github.event.pull_request.labels.*.name) }}"
93-
run: cd current_repo/ && dart pub global run firehose:health --checks ${{ inputs.checks }}
105+
run: cd current_repo/ && dart pub global run firehose:health --checks ${{ inputs.checks }} ${{ fromJSON('{"true":"--test_web","false":""}')[inputs.test_web] }}
94106

95107
- name: Upload coverage to Coveralls
108+
if: ${{ inputs.upload_coverage }}
96109
uses: coverallsapp/github-action@c7885c00cb7ec0b8f9f5ff3f53cddb980f7a4412
97110
with:
98111
format: lcov

.github/workflows/health_internal.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ jobs:
1010
uses: ./.github/workflows/health.yaml
1111
with:
1212
local_debug: true
13+
coverage_web: false

pkgs/firehose/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
## 0.3.23-wip
2-
1+
## 0.3.23
2+
- Tweak PR health workflow.
33
- Shorten some text in the markdown summary table.
44

55
## 0.3.22

pkgs/firehose/bin/health.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ void main(List<String> arguments) async {
1313
'checks',
1414
allowed: ['version', 'license', 'changelog', 'coverage'],
1515
help: 'Check PR health.',
16+
)
17+
..addFlag(
18+
'coverage_web',
19+
help: 'Whether to run web tests for coverage',
1620
);
1721
var parsedArgs = argParser.parse(arguments);
1822
var checks = parsedArgs['checks'] as List<String>;
23+
var coverageWeb = parsedArgs['coverage_web'] as bool;
1924

20-
await Health(Directory.current).healthCheck(checks);
25+
await Health(Directory.current).healthCheck(checks, coverageWeb);
2126
}

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@ import 'package:path/path.dart' as path;
88

99
import '../github.dart';
1010
import '../repo.dart';
11+
import '../utils.dart';
1112

1213
Future<Map<Package, List<GitFile>>> packagesWithoutChangelog(
1314
Github github) async {
1415
final repo = Repository();
1516
final packages = repo.locatePackages();
1617

1718
final files = await github.listFilesForPR();
18-
print('Collecting packages without changed changelogs:');
19-
final packagesWithoutChangedChangelog = packages.where((package) {
20-
var changelogPath = package.changelog.file.path;
21-
var changelog = path.relative(changelogPath, from: Directory.current.path);
22-
return !files.map((e) => e.relativePath).contains(changelog);
23-
}).toList();
24-
print('Done, found ${packagesWithoutChangedChangelog.length} packages.');
19+
20+
var packagesWithoutChangedChangelog =
21+
collectPackagesWithoutChangelogChanges(packages, files);
2522

2623
print('Collecting files without license headers in those packages:');
2724
var packagesWithChanges = <Package, List<GitFile>>{};
@@ -42,6 +39,19 @@ Done, found ${packagesWithChanges.length} packages with a need for a changelog.'
4239
return packagesWithChanges;
4340
}
4441

42+
List<Package> collectPackagesWithoutChangelogChanges(
43+
List<Package> packages, List<GitFile> files) {
44+
print('Collecting packages without changed changelogs:');
45+
final packagesWithoutChangedChangelog = packages
46+
.where((package) => package.changelog.exists)
47+
.where((package) => !files
48+
.map((e) => e.relativePath)
49+
.contains(package.changelog.file.relativePath))
50+
.toList();
51+
print('Done, found ${packagesWithoutChangedChangelog.length} packages.');
52+
return packagesWithoutChangedChangelog;
53+
}
54+
4555
bool fileNeedsEntryInChangelog(Package package, String file) {
4656
final directoryPath = package.directory.path;
4757
final directory = path.relative(directoryPath, from: Directory.current.path);

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import '../utils.dart';
1313
import 'lcov.dart';
1414

1515
class Coverage {
16+
final bool coverageWeb;
17+
18+
Coverage(this.coverageWeb);
19+
1620
Future<CoverageResult> compareCoverages() async {
1721
var files = await Github().listFilesForPR();
1822
var basePath = '../base_repo/';
@@ -88,14 +92,16 @@ Get coverage for ${package.name} by running coverage in ${package.directory.path
8892
['pub', 'get'],
8993
workingDirectory: package.directory.path,
9094
);
91-
print('Get test coverage for web');
92-
var resultChrome = Process.runSync(
93-
'dart',
94-
['test', '-p', 'chrome', '--coverage=coverage'],
95-
workingDirectory: package.directory.path,
96-
);
97-
print(resultChrome.stdout);
98-
print(resultChrome.stderr);
95+
if (coverageWeb) {
96+
print('Get test coverage for web');
97+
var resultChrome = Process.runSync(
98+
'dart',
99+
['test', '-p', 'chrome', '--coverage=coverage'],
100+
workingDirectory: package.directory.path,
101+
);
102+
print(resultChrome.stdout);
103+
print(resultChrome.stderr);
104+
}
99105
print('Get test coverage for vm');
100106
var resultVm = Process.runSync(
101107
'dart',

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

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

10+
import 'package:collection/collection.dart';
1011
import 'package:firehose/firehose.dart';
1112

1213
import '../github.dart';
@@ -34,7 +35,7 @@ class Health {
3435

3536
Health(this.directory);
3637

37-
Future<void> healthCheck(List args) async {
38+
Future<void> healthCheck(List args, bool coverageweb) async {
3839
var github = Github();
3940

4041
// Do basic validation of our expected env var.
@@ -55,13 +56,13 @@ class Health {
5556
validateCheck,
5657
if (args.contains('license') &&
5758
!github.prLabels.contains('skip-license-check'))
58-
(Github _) => licenseCheck(),
59+
licenseCheck,
5960
if (args.contains('changelog') &&
6061
!github.prLabels.contains('skip-changelog-check'))
6162
changelogCheck,
6263
if (args.contains('coverage') &&
6364
!github.prLabels.contains('skip-coverage-check'))
64-
coverageCheck,
65+
(Github github) => coverageCheck(github, coverageweb),
6566
];
6667

6768
var checked =
@@ -90,25 +91,46 @@ Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automati
9091
);
9192
}
9293

93-
Future<HealthCheckResult> licenseCheck() async {
94-
var filePaths = await getFilesWithoutLicenses(Directory.current);
94+
Future<HealthCheckResult> licenseCheck(Github github) async {
95+
var files = await Github().listFilesForPR();
96+
var allFilePaths = await getFilesWithoutLicenses(Directory.current);
9597

98+
var groupedPaths = allFilePaths
99+
.groupListsBy((path) => files.any((f) => f.relativePath == path));
100+
101+
var unchangedFilesPaths = groupedPaths[false] ?? [];
102+
var unchangedMarkdown = '''
103+
<details>
104+
<summary>
105+
Unrelated files missing license headers
106+
</summary>
107+
108+
| Files |
109+
| :--- |
110+
${unchangedFilesPaths.map((e) => '|$e|').join('\n')}
111+
</details>
112+
''';
113+
114+
var changedFilesPaths = groupedPaths[true] ?? [];
96115
var markdownResult = '''
97116
```
98117
$license
99118
```
100119
101120
| Files |
102121
| :--- |
103-
${filePaths.isNotEmpty ? filePaths.map((e) => '|$e|').join('\n') : '| _no missing headers_ |'}
122+
${changedFilesPaths.isNotEmpty ? changedFilesPaths.map((e) => '|$e|').join('\n') : '| _no missing headers_ |'}
104123
105124
All source files should start with a [license header](https://github.com/dart-lang/ecosystem/wiki/License-Header).
125+
126+
${unchangedFilesPaths.isNotEmpty ? unchangedMarkdown : ''}
127+
106128
''';
107129

108130
return HealthCheckResult(
109131
'license',
110132
_licenseBotTag,
111-
filePaths.isNotEmpty ? Severity.error : Severity.success,
133+
changedFilesPaths.isNotEmpty ? Severity.error : Severity.success,
112134
markdownResult,
113135
);
114136
}
@@ -132,8 +154,11 @@ Changes to files need to be [accounted for](https://github.com/dart-lang/ecosyst
132154
);
133155
}
134156

135-
Future<HealthCheckResult> coverageCheck(Github github) async {
136-
var coverage = await Coverage().compareCoverages();
157+
Future<HealthCheckResult> coverageCheck(
158+
Github github,
159+
bool coverageWeb,
160+
) async {
161+
var coverage = await Coverage(coverageWeb).compareCoverages();
137162

138163
var markdownResult = '''
139164
| File | Coverage |

pkgs/firehose/lib/src/utils.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import 'dart:convert';
66
import 'dart:io';
77

8+
import 'package:path/path.dart' as path;
9+
810
/// Execute the given CLI command asynchronously, streaming stdout and stderr to
911
/// the console.
1012
///
@@ -109,6 +111,11 @@ bool expectEnv(String? value, String name) {
109111
}
110112
}
111113

114+
extension FileExtension on File {
115+
String get relativePath =>
116+
path.relative(this.path, from: Directory.current.path);
117+
}
118+
112119
enum Severity {
113120
success(':heavy_check_mark:'),
114121
info(':heavy_check_mark:'),

pkgs/firehose/pubspec.yaml

Lines changed: 2 additions & 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.3.23-wip
3+
version: 0.3.23
44
repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose
55

66
environment:
@@ -12,6 +12,7 @@ executables:
1212

1313
dependencies:
1414
args: ^2.3.0
15+
collection: ^1.17.2
1516
http: ^0.13.0
1617
path: ^1.8.0
1718
pub_semver: ^2.1.0

pkgs/firehose/test/coverage_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ void main() {
4444
}
4545

4646
class FakeHealth extends Coverage {
47+
FakeHealth() : super(true);
48+
4749
@override
4850
Map<String, double> getCoverage(Package? package) {
4951
Map<String, double> result;

0 commit comments

Comments
 (0)