From c99d1d1708f2ca26f2ee228bd5ea1357bf63834c Mon Sep 17 00:00:00 2001 From: Jake Runzer Date: Tue, 28 Jan 2025 04:10:53 -0500 Subject: [PATCH] overwrite command step context with values from config --- core/generate/context.go | 26 ++++++++++++++++++++------ core/plan/step.go | 5 ++--- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/core/generate/context.go b/core/generate/context.go index 6bb7070..246c45c 100644 --- a/core/generate/context.go +++ b/core/generate/context.go @@ -114,18 +114,32 @@ func (c *GenerateContext) ApplyConfig(config *config.Config) error { // Step config for name, configStep := range config.Steps { - // We need to use the key as the step name and not `configStep.Name` + var commandStepBuilder *CommandStepBuilder + // We need to use the key as the step name and not `configStep.Name` if existingStep := c.GetStepByName(name); existingStep != nil { - if commandStep, ok := (*existingStep).(*CommandStepBuilder); ok { - // Just overwrite the commands commands - // TODO: Add support for merging commands - commandStep.Commands = configStep.Commands + if csb, ok := (*existingStep).(*CommandStepBuilder); ok { + commandStepBuilder = csb } else { log.Warnf("Step `%s` exists, but it is not a command step. Skipping...", name) + continue } } else { - c.Steps = append(c.Steps, c.NewCommandStep(name)) + commandStepBuilder = c.NewCommandStep(name) + } + + // Overwrite the step with values from the config if they exist + if len(configStep.DependsOn) > 0 { + commandStepBuilder.DependsOn = configStep.DependsOn + } + if len(configStep.Commands) > 0 { + commandStepBuilder.Commands = configStep.Commands + } + if len(configStep.Outputs) > 0 { + commandStepBuilder.Outputs = configStep.Outputs + } + for k, v := range configStep.Assets { + commandStepBuilder.Assets[k] = v } } diff --git a/core/plan/step.go b/core/plan/step.go index 92c80b8..9e003c3 100644 --- a/core/plan/step.go +++ b/core/plan/step.go @@ -30,9 +30,8 @@ type Step struct { func NewStep(name string) *Step { return &Step{ - Name: name, - DependsOn: make([]string, 0), - Commands: make([]Command, 0), + Name: name, + Assets: make(map[string]string), } }