Update pipeline state on server as a whole on approval (#3504)

We can not just update some records for steps, as we want the pipeline
engine as single source of truth but not manage the state.
And the server should only manage the state but not how pipelines work.

We can match the pipeline but neither workflows or steps 1:1, so we
"update" them as a whole by deleting existing workflow and step data and
insert the new info from engine.

close   #3494
close  #3472

---------
*Sponsored by Kithara Software GmbH*

---------

Co-authored-by: Robert Kaussow <xoxys@rknet.org>
This commit is contained in:
6543
2024-03-18 20:07:45 +01:00
committed by GitHub
parent 43264a5f8e
commit e57a09a404
8 changed files with 78 additions and 230 deletions

View File

@@ -79,25 +79,11 @@ func Approve(ctx context.Context, store store.Store, currentPipeline *model.Pipe
return nil, fmt.Errorf(msg)
}
// TODO improve this
for _, item := range pipelineItems {
for _, wf := range currentPipeline.Workflows {
if item.Workflow.Name == wf.Name {
item.Workflow = wf
for _, stage := range item.Config.Stages {
for _, step := range stage.Steps {
for _, storeStep := range wf.Children {
if storeStep.Name == step.Name {
step.UUID = storeStep.UUID
break
}
}
}
}
break
}
}
// we have no way to link old workflows and steps in database to new engine generated steps,
// so we just delete the old and insert the new ones
if err := store.WorkflowsReplace(currentPipeline, currentPipeline.Workflows); err != nil {
log.Error().Err(err).Str("repo", repo.FullName).Msgf("error persisting new steps for %s#%d after approval", repo.FullName, currentPipeline.Number)
return nil, err
}
publishPipeline(ctx, currentPipeline, repo, user)

View File

@@ -125,6 +125,9 @@ func setPipelineStepsOnPipeline(pipeline *model.Pipeline, pipelineItems []*stepb
}
}
// the workflows in the pipeline should be empty as only we do populate them,
// but if a pipeline was already loaded form database it might contain things, so we just clean it
pipeline.Workflows = nil
for _, item := range pipelineItems {
for _, stage := range item.Config.Stages {
for _, step := range stage.Steps {