Skip to content

Commit 821d725

Browse files
authored
Add support for test_with_coverage (#400)
Update minimum tested SDK to 2.17.5
1 parent a414bc7 commit 821d725

File tree

17 files changed

+354
-90
lines changed

17 files changed

+354
-90
lines changed

.github/workflows/dart.yml

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

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
.packages
33
.dart_tool/
44
pubspec.lock
5+
6+
# default directory for pkg:coverage
7+
coverage/

mono_repo/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
12
## 6.4.0-dev
23

4+
- Added support for `test_with_coverage`.
5+
Uses `package:coverage` and [Coveralls](https://coveralls.io) to track test
6+
code coverage.
37
- Added `--verbose` flag. Helps when debugging failures.
48

59
## 6.3.0

mono_repo/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Manage multiple [Dart packages] within a single repository.
22

3+
[![pub package](https://img.shields.io/pub/v/mono_repo.svg)](https://pub.dev/packages/mono_repo)
4+
[![package publisher](https://img.shields.io/pub/publisher/mono_repo.svg)](https://pub.dev/packages/mono_repo/publisher)
5+
[![Dart CI](https://github.com/google/mono_repo.dart/actions/workflows/dart.yml/badge.svg)](https://github.com/google/mono_repo.dart/actions/workflows/dart.yml)
6+
[![Coverage Status](https://coveralls.io/repos/github/google/mono_repo.dart/badge.svg?branch=master)](https://coveralls.io/github/google/mono_repo.dart?branch=master)
7+
38
## Installation
49

510
```console

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

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'job.dart';
12
import 'step.dart';
23

34
enum ActionInfo implements Comparable<ActionInfo> {
@@ -16,28 +17,65 @@ enum ActionInfo implements Comparable<ActionInfo> {
1617
setupFlutter(
1718
repo: 'subosito/flutter-action',
1819
version: '2fb73e25c9488eb544b9b14b2ce00c4c2baf789e', // v2.4.0
20+
),
21+
22+
/// See https://github.com/marketplace/actions/coveralls-github-action
23+
coveralls(
24+
repo: 'coverallsapp/github-action',
25+
version: 'master',
26+
completionJobFactory: _coverageCompletionJob,
1927
);
2028

2129
const ActionInfo({
2230
required this.repo,
2331
required this.version,
32+
this.completionJobFactory,
2433
});
2534

2635
final String repo;
2736
final String version;
37+
final Job Function()? completionJobFactory;
2838

2939
Step usage({
3040
required String name,
3141
String? id,
3242
Map<String, dynamic>? withContent,
33-
}) =>
34-
Step.uses(
35-
uses: '$repo@$version',
36-
id: id,
37-
name: name,
38-
withContent: withContent,
39-
);
43+
}) {
44+
final step = Step.uses(
45+
uses: '$repo@$version',
46+
id: id,
47+
name: name,
48+
withContent: withContent,
49+
);
50+
// store away the action info for later use.
51+
_actionInfoExpando[step] = this;
52+
return step;
53+
}
4054

4155
@override
4256
int compareTo(ActionInfo other) => index.compareTo(other.index);
4357
}
58+
59+
Job _coverageCompletionJob() => Job(
60+
name: 'Mark Coveralls job finished',
61+
runsOn: 'ubuntu-latest',
62+
steps: [
63+
ActionInfo.coveralls.usage(
64+
name: 'Mark Coveralls job finished',
65+
withContent: {
66+
// https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow
67+
'github-token': r'${{ secrets.GITHUB_TOKEN }}',
68+
'parallel-finished': true
69+
},
70+
)
71+
],
72+
);
73+
74+
/// Allows finding [ActionInfo] for a corresponding [Step].
75+
final _actionInfoExpando = Expando<ActionInfo>();
76+
77+
extension StepExtension on Step {
78+
bool get hasCompletionJob => actionInfo?.completionJobFactory != null;
79+
80+
ActionInfo? get actionInfo => _actionInfoExpando[this];
81+
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ Map<String, String> generateGitHubYml(
8989
final allPrevStageJobs = <String>{};
9090
String? currStageName;
9191

92+
// TaskType : {jobs names}
93+
final completionMap = SplayTreeMap<ActionInfo, Set<String>>();
94+
9295
for (var job in allJobs) {
9396
if (job.stageName != currStageName) {
9497
currStageName = job.stageName;
@@ -99,11 +102,27 @@ Map<String, String> generateGitHubYml(
99102
if (allPrevStageJobs.isNotEmpty) {
100103
job.value.needs = allPrevStageJobs.toList();
101104
}
105+
106+
// process post-run logic
107+
for (var step in job.value.steps) {
108+
if (step.hasCompletionJob) {
109+
completionMap
110+
.putIfAbsent(step.actionInfo!, SplayTreeSet<String>.new)
111+
.add(job.id);
112+
}
113+
}
102114
}
103115

104116
final jobList =
105117
Map.fromEntries(allJobs.map((e) => MapEntry(e.id, e.value)));
106118

119+
for (var completion in completionMap.entries) {
120+
final job = completion.key.completionJobFactory!()
121+
..needs = completion.value.toList();
122+
123+
jobList['job_${jobList.length + 1}'] = job;
124+
}
125+
107126
output[fileName] = '''
108127
$createdWith
109128
${toYaml(rootConfig.monoConfig.github.generate(workflowName))}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Job implements YamlLike {
2020
final String? runsOn;
2121
@JsonKey(name: 'if')
2222
String? ifContent;
23+
@JsonKey(required: true)
2324
final List<Step> steps;
2425
List<String>? needs;
2526

@@ -29,7 +30,7 @@ class Job implements YamlLike {
2930
required this.steps,
3031
});
3132

32-
factory Job.fromJson(Map<String, dynamic> json) => _$JobFromJson(json);
33+
factory Job.fromJson(Map json) => _$JobFromJson(json);
3334

3435
@override
3536
Map<String, dynamic> toJson() => _$JobToJson(this);

mono_repo/lib/src/commands/github/job.g.dart

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ class Step implements YamlLike {
2323
@JsonKey(name: 'working-directory')
2424
final String? workingDirectory;
2525

26-
final Map<String, String>? env;
26+
final Map? env;
2727

2828
final String? uses;
2929
@JsonKey(name: 'with')
30-
final Map<String, dynamic>? withContent;
30+
final Map? withContent;
3131

3232
Step._({
3333
this.id,
@@ -84,7 +84,7 @@ class Step implements YamlLike {
8484
env = null,
8585
workingDirectory = null;
8686

87-
factory Step.fromJson(Map<String, dynamic> json) => _$StepFromJson(json);
87+
factory Step.fromJson(Map json) => _$StepFromJson(json);
8888

8989
@override
9090
Map<String, dynamic> toJson() => _$StepToJson(this);

mono_repo/lib/src/commands/github/step.g.dart

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

0 commit comments

Comments
 (0)