From d560643b266878ac3400dc39f9fb64cdab8c470c Mon Sep 17 00:00:00 2001 From: Laszlo Fogas Date: Fri, 19 Jul 2019 10:13:02 +0200 Subject: [PATCH] Calculating build steps early on to cut short cases without any runnable steps --- server/hook.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/server/hook.go b/server/hook.go index 0becc690c..0d4e5eac5 100644 --- a/server/hook.go +++ b/server/hook.go @@ -177,6 +177,11 @@ func PostHook(c *gin.Context) { return } + if zeroSteps(*build, remoteYamlConfigs) { + c.String(200, "Step conditions yield zero runnable steps") + return + } + if repo.IsGated { // This feature is not clear to me. Reenabling once better understood build.Status = model.StatusBlocked } @@ -293,6 +298,30 @@ func branchFiltered(build *model.Build, remoteYamlConfigs []*remote.FileMeta) bo return true } +// uses pass by value as procBuilder has side effects on build. Something to be fixed +func zeroSteps(build model.Build, remoteYamlConfigs []*remote.FileMeta) bool { + b := procBuilder{ + Repo: &model.Repo{}, + Curr: &build, + Last: &model.Build{}, + Netrc: &model.Netrc{}, + Secs: []*model.Secret{}, + Regs: []*model.Registry{}, + Link: "", + Yamls: remoteYamlConfigs, + } + + buildItems, err := b.Build() + if err != nil { + return false + } + if len(buildItems) == 0 { + return true + } + + return false +} + func findOrPersistPipelineConfig(build *model.Build, remoteYamlConfig *remote.FileMeta) (*model.Config, error) { sha := shasum(remoteYamlConfig.Data) conf, err := Config.Storage.Config.ConfigFindIdentical(build.RepoID, sha)