From e2e094cfda87becedf7a37d6077fabea2c97ebb5 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 20 May 2022 05:20:17 +0200 Subject: [PATCH] Revert "Do not run clone step if no pipeline step will run (#877)" This reverts commit f05f918b8d4119a2cc786e654d61c331af94cc8a. --- pipeline/frontend/yaml/compiler/compiler.go | 10 +------- server/api/hook.go | 27 ++++++--------------- server/shared/procBuilder.go | 22 ++++++++--------- 3 files changed, 20 insertions(+), 39 deletions(-) diff --git a/pipeline/frontend/yaml/compiler/compiler.go b/pipeline/frontend/yaml/compiler/compiler.go index 3bc8fa8b5..4e26739ad 100644 --- a/pipeline/frontend/yaml/compiler/compiler.go +++ b/pipeline/frontend/yaml/compiler/compiler.go @@ -183,7 +183,6 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config { config.Stages = append(config.Stages, stage) } - var stages []*backend.Stage // add pipeline steps. 1 pipeline step per stage, at the moment var stage *backend.Stage var group string @@ -203,7 +202,7 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config { stage = new(backend.Stage) stage.Name = fmt.Sprintf("%s_stage_%v", c.prefix, i) stage.Alias = container.Name - stages = append(stages, stage) + config.Stages = append(config.Stages, stage) } name := fmt.Sprintf("%s_step_%d", c.prefix, i) @@ -211,13 +210,6 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config { stage.Steps = append(stage.Steps, step) } - if len(stages) == 0 { - // nothing will run, remove services and clone step - config.Stages = []*backend.Stage{} - } else { - config.Stages = append(config.Stages, stages...) - } - c.setupCacheRebuild(conf, config) return config diff --git a/server/api/hook.go b/server/api/hook.go index afe9211f5..b38d23cb2 100644 --- a/server/api/hook.go +++ b/server/api/hook.go @@ -200,20 +200,10 @@ func PostHook(c *gin.Context) { return } - // TODO: move global pipeline filters into own check functions ... - if z, steps := zeroSteps(build, remoteYamlConfigs); z { + if zeroSteps(build, remoteYamlConfigs) { msg := "ignoring hook: step conditions yield zero runnable steps" log.Debug().Str("repo", repo.FullName).Msg(msg) c.String(http.StatusOK, msg) - build.Status = model.StatusSuccess - for _, step := range steps { - step.Proc.State = model.StatusSuccess - build.Procs = append(build.Procs, step.Proc) - } - // TODO: this wont create any builds the status can link to ... - if err := updateBuildStatus(c, build, repo, repoUser); err != nil { - log.Error().Err(err).Msg("updateBuildStatus") - } return } @@ -302,7 +292,7 @@ func branchFiltered(build *model.Build, remoteYamlConfigs []*remote.FileMeta) (b return true, nil } -func zeroSteps(build *model.Build, remoteYamlConfigs []*remote.FileMeta) (bool, []*shared.BuildItem) { +func zeroSteps(build *model.Build, remoteYamlConfigs []*remote.FileMeta) bool { b := shared.ProcBuilder{ Repo: &model.Repo{}, Curr: build, @@ -314,16 +304,15 @@ func zeroSteps(build *model.Build, remoteYamlConfigs []*remote.FileMeta) (bool, Yamls: remoteYamlConfigs, } - buildItemsNoEmpty, err := b.Build() - if err != nil { - return false, []*shared.BuildItem{} - } - b.IncludeEmpty = true buildItems, err := b.Build() if err != nil { - return false, []*shared.BuildItem{} + return false } - return len(buildItemsNoEmpty) == 0, buildItems + if len(buildItems) == 0 { + return true + } + + return false } func findOrPersistPipelineConfig(store store.Store, build *model.Build, remoteYamlConfig *remote.FileMeta) (*model.Config, error) { diff --git a/server/shared/procBuilder.go b/server/shared/procBuilder.go index 2d844fdb2..864268878 100644 --- a/server/shared/procBuilder.go +++ b/server/shared/procBuilder.go @@ -37,16 +37,15 @@ import ( // ProcBuilder Takes the hook data and the yaml and returns in internal data model type ProcBuilder struct { - Repo *model.Repo - Curr *model.Build - Last *model.Build - Netrc *model.Netrc - Secs []*model.Secret - Regs []*model.Registry - Link string - Yamls []*remote.FileMeta - Envs map[string]string - IncludeEmpty bool + Repo *model.Repo + Curr *model.Build + Last *model.Build + Netrc *model.Netrc + Secs []*model.Secret + Regs []*model.Registry + Link string + Yamls []*remote.FileMeta + Envs map[string]string } type BuildItem struct { @@ -115,7 +114,7 @@ func (b *ProcBuilder) Build() ([]*BuildItem, error) { ir := b.toInternalRepresentation(parsed, environ, metadata, proc.ID) - if len(ir.Stages) == 0 && !b.IncludeEmpty { + if len(ir.Stages) == 0 { continue } @@ -139,6 +138,7 @@ func (b *ProcBuilder) Build() ([]*BuildItem, error) { items = filterItemsWithMissingDependencies(items) // check if at least one proc can start, if list is not empty + procListContainsItemsToRun(items) if len(items) > 0 && !procListContainsItemsToRun(items) { return nil, fmt.Errorf("build has no startpoint") }