summaryrefslogtreecommitdiff
path: root/src/marlin.core/models/meta/Recipe.cs
blob: 33ed8148ed72c4e4645b9f41c5fe838d551c36bb (plain)
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
namespace marlin.core.models.meta;

public class Recipe
{
    public Recipe(string id)
    {
        this.Id = id;
    }

    public string Id { get; }
    public string Name { get; set; }

    public string? RunsOnId { get; set; }
    public List<string> RequireIds { get; set; } = [];
    public Dictionary<string, RecipeStep> Steps { get; set; } = new();
    public Dictionary<string, string> Parameters { get; set; } = new();
    public Dictionary<string, string> Environment { get; set; } = new();

    public RequirementSet? GetRunsOn(Workflow workflow) =>
        this.RunsOnId != null ? workflow.Requirements[this.RunsOnId] : null;

    public IEnumerable<Recipe> GetRequires(Workflow workflow) =>
        this.RequireIds.Select(id => workflow.Recipes[id]);

    public Dictionary<string, string> CreateArguments()
    {
        Dictionary<string, string> args = new();
        foreach (var parameter in this.Parameters)
            args.Add(parameter.Key, parameter.Value);

        foreach (var environment in this.Environment)
            args.Add($"env.{environment.Key}", environment.Value);

        return args;
    }
}