pipeline-StepBuilder extract item generation of workflow into own function (#1950)

This commit is contained in:
6543 2023-07-08 22:17:09 +02:00 committed by GitHub
parent 1d6b073ca5
commit b3f65d9d01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 75 additions and 63 deletions

View file

@ -30,7 +30,6 @@ import (
"github.com/woodpecker-ci/woodpecker/cli/common"
"github.com/woodpecker-ci/woodpecker/pipeline"
"github.com/woodpecker-ci/woodpecker/pipeline/backend"
"github.com/woodpecker-ci/woodpecker/pipeline/backend/types"
backendTypes "github.com/woodpecker-ci/woodpecker/pipeline/backend/types"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/compiler"
@ -202,7 +201,7 @@ func execWithAxis(c *cli.Context, file, repoPath string, axis matrix.Axis) error
return err
}
backendCtx := context.WithValue(c.Context, types.CliContext, c)
backendCtx := context.WithValue(c.Context, backendTypes.CliContext, c)
backend.Init(backendCtx)
engine, err := backend.FindEngine(backendCtx, c.String("backend-engine"))

View file

@ -85,7 +85,32 @@ func (b *StepBuilder) Build() ([]*Item, error) {
Environ: axis,
Name: SanitizePath(y.Name),
}
item, err := b.genItemForWorkflow(workflow, axis, string(y.Data))
if err != nil {
return nil, err
}
if item == nil {
continue
}
items = append(items, item)
pidSequence++
}
// TODO: add summary workflow that send status back based on workflows generated by matrix function
// depend on https://github.com/woodpecker-ci/woodpecker/issues/778
}
items = filterItemsWithMissingDependencies(items)
// check if at least one step can start, if list is not empty
if len(items) > 0 && !stepListContainsItemsToRun(items) {
return nil, fmt.Errorf("pipeline has no startpoint")
}
return items, nil
}
func (b *StepBuilder) genItemForWorkflow(workflow *model.Workflow, axis matrix.Axis, data string) (*Item, error) {
workflowMetadata := frontend.MetadataFromStruct(b.Forge, b.Repo, b.Curr, b.Last, workflow, b.Link)
environ := b.environmentVariables(workflowMetadata, axis)
@ -99,7 +124,7 @@ func (b *StepBuilder) Build() ([]*Item, error) {
}
// substitute vars
substituted, err := frontend.EnvVarSubst(string(y.Data), environ)
substituted, err := frontend.EnvVarSubst(data, environ)
if err != nil {
return nil, err
}
@ -136,7 +161,7 @@ func (b *StepBuilder) Build() ([]*Item, error) {
}
if len(ir.Stages) == 0 {
continue
return nil, nil
}
item := &Item{
@ -151,19 +176,7 @@ func (b *StepBuilder) Build() ([]*Item, error) {
item.Labels = map[string]string{}
}
items = append(items, item)
pidSequence++
}
}
items = filterItemsWithMissingDependencies(items)
// check if at least one step can start, if list is not empty
if len(items) > 0 && !stepListContainsItemsToRun(items) {
return nil, fmt.Errorf("pipeline has no startpoint")
}
return items, nil
return item, nil
}
func stepListContainsItemsToRun(items []*Item) bool {