Skip to content

Add cli mode #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions .github/workflows/health.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ name: Health
# warn_on: "license,coverage,breaking,leaking"
# coverage_web: false
# upload_coverage: false
# use-flutter: true
# flutter_packages: "pkgs/my_flutter_package"
# ignore_license: "**.g.dart"
# ignore_coverage: "**.mock.dart,**.g.dart"
# ignore_packages: "pkgs/helper_package"
Expand All @@ -42,6 +42,12 @@ on:
# parameter is not required; it defaults to `stable` - using the most recent
# stable release of the Dart SDK.
sdk:
description: >-
The Dart SDK version, either a semver or one of `dev`, `stable` etc.
default: "stable"
required: false
type: string
channel:
description: >-
The channel, or a specific version from a channel, to install
('2.19.0','stable', 'beta', 'dev'). Using one of the three channels
Expand Down Expand Up @@ -81,11 +87,11 @@ on:
default: false
type: boolean
required: false
use-flutter:
description: Whether to setup Flutter in this workflow.
default: false
flutter_packages:
description: List of packages depending on Flutter.
default: "\"\""
required: false
type: boolean
type: string
ignore_license:
description: Which files to ignore for the license check.
default: "\"\""
Expand Down Expand Up @@ -122,7 +128,7 @@ jobs:
fail_on: ${{ inputs.fail_on }}
warn_on: ${{ inputs.warn_on }}
local_debug: ${{ inputs.local_debug }}
use-flutter: ${{ inputs.use-flutter }}
flutter_packages: ${{ inputs.flutter_packages }}
ignore_packages: ${{ inputs.ignore_packages }}
checkout_submodules: ${{ inputs.checkout_submodules }}

Expand All @@ -135,7 +141,7 @@ jobs:
fail_on: ${{ inputs.fail_on }}
warn_on: ${{ inputs.warn_on }}
local_debug: ${{ inputs.local_debug }}
use-flutter: ${{ inputs.use-flutter }}
flutter_packages: ${{ inputs.flutter_packages }}
ignore_license: ${{ inputs.ignore_license }}
ignore_packages: ${{ inputs.ignore_packages }}
checkout_submodules: ${{ inputs.checkout_submodules }}
Expand All @@ -151,7 +157,7 @@ jobs:
upload_coverage: ${{ inputs.upload_coverage }}
coverage_web: ${{ inputs.coverage_web }}
local_debug: ${{ inputs.local_debug }}
use-flutter: ${{ inputs.use-flutter }}
flutter_packages: ${{ inputs.flutter_packages }}
ignore_coverage: ${{ inputs.ignore_coverage }}
ignore_packages: ${{ inputs.ignore_packages }}
checkout_submodules: ${{ inputs.checkout_submodules }}
Expand All @@ -166,7 +172,7 @@ jobs:
fail_on: ${{ inputs.fail_on }}
warn_on: ${{ inputs.warn_on }}
local_debug: ${{ inputs.local_debug }}
use-flutter: ${{ inputs.use-flutter }}
flutter_packages: ${{ inputs.flutter_packages }}
ignore_packages: ${{ inputs.ignore_packages }}
checkout_submodules: ${{ inputs.checkout_submodules }}

Expand All @@ -179,7 +185,7 @@ jobs:
fail_on: ${{ inputs.fail_on }}
warn_on: ${{ inputs.warn_on }}
local_debug: ${{ inputs.local_debug }}
use-flutter: ${{ inputs.use-flutter }}
flutter_packages: ${{ inputs.flutter_packages }}
ignore_packages: ${{ inputs.ignore_packages }}
checkout_submodules: ${{ inputs.checkout_submodules }}

Expand All @@ -192,7 +198,7 @@ jobs:
fail_on: ${{ inputs.fail_on }}
warn_on: ${{ inputs.warn_on }}
local_debug: ${{ inputs.local_debug }}
use-flutter: ${{ inputs.use-flutter }}
flutter_packages: ${{ inputs.flutter_packages }}
ignore_packages: ${{ inputs.ignore_packages }}
checkout_submodules: ${{ inputs.checkout_submodules }}

