Skip to content

Commit f200385

Browse files
author
Dillon Nys
committed
Fix tests
1 parent 248eee8 commit f200385

File tree

10 files changed

+136
-126
lines changed

10 files changed

+136
-126
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ enum ActionInfo implements Comparable<ActionInfo> {
3939
Step usage({
4040
required String name,
4141
String? id,
42-
Map<String, dynamic>? withContent,
42+
Map<String, String>? withContent,
4343
}) {
4444
final step = Step.uses(
4545
uses: '$repo@$version',
@@ -65,7 +65,7 @@ Job _coverageCompletionJob() => Job(
6565
withContent: {
6666
// https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow
6767
'github-token': r'${{ secrets.GITHUB_TOKEN }}',
68-
'parallel-finished': true
68+
'parallel-finished': 'true'
6969
},
7070
)
7171
],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ class _CommandEntry extends _CommandEntryBase implements GitHubActionOverrides {
462462
final Map<String, String>? env;
463463

464464
@override
465-
final Map<String, dynamic>? withContent;
465+
final Map<String, String>? withContent;
466466

467467
@override
468468
final String? shell;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class GitHubActionOverrides {
1616
///
1717
/// A map of key-value pairs which are passed to the action's `with`
1818
/// parameter.
19-
Map<String, dynamic>? get withContent;
19+
Map<String, String>? get withContent;
2020

2121
/// The condition on which to run this action.
2222
String? get ifContent;

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

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ class Step implements GitHubActionOverrides, YamlLike {
3737
final String? uses;
3838
@override
3939
@JsonKey(name: 'with')
40-
final Map<String, dynamic>? withContent;
40+
final Map<String, String>? withContent;
4141

4242
@override
4343
final String? shell;
4444

4545
@override
46+
@JsonKey(name: 'continue-on-error')
4647
final bool? continueOnError;
4748

4849
@override
50+
@JsonKey(name: 'timeout-minutes')
4951
final int? timeoutMinutes;
5052

5153
Step._({
@@ -61,13 +63,6 @@ class Step implements GitHubActionOverrides, YamlLike {
6163
this.continueOnError,
6264
this.timeoutMinutes,
6365
}) {
64-
if (name == null) {
65-
throw ArgumentError.value(
66-
name,
67-
'name',
68-
'`name` must be defined.',
69-
);
70-
}
7166
if (run == null) {
7267
if (uses == null) {
7368
throw ArgumentError.value(
@@ -93,25 +88,35 @@ class Step implements GitHubActionOverrides, YamlLike {
9388
}
9489
}
9590

96-
Step.fromOverrides(GitHubActionOverrides overrides)
97-
: this._(
98-
id: overrides.id,
99-
name: overrides.name,
100-
uses: overrides.uses,
101-
withContent: overrides.withContent,
102-
workingDirectory: overrides.workingDirectory,
103-
run: overrides.run,
104-
env: overrides.env,
105-
shell: overrides.shell,
106-
ifContent: overrides.ifContent,
107-
continueOnError: overrides.continueOnError,
108-
timeoutMinutes: overrides.timeoutMinutes,
109-
);
91+
factory Step.fromOverrides(GitHubActionOverrides overrides) {
92+
if (overrides.uses != null) {
93+
return Step._(
94+
id: overrides.id,
95+
name: overrides.name,
96+
uses: overrides.uses,
97+
withContent: overrides.withContent,
98+
ifContent: overrides.ifContent,
99+
continueOnError: overrides.continueOnError,
100+
timeoutMinutes: overrides.timeoutMinutes,
101+
);
102+
}
103+
return Step._(
104+
id: overrides.id,
105+
name: overrides.name,
106+
run: overrides.run,
107+
workingDirectory: overrides.workingDirectory,
108+
env: overrides.env,
109+
shell: overrides.shell,
110+
ifContent: overrides.ifContent,
111+
continueOnError: overrides.continueOnError,
112+
timeoutMinutes: overrides.timeoutMinutes,
113+
);
114+
}
110115

111116
Step.run({
112117
this.id,
113118
required String this.name,
114-
required this.run,
119+
required String this.run,
115120
this.ifContent,
116121
this.workingDirectory,
117122
this.env,
@@ -124,7 +129,7 @@ class Step implements GitHubActionOverrides, YamlLike {
124129
Step.uses({
125130
this.id,
126131
required String this.name,
127-
required this.uses,
132+
required String this.uses,
128133
this.withContent,
129134
this.ifContent,
130135
this.continueOnError,

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

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

mono_repo/lib/src/github_config.dart

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ class GitHubActionConfig implements GitHubActionOverrides {
158158
this.env,
159159
this.continueOnError,
160160
this.timeoutMinutes,
161-
this.otherConfig,
162161
}) : assert(
163162
run != null || uses != null,
164163
'Either `run` or `uses` must be specified',
@@ -176,11 +175,8 @@ class GitHubActionConfig implements GitHubActionOverrides {
176175
@override
177176
final String? uses;
178177

179-
/// The command identifier for this step, used in caching.
180-
String get command => (run ?? uses)!;
181-
182178
@override
183-
final Map<String, dynamic>? withContent;
179+
final Map<String, String>? withContent;
184180

185181
@override
186182
final String? ifContent;
@@ -200,9 +196,6 @@ class GitHubActionConfig implements GitHubActionOverrides {
200196
@override
201197
final int? timeoutMinutes;
202198

203-
/// Configuration options not defined by one of the other keys.
204-
final Map<String, dynamic>? otherConfig;
205-
206199
factory GitHubActionConfig.fromJson(Map json) {
207200
// Create a copy of unmodifiable `json`.
208201
json = Map.of(json);
@@ -223,7 +216,7 @@ class GitHubActionConfig implements GitHubActionOverrides {
223216
throw CheckedFromJsonException(
224217
json,
225218
'id',
226-
'ActionConfig',
219+
'GitHubActionConfig',
227220
'Invalid `id` parameter. See GitHub docs for more info: '
228221
'https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsid',
229222
);
@@ -233,7 +226,7 @@ class GitHubActionConfig implements GitHubActionOverrides {
233226
throw CheckedFromJsonException(
234227
json,
235228
'name',
236-
'ActionConfig',
229+
'GitHubActionConfig',
237230
'Invalid `name` parameter. See GitHub docs for more info: '
238231
'https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsname',
239232
);
@@ -243,7 +236,7 @@ class GitHubActionConfig implements GitHubActionOverrides {
243236
throw CheckedFromJsonException(
244237
json,
245238
'run',
246-
'ActionConfig',
239+
'GitHubActionConfig',
247240
'Invalid `run` parameter. See GitHub docs for more info: '
248241
'https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun',
249242
);
@@ -253,7 +246,7 @@ class GitHubActionConfig implements GitHubActionOverrides {
253246
throw CheckedFromJsonException(
254247
json,
255248
'uses',
256-
'ActionConfig',
249+
'GitHubActionConfig',
257250
'Invalid `uses` parameter. See GitHub docs for more info: '
258251
'https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses',
259252
);
@@ -263,7 +256,7 @@ class GitHubActionConfig implements GitHubActionOverrides {
263256
throw CheckedFromJsonException(
264257
json,
265258
'with',
266-
'ActionConfig',
259+
'GitHubActionConfig',
267260
'Invalid `with` parameter. See GitHub docs for more info: '
268261
'https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepswith',
269262
);
@@ -273,7 +266,7 @@ class GitHubActionConfig implements GitHubActionOverrides {
273266
throw CheckedFromJsonException(
274267
json,
275268
'if',
276-
'ActionConfig',
269+
'GitHubActionConfig',
277270
'Invalid `if` parameter. See GitHub docs for more info: '
278271
'https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsif',
279272
);
@@ -283,7 +276,7 @@ class GitHubActionConfig implements GitHubActionOverrides {
283276
throw CheckedFromJsonException(
284277
json,
285278
'working-directory',
286-
'ActionConfig',
279+
'GitHubActionConfig',
287280
'Invalid `working-directory` parameter. See GitHub docs for more info: '
288281
'https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun',
289282
);
@@ -293,7 +286,7 @@ class GitHubActionConfig implements GitHubActionOverrides {
293286
throw CheckedFromJsonException(
294287
json,
295288
'shell',
296-
'ActionConfig',
289+
'GitHubActionConfig',
297290
'Invalid `shell` parameter. See GitHub docs for more info: '
298291
'https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell',
299292
);
@@ -303,7 +296,7 @@ class GitHubActionConfig implements GitHubActionOverrides {
303296
throw CheckedFromJsonException(
304297
json,
305298
'env',
306-
'ActionConfig',
299+
'GitHubActionConfig',
307300
'Invalid `env` parameter. See GitHub docs for more info: '
308301
'https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsenv',
309302
);
@@ -313,7 +306,7 @@ class GitHubActionConfig implements GitHubActionOverrides {
313306
throw CheckedFromJsonException(
314307
json,
315308
'continue-on-error',
316-
'ActionConfig',
309+
'GitHubActionConfig',
317310
'Invalid `continue-on-error` parameter. See GitHub docs for more info: '
318311
'https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepscontinue-on-error',
319312
);
@@ -323,7 +316,7 @@ class GitHubActionConfig implements GitHubActionOverrides {
323316
throw CheckedFromJsonException(
324317
json,
325318
'timeout-minutes',
326-
'ActionConfig',
319+
'GitHubActionConfig',
327320
'Invalid `timeout-minutes` parameter. See GitHub docs for more info: '
328321
'https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepstimeout-minutes',
329322
);
@@ -333,23 +326,30 @@ class GitHubActionConfig implements GitHubActionOverrides {
333326
throw CheckedFromJsonException(
334327
json,
335328
'run,uses',
336-
'ActionConfig',
329+
'GitHubActionConfig',
337330
'Either `run` or `uses` must be specified',
338331
);
339332
}
333+
if (json.isNotEmpty) {
334+
throw CheckedFromJsonException(
335+
json,
336+
json.keys.join(','),
337+
'GitHubActionConfig',
338+
'Invalid keys',
339+
);
340+
}
340341

341342
return GitHubActionConfig(
342343
id: id,
343344
uses: uses,
344345
run: run,
345-
withContent: withContent?.cast(),
346+
withContent: toEnvMap(withContent),
346347
ifContent: ifContent,
347348
workingDirectory: workingDirectory,
348349
shell: shell,
349350
env: toEnvMap(env),
350351
continueOnError: continueOnError,
351352
timeoutMinutes: timeoutMinutes?.toInt(),
352-
otherConfig: json.cast(),
353353
);
354354
}
355355
}

mono_repo/lib/src/task_type.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package_flavor.dart';
1111
abstract class TaskType implements Comparable<TaskType> {
1212
static const command = _CommandTask();
1313
const factory TaskType.githubAction(GitHubActionConfig config) =
14-
GitHubActionTaskType;
14+
_GitHubActionTaskType;
1515

1616
static const _values = <TaskType>[
1717
_FormatTask(),
@@ -49,10 +49,13 @@ abstract class TaskType implements Comparable<TaskType> {
4949
yield val.name;
5050
yield* val.alternates;
5151
}
52+
yield _GitHubActionTaskType._name;
5253
}
5354

54-
static final prettyTaskList =
55-
TaskType._values.map((t) => '`${t.name}`').join(', ');
55+
static final prettyTaskList = [
56+
...TaskType._values.map((t) => '`${t.name}`'),
57+
'`${_GitHubActionTaskType._name}`',
58+
].join(', ');
5659

5760
static TaskType taskFromName(String input) => TaskType._values.singleWhere(
5861
(element) =>
@@ -154,21 +157,23 @@ class _TestWithCoverageTask extends TaskType {
154157
'github-token': r'${{ secrets.GITHUB_TOKEN }}',
155158
'path-to-lcov': '$packageDirectory/coverage/lcov.info',
156159
'flag-name': 'coverage_$countString',
157-
'parallel': true,
160+
'parallel': 'true',
158161
},
159162
),
160163
];
161164
}
162165
}
163166

164-
class GitHubActionTaskType extends TaskType {
165-
const GitHubActionTaskType(this.overrides) : super._('github_action');
167+
class _GitHubActionTaskType extends TaskType {
168+
const _GitHubActionTaskType(this.overrides) : super._(_name);
169+
170+
static const _name = 'github_action';
166171

167172
@override
168173
final GitHubActionConfig overrides;
169174

170175
@override
171-
List<String> commandValue(PackageFlavor flavor, String? args) {
172-
throw UnimplementedError();
173-
}
176+
List<String> commandValue(PackageFlavor flavor, String? args) => [
177+
if (overrides.run != null) overrides.run!,
178+
];
174179
}

0 commit comments

Comments
 (0)