forked from Fallout-build/Fallout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitHubActionsStepPipeline.cs
More file actions
54 lines (44 loc) · 2.42 KB
/
Copy pathGitHubActionsStepPipeline.cs
File metadata and controls
54 lines (44 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Collections.Generic;
using System.Linq;
using Fallout.Common.Utilities;
namespace Fallout.Common.CI.GitHubActions.Configuration;
/// <summary>
/// The per-job insertion surface handed to <see cref="IConfigureGitHubActions.ConfigureSteps"/>. Carries
/// the job's identity (<see cref="WorkflowName"/>, <see cref="Image"/>) and a read-only view of the job's
/// built-in steps, and collects the caller's insertions. Generator-constructed; not user-instantiable.
/// </summary>
public class GitHubActionsStepPipeline
{
private readonly Dictionary<GitHubActionsStepPosition, List<GitHubActionsCustomStep>> _inserts =
new Dictionary<GitHubActionsStepPosition, List<GitHubActionsCustomStep>>();
internal GitHubActionsStepPipeline(string workflowName, GitHubActionsImage image, IReadOnlyList<GitHubActionsStep> builtInSteps)
{
WorkflowName = workflowName;
Image = image;
BuiltInSteps = builtInSteps;
}
/// <summary>The name of the workflow this job belongs to (normalized, spaces-to-underscores).</summary>
public string WorkflowName { get; }
/// <summary>The runner image of this job.</summary>
public GitHubActionsImage Image { get; }
/// <summary>A read-only view of the built-in steps already assembled for this job.</summary>
public IReadOnlyList<GitHubActionsStep> BuiltInSteps { get; }
/// <summary>Insert one custom step at <paramref name="position"/>. Multiple inserts at one position render in call order.</summary>
public void Insert(GitHubActionsStepPosition position, GitHubActionsCustomStep step)
{
Assert.NotNull(step);
if (!_inserts.TryGetValue(position, out var list))
_inserts[position] = list = new List<GitHubActionsCustomStep>();
list.Add(step);
}
/// <summary>Insert several custom steps at <paramref name="position"/>, in enumeration order.</summary>
public void Insert(GitHubActionsStepPosition position, IEnumerable<GitHubActionsCustomStep> steps)
{
Assert.NotNull(steps);
foreach (var step in steps)
Insert(position, step);
}
internal IReadOnlyList<GitHubActionsCustomStep> GetInserts(GitHubActionsStepPosition position)
=> _inserts.TryGetValue(position, out var list) ? list : (IReadOnlyList<GitHubActionsCustomStep>)new GitHubActionsCustomStep[0];
internal IEnumerable<GitHubActionsCustomStep> AllInserts => _inserts.Values.SelectMany(x => x);
}