Expand Down
31 changes: 20 additions & 11 deletions .github/workflows/health_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ on:
default: "stable"
required: false
type: string
channel:
description: >-
The channel, or a specific version from a channel, to install
('2.19.0','stable', 'beta', 'dev'). Using one of the three channels
will give you the latest version published to that channel.
default: "stable"
required: false
type: string
check:
description: What to check for in the PR health check - any of "changelog,license,coverage,breaking,do-not-submit,leaking"
type: string
Expand Down Expand Up @@ -44,11 +52,11 @@ on:
default: false
type: boolean
required: false
use-flutter:
description: Whether to setup Flutter in this workflow.
default: false
flutter_packages:
description: List of packages depending on Flutter.
default: "\"\""
required: false
type: boolean
type: string
ignore_license:
description: Which files to ignore for the license check.
default: "\"\""
Expand Down Expand Up @@ -98,23 +106,23 @@ jobs:
if: ${{ inputs.check == 'coverage' }} || ${{ inputs.check == 'breaking' }}

- run: mkdir -p current_repo/output/

- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
if: ${{ inputs.use-flutter }}
with:
channel: ${{ inputs.sdk }}

- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
if: ${{ !inputs.use-flutter }}
with:
sdk: ${{ inputs.sdk }}

- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
if: ${{ inputs.flutter_packages != '' }}
with:
channel: ${{ inputs.channel }}

- name: Install coverage
run: dart pub global activate coverage
if: ${{ inputs.check == 'coverage' }}

- name: Install firehose
run: dart pub global activate firehose
run: dart pub global activate --source git https://github.com/dart-lang/ecosystem --git-path pkgs/firehose/ --git-ref=forceFlutter
# DO-NOT-SUBMIT
if: ${{ !inputs.local_debug }}

- name: Install local firehose
Expand All @@ -139,6 +147,7 @@ jobs:
${{ fromJSON('{"true":"--coverage_web","false":""}')[inputs.coverage_web] }} \
--fail_on ${{ inputs.fail_on }} \
--warn_on ${{ inputs.warn_on }} \
--flutter_packages ${{ inputs.flutter_packages }} \
--ignore_license ${{ inputs.ignore_license }} \
--ignore_coverage ${{ inputs.ignore_coverage }} \
--ignore_packages ${{ inputs.ignore_packages }} \
Expand Down
3 changes: 3 additions & 0 deletions pkgs/firehose/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

- Remove the `version` pubspec checks (these largely duplicate the feedback
provided by publishing automation).
- Run health workflow on all packages if it is changed.
- Specify Flutter packages in the repo, to only have a single workflow file.
- Compare to last published version in breaking check.

## 0.9.3

Expand Down
106 changes: 98 additions & 8 deletions pkgs/firehose/bin/health.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'dart:io';
import 'package:args/args.dart';
import 'package:firehose/src/github.dart';
import 'package:firehose/src/health/health.dart';
import 'package:github/src/common/model/repos.dart';
import 'package:glob/glob.dart';

