Skip to content

Commit e325c69

Browse files
author
Dillon Nys
committed
Migrate to top-level action
1 parent 4f16960 commit e325c69

File tree

9 files changed

+353
-133
lines changed

9 files changed

+353
-133
lines changed

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

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import '../../user_exception.dart';
1717
import '../../yaml.dart';
1818
import 'action_info.dart';
1919
import 'job.dart';
20+
import 'overrides.dart';
2021
import 'step.dart';
2122

2223
const _onCompletionStage = '_on_completion';
@@ -305,36 +306,40 @@ extension on CIJobEntry {
305306
id: pubStepId,
306307
// Run this regardless of the success of other steps other than the
307308
// pub step.
308-
ifCondition: "always() && steps.checkout.conclusion == 'success'",
309+
ifContent: "always() && steps.checkout.conclusion == 'success'",
309310
workingDirectory: package,
310311
),
311312
);
312313
for (var i = 0; i < commands.length; i++) {
313314
final task = job.tasks[i];
314-
var workingDirectory = task.action?.workingDirectory;
315+
final overrides = task.type.overrides;
316+
var workingDirectory = overrides?.workingDirectory;
315317
if (workingDirectory != null) {
316318
workingDirectory = posix.normalize(
317319
posix.join(package, workingDirectory),
318320
);
319321
}
320-
var condition = task.action?.condition;
321-
if (condition != null) {
322-
condition += " && steps.$pubStepId.conclusion == 'success'";
322+
var ifCondition = overrides?.ifContent;
323+
if (ifCondition != null) {
324+
ifCondition += " && steps.$pubStepId.conclusion == 'success'";
323325
}
324326
commandEntries.add(
325327
_CommandEntry(
326328
'$package; ${task.command}',
327329
_commandForOs(task.command),
328330
type: task.type,
329-
id: task.action?.id,
330-
ifCondition: condition ??
331+
id: overrides?.id,
332+
ifContent: ifCondition ??
331333
// Run this regardless of the success of other steps other than
332334
// the pub step.
333335
"always() && steps.$pubStepId.conclusion == 'success'",
334336
workingDirectory: workingDirectory ?? package,
335-
uses: task.action?.uses,
336-
inputs: task.action?.inputs,
337-
shell: task.action?.shell,
337+
uses: overrides?.uses,
338+
withContent: overrides?.withContent,
339+
shell: overrides?.shell,
340+
env: overrides?.env,
341+
timeoutMinutes: overrides?.timeoutMinutes,
342+
continueOnError: overrides?.continueOnError,
338343
),
339344
);
340345
}
@@ -438,49 +443,54 @@ class _CommandEntryBase {
438443
Iterable<Step> get runContent => [Step.run(name: name, run: run)];
439444
}
440445

441-
class _CommandEntry extends _CommandEntryBase {
446+
class _CommandEntry extends _CommandEntryBase implements GitHubActionOverrides {
442447
final TaskType? type;
448+
449+
@override
443450
final String? id;
444-
final String? ifCondition;
451+
452+
@override
453+
final String? ifContent;
454+
455+
@override
445456
final String workingDirectory;
457+
458+
@override
446459
final String? uses;
460+
461+
@override
447462
final Map<String, String>? env;
448-
final Map<String, String>? inputs;
463+
464+
@override
465+
final Map<String, dynamic>? withContent;
466+
467+
@override
449468
final String? shell;
450469

470+
@override
471+
final bool? continueOnError;
472+
473+
@override
474+
final int? timeoutMinutes;
475+
451476
_CommandEntry(
452477
super.name,
453478
super.run, {
454479
required this.workingDirectory,
455480
this.type,
456481
this.id,
457-
this.ifCondition,
482+
this.ifContent,
458483
this.uses,
459484
this.env,
460-
this.inputs,
485+
this.withContent,
461486
this.shell,
487+
this.continueOnError,
488+
this.timeoutMinutes,
462489
});
463490

464491
@override
465492
Iterable<Step> get runContent => [
466-
if (uses != null)
467-
Step.uses(
468-
id: id,
469-
name: name,
470-
uses: uses,
471-
withContent: inputs,
472-
ifContent: ifCondition,
473-
)
474-
else
475-
Step.run(
476-
id: id,
477-
name: name,
478-
ifContent: ifCondition,
479-
workingDirectory: workingDirectory,
480-
run: run,
481-
env: env,
482-
shell: shell,
483-
),
493+
Step.fromOverrides(this),
484494
...?type?.afterEachSteps(workingDirectory),
485495
];
486496
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
abstract class GitHubActionOverrides {
2+
/// The step's identifier, which can be used to refer to the step and its
3+
/// outputs in the [ifContent] property of this and other steps.
4+
String? get id;
5+
6+
/// The name of the step.
7+
String? get name;
8+
9+
/// The shell command to run for this step.
10+
String? get run;
11+
12+
/// The GitHub action identifier, e.g. `actions/checkout@v3`.
13+
String? get uses;
14+
15+
/// The inputs to the action.
16+
///
17+
/// A map of key-value pairs which are passed to the action's `with`
18+
/// parameter.
19+
Map<String, dynamic>? get withContent;
20+
21+
/// The condition on which to run this action.
22+
String? get ifContent;
23+
24+
/// The directory in which to run this action.
25+
String? get workingDirectory;
26+
27+
/// The shell override for this action.
28+
String? get shell;
29+
30+
/// The environment variables for the step.
31+
Map<String, String>? get env;
32+
33+
/// Prevents a job from failing when a step fails.
34+
bool? get continueOnError;
35+
36+
/// The number of minutes to allow the step to run.
37+
int? get timeoutMinutes;
38+
}

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

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:json_annotation/json_annotation.dart';
66

77
import '../../yaml.dart';
8+
import 'overrides.dart';
89

910
part 'step.g.dart';
1011

@@ -13,24 +14,40 @@ part 'step.g.dart';
1314
includeIfNull: false,
1415
constructor: '_',
1516
)
16-
class Step implements YamlLike {
17+
class Step implements GitHubActionOverrides, YamlLike {
18+
@override
1719
final String? id;
20+
@override
1821
final String? name;
22+
@override
1923
final String? run;
2024

25+
@override
2126
@JsonKey(name: 'if')
2227
final String? ifContent;
28+
29+
@override
2330
@JsonKey(name: 'working-directory')
2431
final String? workingDirectory;
2532

26-
final Map? env;
33+
@override
34+
final Map<String, String>? env;
2735

36+
@override
2837
final String? uses;
38+
@override
2939
@JsonKey(name: 'with')
30-
final Map? withContent;
40+
final Map<String, dynamic>? withContent;
3141

42+
@override
3243
final String? shell;
3344

45+
@override
46+
final bool? continueOnError;
47+
48+
@override
49+
final int? timeoutMinutes;
50+
3451
Step._({
3552
this.id,
3653
this.withContent,
@@ -41,7 +58,16 @@ class Step implements YamlLike {
4158
this.workingDirectory,
4259
this.env,
4360
this.shell,
61+
this.continueOnError,
62+
this.timeoutMinutes,
4463
}) {
64+
if (name == null) {
65+
throw ArgumentError.value(
66+
name,
67+
'name',
68+
'`name` must be defined.',
69+
);
70+
}
4571
if (run == null) {
4672
if (uses == null) {
4773
throw ArgumentError.value(
@@ -67,6 +93,21 @@ class Step implements YamlLike {
6793
}
6894
}
6995

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+
);
110+
70111
Step.run({
71112
this.id,
72113
required String this.name,
@@ -75,6 +116,8 @@ class Step implements YamlLike {
75116
this.workingDirectory,
76117
this.env,
77118
this.shell,
119+
this.continueOnError,
120+
this.timeoutMinutes,
78121
}) : uses = null,
79122
withContent = null;
80123

@@ -84,6 +127,8 @@ class Step implements YamlLike {
84127
required this.uses,
85128
this.withContent,
86129
this.ifContent,
130+
this.continueOnError,
131+
this.timeoutMinutes,
87132
}) : run = null,
88133
env = null,
89134
workingDirectory = null,

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

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

0 commit comments

Comments
 (0)