Skip to content

Commit 9b8588c

Browse files
author
Dillon Nys
committed
Merge remote-tracking branch 'google/master' into feat/actions-config
2 parents 524502e + 53aa5b2 commit 9b8588c

File tree

14 files changed

+196
-96
lines changed

14 files changed

+196
-96
lines changed

.github/workflows/dart.yml

Lines changed: 21 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mono_repo.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
merge_stages:
33
- smoke_test
44

5+
coverage_service:
6+
- coveralls
7+
- codecov
8+
59
github:
610
# Setting just `cron` keeps the defaults for `push` and `pull_request`
711
cron: '0 0 * * 0' # “At 00:00 (UTC) on Sunday.”

mono_repo/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
## 6.4.0-dev
33

44
- Added support for `test_with_coverage`.
5-
Uses `package:coverage` and [Coveralls](https://coveralls.io) to track test
6-
code coverage.
5+
Uses `package:coverage` and supports [Coveralls](https://coveralls.io)
6+
(the default) and [Codecov](https://codecov.com/) to track test code coverage.
77
- Added `--verbose` flag. Helps when debugging failures.
88

99
## 6.3.0

mono_repo/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ self_validate: analyze
137137
# Use this key to merge stages across packages to create fewer jobs
138138
merge_stages:
139139
- analyze
140+
141+
# When using `test_with_coverage`, this setting configures the service that
142+
# results are uploaded to.
143+
# Note: you can configure both options, but this would be unusual.
144+
# Note: you can configure this key with no values, to just generate the files
145+
# locally. This may be to enable other, custom processing.
146+
coverage_service:
147+
# https://coveralls.io/ - the default
148+
- coveralls
149+
# https://codecov.io/ – the other option
150+
- codecov
140151
```
141152
142153
### Adding a package config
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'coverage_processor.dart';
6+
7+
/// Represents top-level configuration values that are needed by specific
8+
/// jobs or actions.
9+
///
10+
/// Meant to be minimal and expanded on an as-needed basis.
11+
abstract class BasicConfiguration {
12+
Set<CoverageProcessor> get coverageProcessors;
13+
}

mono_repo/lib/src/commands/github/action_info.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,59 @@ import 'step.dart';
33

44
enum ActionInfo implements Comparable<ActionInfo> {
55
checkout(
6+
name: 'Checkout repository',
67
repo: 'actions/checkout',
78
version: 'd0651293c4a5a52e711f25b41b05b2212f385d28', // v3
89
),
910
cache(
11+
name: 'Cache Pub hosted dependencies',
1012
repo: 'actions/cache',
1113
version: '4504faf7e9bcf8f3ed0bc863c4e1d21499ab8ef8', // v3
1214
),
1315
setupDart(
16+
name: 'Setup Dart SDK',
1417
repo: 'dart-lang/setup-dart',
1518
version: '6a218f2413a3e78e9087f638a238f6b40893203d', // v1.3
1619
),
1720
setupFlutter(
21+
name: 'Setup Flutter SDK',
1822
repo: 'subosito/flutter-action',
1923
version: '2fb73e25c9488eb544b9b14b2ce00c4c2baf789e', // v2.4.0
2024
),
2125

2226
/// See https://github.com/marketplace/actions/coveralls-github-action
2327
coveralls(
28+
name: 'Upload coverage to Coveralls',
2429
repo: 'coverallsapp/github-action',
2530
version: 'master',
2631
completionJobFactory: _coverageCompletionJob,
32+
),
33+
34+
/// See https://github.com/marketplace/actions/codecov
35+
codecov(
36+
name: 'Upload coverage to codecov.io',
37+
repo: 'codecov/codecov-action',
38+
version: 'master',
2739
);
2840

2941
const ActionInfo({
3042
required this.repo,
3143
required this.version,
44+
required this.name,
3245
this.completionJobFactory,
3346
});
3447

3548
final String repo;
3649
final String version;
50+
final String name;
3751
final Job Function()? completionJobFactory;
3852

3953
Step usage({
40-
required String name,
54+
String? name,
4155
String? id,
4256
Map<String, String>? withContent,
4357
}) {
58+
name ??= this.name;
4459
final step = Step.uses(
4560
uses: '$repo@$version',
4661
id: id,

mono_repo/lib/src/commands/github/generate.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ class _GeneratedGitHubConfig {
5252
_GeneratedGitHubConfig._(this.workflowFiles);
5353

5454
factory _GeneratedGitHubConfig.generate(RootConfig rootConfig) {
55-
final commandsToKeys = extractCommands(rootConfig);
56-
57-
final result = generateGitHubYml(rootConfig, commandsToKeys);
58-
55+
final result = generateGitHubYml(rootConfig);
5956
return _GeneratedGitHubConfig._(result);
6057
}
6158
}

mono_repo/lib/src/commands/github/github_yaml.dart

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:collection';
66

77
import 'package:path/path.dart';
88

9+
import '../../basic_config.dart';
910
import '../../ci_shared.dart';
1011
import '../../github_config.dart';
1112
import '../../mono_config.dart';
@@ -22,10 +23,7 @@ import 'step.dart';
2223

2324
const _onCompletionStage = '_on_completion';
2425

25-
Map<String, String> generateGitHubYml(
26-
RootConfig rootConfig,
27-
Map<String, String> commandsToKeys,
28-
) {
26+
Map<String, String> generateGitHubYml(RootConfig rootConfig) {
2927
final jobs = <HasStageName>[
3028
...rootConfig.expand((config) => config.jobs),
3129
];
@@ -82,7 +80,6 @@ Map<String, String> generateGitHubYml(
8280
final allJobs = _listJobs(
8381
rootConfig,
8482
sortedJobs,
85-
commandsToKeys,
8683
rootConfig.monoConfig.mergeStages,
8784
rootConfig.monoConfig.github.onCompletion,
8885
rootConfig.monoConfig.githubConditionalStages,
@@ -178,7 +175,6 @@ ${toYaml({'jobs': jobList})}
178175
Iterable<_MapEntryWithStage> _listJobs(
179176
RootConfig rootConfig,
180177
List<HasStageName> jobs,
181-
Map<String, String> commandsToKeys,
182178
Set<String> mergeStages,
183179
List<Job>? onCompletionJobs,
184180
Map<String, ConditionalStage> conditionalStages,
@@ -203,12 +199,14 @@ Iterable<_MapEntryWithStage> _listJobs(
203199

204200
for (var job in jobs) {
205201
if (job is _SelfValidateJob) {
206-
yield jobEntry(_selfValidateJob(), job.stageName);
202+
yield jobEntry(_selfValidateJob(rootConfig.monoConfig), job.stageName);
207203
continue;
208204
}
209205

210206
final ciJob = job as CIJob;
211207

208+
final commandsToKeys = extractCommands(rootConfig);
209+
212210
final commands =
213211
ciJob.tasks.map((task) => commandsToKeys[task.command]!).toList();
214212

@@ -357,6 +355,7 @@ extension on CIJobEntry {
357355
job.flavor,
358356
job.sdk,
359357
commandEntries,
358+
config: rootConfig.monoConfig,
360359
additionalCacheKeys: {
361360
'packages': packages.join('-'),
362361
'commands': commands.join('-'),
@@ -399,6 +398,7 @@ Job _githubJob(
399398
PackageFlavor packageFlavor,
400399
String sdkVersion,
401400
List<_CommandEntryBase> runCommands, {
401+
required BasicConfiguration config,
402402
Map<String, String>? additionalCacheKeys,
403403
}) =>
404404
Job(
@@ -416,10 +416,9 @@ Job _githubJob(
416416
packageFlavor.setupStep(sdkVersion),
417417
..._beforeSteps(runCommands.whereType<_CommandEntry>()),
418418
ActionInfo.checkout.usage(
419-
name: 'Checkout repository',
420419
id: 'checkout',
421420
),
422-
for (var command in runCommands) ...command.runContent,
421+
for (var command in runCommands) ...command.runContent(config),
423422
],
424423
);
425424

@@ -440,7 +439,8 @@ class _CommandEntryBase {
440439

441440
_CommandEntryBase(this.name, this.run);
442441

443-
Iterable<Step> get runContent => [Step.run(name: name, run: run)];
442+
Iterable<Step> runContent(BasicConfiguration config) =>
443+
[Step.run(name: name, run: run)];
444444
}
445445

446446
class _CommandEntry extends _CommandEntryBase implements GitHubActionOverrides {
@@ -489,9 +489,9 @@ class _CommandEntry extends _CommandEntryBase implements GitHubActionOverrides {
489489
});
490490

491491
@override
492-
Iterable<Step> get runContent => [
492+
Iterable<Step> runContent(BasicConfiguration config) => [
493493
Step.fromOverrides(this),
494-
...?type?.afterEachSteps(workingDirectory),
494+
...?type?.afterEachSteps(workingDirectory, config),
495495
];
496496
}
497497

@@ -524,7 +524,6 @@ Step _cacheEntries(
524524
const pubCacheHosted = '~/.pub-cache/hosted';
525525

526526
return ActionInfo.cache.usage(
527-
name: 'Cache Pub hosted dependencies',
528527
withContent: {
529528
'path': pubCacheHosted,
530529
'key': restoreKeys.first,
@@ -540,7 +539,7 @@ String _maxLength(String input) {
540539
return input.substring(0, 512 - hash.length) + hash;
541540
}
542541

543-
Job _selfValidateJob() => _githubJob(
542+
Job _selfValidateJob(BasicConfiguration config) => _githubJob(
544543
selfValidateJobName,
545544
_ubuntuLatest,
546545
PackageFlavor.dart,
@@ -549,6 +548,7 @@ Job _selfValidateJob() => _githubJob(
549548
for (var command in selfValidateCommands)
550549
_CommandEntryBase(selfValidateJobName, command),
551550
],
551+
config: config,
552552
);
553553

554554
const _ubuntuLatest = 'ubuntu-latest';
@@ -580,13 +580,11 @@ extension on PackageFlavor {
580580
switch (this) {
581581
case PackageFlavor.dart:
582582
return ActionInfo.setupDart.usage(
583-
name: 'Setup Dart SDK',
584583
withContent: {'sdk': sdkVersion},
585584
);
586585

587586
case PackageFlavor.flutter:
588587
return ActionInfo.setupFlutter.usage(
589-
name: 'Setup Flutter SDK',
590588
withContent: {'channel': sdkVersion},
591589
);
592590
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'commands/github/action_info.dart';
6+
7+
enum CoverageProcessor {
8+
coveralls(ActionInfo.coveralls),
9+
codecov(ActionInfo.codecov);
10+
11+
final ActionInfo actionInfo;
12+
13+
const CoverageProcessor(this.actionInfo);
14+
}

0 commit comments

Comments
 (0)