void main(List<String> arguments) async {
var checkTypes = Check.values.map((c) => c.name);
Expand Down Expand Up @@ -48,23 +50,50 @@ void main(List<String> arguments) async {
..addFlag(
'coverage_web',
help: 'Whether to run web tests for coverage',
);
)
..addMultiOption(
'flutter_packages',
defaultsTo: [],
help: 'The Flutter packages in this repo',
)
..addFlag(
'cli_mode',
help: 'Whether to use the Github API or manually provide the input.',
)
..addOption('pr_body')
..addOption('file_list', defaultsTo: '');
final parsedArgs = argParser.parse(arguments);
final checkStr = parsedArgs['check'] as String;
final checkStr = parsedArgs.option('check');
final check = Check.values.firstWhere((c) => c.name == checkStr);
final warnOn = parsedArgs['warn_on'] as List<String>;
final failOn = parsedArgs['fail_on'] as List<String>;
final warnOn = parsedArgs.multiOption('warn_on');
final failOn = parsedArgs.multiOption('fail_on');
final flutterPackages = _listNonEmpty(parsedArgs, 'flutter_packages');
final ignorePackages = _listNonEmpty(parsedArgs, 'ignore_packages');
final ignoreLicense = _listNonEmpty(parsedArgs, 'ignore_license');
final ignoreCoverage = _listNonEmpty(parsedArgs, 'ignore_coverage');
final experiments = _listNonEmpty(parsedArgs, 'experiments');
final coverageWeb = parsedArgs['coverage_web'] as bool;
final coverageWeb = parsedArgs.flag('coverage_web');
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.');
}
var current = Directory.current;
GithubApi githubApi;
if (parsedArgs.flag('cli_mode')) {
final prBody = parsedArgs.option('pr_body');
final gitFiles = _listNonEmpty(parsedArgs, 'file_list')
.map((e) => GitFile(e, FileStatus.modified, current))
.toList();
githubApi = ManualFileApi(
prBody: prBody ?? '',
files: gitFiles,
prLabels: [],
);
} else {
githubApi = GithubApi();
}
await Health(
Directory.current,
current,
check,
warnOn,
failOn,
Expand All @@ -73,9 +102,70 @@ void main(List<String> arguments) async {
ignoreLicense,
ignoreCoverage,
experiments,
GithubApi(),
githubApi,
flutterPackages,
).healthCheck();
}

List<String> _listNonEmpty(ArgResults parsedArgs, String key) =>
(parsedArgs[key] as List<String>).where((e) => e.isNotEmpty).toList();
parsedArgs.multiOption(key).where((option) => option.isNotEmpty).toList();

class ManualFileApi implements GithubApi {
final String prBody;
final List<GitFile> files;

@override
final List<String> prLabels;

ManualFileApi({
required this.prBody,
required this.files,
required this.prLabels,
});

@override
String? get actor => throw UnimplementedError();

@override
void appendStepSummary(String markdownSummary) {}

@override
String? get baseRef => throw UnimplementedError();

@override
void close() {}

@override
Future<int?> findCommentId({required String user, String? searchTerm}) {
throw UnimplementedError();
}

@override
String? get githubAuthToken => null;

@override
bool get inGithubContext => false;

@override
Future<List<GitFile>> listFilesForPR(Directory directory,
[List<Glob> ignoredFiles = const []]) async =>
files;

@override
void notice({required String message}) {}

@override
Future<String> pullrequestBody() async => prBody;

@override
String? get refName => throw UnimplementedError();

@override
RepositorySlug? get repoSlug => RepositorySlug('owner', 'name');

@override
int? get issueNumber => -1;

@override
String? get sha => '';
}
2 changes: 1 addition & 1 deletion pkgs/firehose/lib/firehose.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Saving existing comment id $existingCommentId to file ${idFile.path}''');

Future<VerificationResults> verify(GithubApi github) async {
var repo = Repository(directory);
var packages = repo.locatePackages(ignoredPackages);
var packages = repo.locatePackages(ignore: ignoredPackages);

var pub = Pub();

Expand Down
2 changes: 1 addition & 1 deletion pkgs/firehose/lib/src/health/changelog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Future<Map<Package, List<GitFile>>> packagesWithoutChangelog(
Directory directory,
) async {
final repo = Repository(directory);
final packages = repo.locatePackages(ignoredPackages);
final packages = repo.locatePackages(ignore: ignoredPackages);

final files = await github.listFilesForPR(directory, ignoredPackages);

Expand Down
10 changes: 2 additions & 8 deletions pkgs/firehose/lib/src/health/coverage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,9 @@ class Coverage {
this.experiments,
);

Future<CoverageResult> compareCoverages(
GithubApi github, Directory base) async {
var files = await github.listFilesForPR(directory, ignoredFiles);
return compareCoveragesFor(files, base);
}

CoverageResult compareCoveragesFor(List<GitFile> files, Directory base) {
var repository = Repository(directory);
var packages = repository.locatePackages(ignoredPackages);
var packages = repository.locatePackages(ignore: ignoredPackages);
print('Found packages $packages at $directory');

var filesOfInterest = files
Expand All @@ -49,7 +43,7 @@ class Coverage {
print('The files of interest are $filesOfInterest');

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

var changedPackages = packages
Expand Down
Loading
Loading