From f61a550e6ef3e29a67e48320f027321dc4b2a38d Mon Sep 17 00:00:00 2001 From: Moritz Date: Tue, 16 Jan 2024 12:12:39 +0100 Subject: [PATCH] Enable experiments for health (#226) * Enable `enable-experiment` option for health * Fix DNS bug * Add default * Add default to yaml * Add default to other wf * Add debug message * Remove empty from list * Add empty arg * Rev version * join by comma * Fix typos --- .github/workflows/health.yaml | 7 ++++++ .github/workflows/health_base.yaml | 8 ++++++- pkgs/firehose/CHANGELOG.md | 4 ++++ pkgs/firehose/bin/health.dart | 17 ++++++++++++-- pkgs/firehose/lib/src/health/coverage.dart | 26 ++++++++++++++++++---- pkgs/firehose/lib/src/health/health.dart | 25 ++++++++++++--------- pkgs/firehose/pubspec.yaml | 2 +- pkgs/firehose/test/coverage_test.dart | 2 +- 8 files changed, 72 insertions(+), 19 deletions(-) diff --git a/.github/workflows/health.yaml b/.github/workflows/health.yaml index 46cad959..751bcedb 100644 --- a/.github/workflows/health.yaml +++ b/.github/workflows/health.yaml @@ -88,6 +88,11 @@ on: default: false required: false type: boolean + experiments: + description: Which experiments should be enabled for Dart. + default: "\"\"" + type: string + required: false jobs: version: @@ -101,6 +106,7 @@ jobs: local_debug: ${{ inputs.local_debug }} use-flutter: ${{ inputs.use-flutter }} checkout_submodules: ${{ inputs.checkout_submodules }} + changelog: if: ${{ contains(inputs.checks, 'changelog') }} uses: ./.github/workflows/health_base.yaml @@ -138,6 +144,7 @@ jobs: local_debug: ${{ inputs.local_debug }} use-flutter: ${{ inputs.use-flutter }} checkout_submodules: ${{ inputs.checkout_submodules }} + experiments: ${{ inputs.experiments }} breaking: if: ${{ contains(inputs.checks, 'breaking') }} diff --git a/.github/workflows/health_base.yaml b/.github/workflows/health_base.yaml index 92a451a6..1a4e7dae 100644 --- a/.github/workflows/health_base.yaml +++ b/.github/workflows/health_base.yaml @@ -55,6 +55,11 @@ on: default: false required: false type: boolean + experiments: + description: Which experiments should be enabled for Dart. + default: "\"\"" + type: string + required: false jobs: health: @@ -119,7 +124,8 @@ jobs: --check ${{ inputs.check }} \ ${{ fromJSON('{"true":"--coverage_web","false":""}')[inputs.coverage_web] }} \ --fail_on ${{ inputs.fail_on }} \ - --warn_on ${{ inputs.warn_on }} + --warn_on ${{ inputs.warn_on }} \ + --experiments ${{ inputs.experiments }} - run: test -f current_repo/output/comment.md || echo $'The ${{ inputs.check }} workflow has encountered an exception and did not complete.' >> current_repo/output/comment.md if: ${{ '$action_state' == 1 }} diff --git a/pkgs/firehose/CHANGELOG.md b/pkgs/firehose/CHANGELOG.md index d54df277..0e106d55 100644 --- a/pkgs/firehose/CHANGELOG.md +++ b/pkgs/firehose/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.3 + +- Allow experiments to be enabled for Dart. + ## 0.5.2 - Also run health workflows on bot PRs. diff --git a/pkgs/firehose/bin/health.dart b/pkgs/firehose/bin/health.dart index 19a98d40..f7f75f96 100644 --- a/pkgs/firehose/bin/health.dart +++ b/pkgs/firehose/bin/health.dart @@ -24,6 +24,10 @@ void main(List arguments) async { allowed: checkTypes, help: 'Which checks should lead to workflow failure', ) + ..addMultiOption( + 'experiments', + help: 'Which experiments should be enabled for Dart', + ) ..addFlag( 'coverage_web', help: 'Whether to run web tests for coverage', @@ -32,11 +36,20 @@ void main(List arguments) async { var check = parsedArgs['check'] as String; var warnOn = parsedArgs['warn_on'] as List; var failOn = parsedArgs['fail_on'] as List; + var experiments = (parsedArgs['experiments'] as List) + .where((name) => name.isNotEmpty) + .toList(); 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) - .healthCheck(); + await Health( + Directory.current, + check, + warnOn, + failOn, + coverageWeb, + experiments, + ).healthCheck(); } diff --git a/pkgs/firehose/lib/src/health/coverage.dart b/pkgs/firehose/lib/src/health/coverage.dart index b1e8aa12..8e617f26 100644 --- a/pkgs/firehose/lib/src/health/coverage.dart +++ b/pkgs/firehose/lib/src/health/coverage.dart @@ -14,8 +14,9 @@ import 'lcov.dart'; class Coverage { final bool coverageWeb; + final List experiments; - Coverage(this.coverageWeb); + Coverage(this.coverageWeb, this.experiments); Future compareCoverages(GithubApi github) async { var files = await github.listFilesForPR(); @@ -93,14 +94,26 @@ class Coverage { Get coverage for ${package.name} by running coverage in ${package.directory.path}'''); Process.runSync( 'dart', - ['pub', 'get'], + [ + if (experiments.isNotEmpty) + '--enable-experiment=${experiments.join(',')}', + 'pub', + 'get' + ], workingDirectory: package.directory.path, ); if (coverageWeb) { print('Get test coverage for web'); var resultChrome = Process.runSync( 'dart', - ['test', '-p', 'chrome', '--coverage=coverage'], + [ + if (experiments.isNotEmpty) + '--enable-experiment=${experiments.join(',')}', + 'test', + '-p', + 'chrome', + '--coverage=coverage' + ], workingDirectory: package.directory.path, ); print(resultChrome.stdout); @@ -109,7 +122,12 @@ Get coverage for ${package.name} by running coverage in ${package.directory.path print('Get test coverage for vm'); var resultVm = Process.runSync( 'dart', - ['test', '--coverage=coverage'], + [ + if (experiments.isNotEmpty) + '--enable-experiment=${experiments.join(',')}', + 'test', + '--coverage=coverage' + ], workingDirectory: package.directory.path, ); print(resultVm.stdout); diff --git a/pkgs/firehose/lib/src/health/health.dart b/pkgs/firehose/lib/src/health/health.dart index 7f1ce1e7..5b06e96c 100644 --- a/pkgs/firehose/lib/src/health/health.dart +++ b/pkgs/firehose/lib/src/health/health.dart @@ -50,6 +50,7 @@ class Health { this.warnOn, this.failOn, this.coverageweb, + this.experiments, ); final github = GithubApi(); @@ -57,6 +58,7 @@ class Health { final List warnOn; final List failOn; final bool coverageweb; + final List experiments; Future healthCheck() async { // Do basic validation of our expected env var. @@ -259,24 +261,26 @@ Changes to files need to be [accounted for](https://github.com/dart-lang/ecosyst } Future doNotSubmitCheck() async { + final dns = 'DO_NOT${'_'}SUBMIT'; + final body = await github.pullrequestBody(); final files = await github.listFilesForPR(); - print('Checking for DO_NOT${'_'}SUBMIT strings: $files'); + print('Checking for $dns strings: $files'); final filesWithDNS = files .where((file) => ![FileStatus.removed, FileStatus.unchanged].contains(file.status)) - .where((file) => File(file.relativePath) - .readAsStringSync() - .contains('DO_NOT${'_'}SUBMIT')) + .where((file) => File(file.relativePath).existsSync()) + .where( + (file) => File(file.relativePath).readAsStringSync().contains(dns)) .toList(); - print('Found files with DO_NOT_${'SUBMIT'}: $filesWithDNS'); + print('Found files with $dns: $filesWithDNS'); - final bodyContainsDNS = body.contains('DO_NOT${'_'}SUBMIT'); - print('The body contains a DO_NOT${'_'}SUBMIT string: $bodyContainsDNS'); + final bodyContainsDNS = body.contains(dns); + print('The body contains a $dns string: $bodyContainsDNS'); final markdownResult = ''' -Body contains `DO_NOT${'_'}SUBMIT`: $bodyContainsDNS +Body contains `$dns`: $bodyContainsDNS -| Files with `DO_NOT_${'SUBMIT'}` | +| Files with `$dns` | | :--- | ${filesWithDNS.map((e) => e.filename).map((e) => '|$e|').join('\n')} '''; @@ -290,7 +294,8 @@ ${filesWithDNS.map((e) => e.filename).map((e) => '|$e|').join('\n')} } Future coverageCheck() async { - var coverage = await Coverage(coverageweb).compareCoverages(github); + var coverage = + await Coverage(coverageweb, experiments).compareCoverages(github); var markdownResult = ''' | File | Coverage | diff --git a/pkgs/firehose/pubspec.yaml b/pkgs/firehose/pubspec.yaml index 4519fdec..de9ff9ba 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.5.2 +version: 0.5.3 repository: https://github.com/dart-lang/ecosystem/tree/main/pkgs/firehose environment: diff --git a/pkgs/firehose/test/coverage_test.dart b/pkgs/firehose/test/coverage_test.dart index beb865c6..2cfbeaa2 100644 --- a/pkgs/firehose/test/coverage_test.dart +++ b/pkgs/firehose/test/coverage_test.dart @@ -43,7 +43,7 @@ void main() { } class FakeHealth extends Coverage { - FakeHealth() : super(true); + FakeHealth() : super(true, []); @override Map getCoverage(Package? package) {