Skip to content

Commit

Permalink
Step bundles (#976)
Browse files Browse the repository at this point in the history
* Introduce StepBundle model to the Bitrise config

Introduce activateStep method

Introduce prepareEnvsForStepRun

Remove unused GetBuildFailedEnvironments and SetBuildFailedEnv

Code cleanup

Restore SetBuildFailedEnv

Fix build failed env handling

Add step run output envs to the activateAndRunStepResult

Fix comment typo and unnecessary variable in step activator.go

Simplify when to stop containers

Update envman to the latest master version

Introduce StepBundle model to the Bitrise config

* Handle step bundle envs

* Normalise step bundles and containers

* Validate step bundles

* Test Step Bundle env vars

* Fix failing env order test

* Test build failed mode for step bundles

* Rebase fix

* Simplify step bundle envs preparation

* Update go modules

* Code cleanup

* Rename buildEnvironments to workflowEnvironments

* Bump format and CLI version
  • Loading branch information
godrei authored Jul 12, 2024
1 parent 016883c commit 6c62088
Show file tree
Hide file tree
Showing 8 changed files with 953 additions and 275 deletions.
84 changes: 64 additions & 20 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (r WorkflowRunner) runWorkflows(tracker analytics.Tracker) (models.BuildRun
ProjectType: r.config.Config.ProjectType,
}

plan, err := createWorkflowRunPlan(r.config.Modes, r.config.Workflow, r.config.Config.Workflows, func() string { return uuid.Must(uuid.NewV4()).String() })
plan, err := createWorkflowRunPlan(r.config.Modes, r.config.Workflow, r.config.Config.Workflows, r.config.Config.StepBundles, func() string { return uuid.Must(uuid.NewV4()).String() })
if err != nil {
return models.BuildRunResultsModel{}, fmt.Errorf("failed to create workflow execution plan: %w", err)
}
Expand Down Expand Up @@ -495,22 +495,39 @@ func registerRunModes(modes models.WorkflowRunModes) error {
return nil
}

func createWorkflowRunPlan(modes models.WorkflowRunModes, targetWorkflow string, workflows map[string]models.WorkflowModel, uuidProvider func() string) (models.WorkflowRunPlan, error) {
func createWorkflowRunPlan(modes models.WorkflowRunModes, targetWorkflow string, workflows map[string]models.WorkflowModel, stepBundles map[string]models.StepBundleModel, uuidProvider func() string) (models.WorkflowRunPlan, error) {
var executionPlan []models.WorkflowExecutionPlan

workflowList := walkWorkflows(targetWorkflow, workflows, nil)
for _, workflowID := range workflowList {
workflow := workflows[workflowID]

var stepPlan []models.StepExecutionPlan
var stepPlans []models.StepExecutionPlan

for _, stepListItem := range workflow.Steps {
key, step, with, err := stepListItem.GetStepListItemKeyAndValue()
key, t, err := stepListItem.GetKeyAndType()
if err != nil {
return models.WorkflowRunPlan{}, err
}

if key == models.StepListItemWithKey {
if t == models.StepListItemTypeStep {
step, err := stepListItem.GetStep()
if err != nil {
return models.WorkflowRunPlan{}, err
}

stepID := key
stepPlans = append(stepPlans, models.StepExecutionPlan{
UUID: uuidProvider(),
StepID: stepID,
Step: *step,
})
} else if t == models.StepListItemTypeWith {
with, err := stepListItem.GetWith()
if err != nil {
return models.WorkflowRunPlan{}, err
}

groupID := uuidProvider()

for _, stepListStepItem := range with.Steps {
Expand All @@ -519,22 +536,49 @@ func createWorkflowRunPlan(modes models.WorkflowRunModes, targetWorkflow string,
return models.WorkflowRunPlan{}, err
}

stepPlan = append(stepPlan, models.StepExecutionPlan{
UUID: uuidProvider(),
StepID: stepID,
Step: step,
GroupID: groupID,
ContainerID: with.ContainerID,
ServiceIDs: with.ServiceIDs,
stepPlans = append(stepPlans, models.StepExecutionPlan{
UUID: uuidProvider(),
StepID: stepID,
Step: step,
WithGroupUUID: groupID,
ContainerID: with.ContainerID,
ServiceIDs: with.ServiceIDs,
})
}
} else {
stepID := key
stepPlan = append(stepPlan, models.StepExecutionPlan{
UUID: uuidProvider(),
StepID: stepID,
Step: step,
})
} else if t == models.StepListItemTypeBundle {
bundleID := key
bundleOverride, err := stepListItem.GetBundle()
if err != nil {
return models.WorkflowRunPlan{}, err
}

bundleDefinition, ok := stepBundles[bundleID]
if !ok {
return models.WorkflowRunPlan{}, fmt.Errorf("referenced step bundle not defined: %s", bundleID)
}

bundleEnvs := append(bundleDefinition.Environments, bundleOverride.Environments...)
bundleUUID := uuidProvider()

for idx, stepListStepItem := range bundleDefinition.Steps {
stepID, step, err := stepListStepItem.GetStepIDAndStep()
if err != nil {
return models.WorkflowRunPlan{}, err
}

stepPlan := models.StepExecutionPlan{
UUID: uuidProvider(),
StepID: stepID,
Step: step,
StepBundleUUID: bundleUUID,
}

if idx == 0 {
stepPlan.StepBundleEnvs = bundleEnvs
}

stepPlans = append(stepPlans, stepPlan)
}
}
}

Expand All @@ -546,7 +590,7 @@ func createWorkflowRunPlan(modes models.WorkflowRunModes, targetWorkflow string,
executionPlan = append(executionPlan, models.WorkflowExecutionPlan{
UUID: uuidProvider(),
WorkflowID: workflowID,
Steps: stepPlan,
Steps: stepPlans,
WorkflowTitle: workflowTitle,
IsSteplibOfflineMode: modes.IsSteplibOfflineMode,
})
Expand Down
Loading

0 comments on commit 6c62088

Please sign in to comment.