Skip to content

Commit

Permalink
overwrite command step context with values from config
Browse files Browse the repository at this point in the history
  • Loading branch information
coffee-cup committed Jan 28, 2025
1 parent 410dda7 commit c99d1d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
26 changes: 20 additions & 6 deletions core/generate/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
5 changes: 2 additions & 3 deletions core/plan/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down

0 comments on commit c99d1d1

Please sign in to comment.