mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-02 04:54:29 +00:00
Do not run clone step if no pipeline step will run (#877)
Skip the clone step and ignore hook/pipeline if no pipeline step except clone would run. The status reported back to the forge is `success`. Closes https://github.com/woodpecker-ci/woodpecker/issues/778
This commit is contained in:
@@ -183,6 +183,7 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config {
|
|||||||
config.Stages = append(config.Stages, stage)
|
config.Stages = append(config.Stages, stage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var stages []*backend.Stage
|
||||||
// add pipeline steps. 1 pipeline step per stage, at the moment
|
// add pipeline steps. 1 pipeline step per stage, at the moment
|
||||||
var stage *backend.Stage
|
var stage *backend.Stage
|
||||||
var group string
|
var group string
|
||||||
@@ -202,7 +203,7 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config {
|
|||||||
stage = new(backend.Stage)
|
stage = new(backend.Stage)
|
||||||
stage.Name = fmt.Sprintf("%s_stage_%v", c.prefix, i)
|
stage.Name = fmt.Sprintf("%s_stage_%v", c.prefix, i)
|
||||||
stage.Alias = container.Name
|
stage.Alias = container.Name
|
||||||
config.Stages = append(config.Stages, stage)
|
stages = append(stages, stage)
|
||||||
}
|
}
|
||||||
|
|
||||||
name := fmt.Sprintf("%s_step_%d", c.prefix, i)
|
name := fmt.Sprintf("%s_step_%d", c.prefix, i)
|
||||||
@@ -210,6 +211,13 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config {
|
|||||||
stage.Steps = append(stage.Steps, step)
|
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)
|
c.setupCacheRebuild(conf, config)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
@@ -200,10 +200,20 @@ func PostHook(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if zeroSteps(build, remoteYamlConfigs) {
|
// TODO: move global pipeline filters into own check functions ...
|
||||||
|
if z, steps := zeroSteps(build, remoteYamlConfigs); z {
|
||||||
msg := "ignoring hook: step conditions yield zero runnable steps"
|
msg := "ignoring hook: step conditions yield zero runnable steps"
|
||||||
log.Debug().Str("repo", repo.FullName).Msg(msg)
|
log.Debug().Str("repo", repo.FullName).Msg(msg)
|
||||||
c.String(http.StatusOK, 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +302,7 @@ func branchFiltered(build *model.Build, remoteYamlConfigs []*remote.FileMeta) (b
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func zeroSteps(build *model.Build, remoteYamlConfigs []*remote.FileMeta) bool {
|
func zeroSteps(build *model.Build, remoteYamlConfigs []*remote.FileMeta) (bool, []*shared.BuildItem) {
|
||||||
b := shared.ProcBuilder{
|
b := shared.ProcBuilder{
|
||||||
Repo: &model.Repo{},
|
Repo: &model.Repo{},
|
||||||
Curr: build,
|
Curr: build,
|
||||||
@@ -304,15 +314,16 @@ func zeroSteps(build *model.Build, remoteYamlConfigs []*remote.FileMeta) bool {
|
|||||||
Yamls: remoteYamlConfigs,
|
Yamls: remoteYamlConfigs,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildItemsNoEmpty, err := b.Build()
|
||||||
|
if err != nil {
|
||||||
|
return false, []*shared.BuildItem{}
|
||||||
|
}
|
||||||
|
b.IncludeEmpty = true
|
||||||
buildItems, err := b.Build()
|
buildItems, err := b.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false, []*shared.BuildItem{}
|
||||||
}
|
}
|
||||||
if len(buildItems) == 0 {
|
return len(buildItemsNoEmpty) == 0, buildItems
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func findOrPersistPipelineConfig(store store.Store, build *model.Build, remoteYamlConfig *remote.FileMeta) (*model.Config, error) {
|
func findOrPersistPipelineConfig(store store.Store, build *model.Build, remoteYamlConfig *remote.FileMeta) (*model.Config, error) {
|
||||||
|
@@ -37,15 +37,16 @@ import (
|
|||||||
|
|
||||||
// ProcBuilder Takes the hook data and the yaml and returns in internal data model
|
// ProcBuilder Takes the hook data and the yaml and returns in internal data model
|
||||||
type ProcBuilder struct {
|
type ProcBuilder struct {
|
||||||
Repo *model.Repo
|
Repo *model.Repo
|
||||||
Curr *model.Build
|
Curr *model.Build
|
||||||
Last *model.Build
|
Last *model.Build
|
||||||
Netrc *model.Netrc
|
Netrc *model.Netrc
|
||||||
Secs []*model.Secret
|
Secs []*model.Secret
|
||||||
Regs []*model.Registry
|
Regs []*model.Registry
|
||||||
Link string
|
Link string
|
||||||
Yamls []*remote.FileMeta
|
Yamls []*remote.FileMeta
|
||||||
Envs map[string]string
|
Envs map[string]string
|
||||||
|
IncludeEmpty bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type BuildItem struct {
|
type BuildItem struct {
|
||||||
@@ -114,7 +115,7 @@ func (b *ProcBuilder) Build() ([]*BuildItem, error) {
|
|||||||
|
|
||||||
ir := b.toInternalRepresentation(parsed, environ, metadata, proc.ID)
|
ir := b.toInternalRepresentation(parsed, environ, metadata, proc.ID)
|
||||||
|
|
||||||
if len(ir.Stages) == 0 {
|
if len(ir.Stages) == 0 && !b.IncludeEmpty {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +139,6 @@ func (b *ProcBuilder) Build() ([]*BuildItem, error) {
|
|||||||
items = filterItemsWithMissingDependencies(items)
|
items = filterItemsWithMissingDependencies(items)
|
||||||
|
|
||||||
// check if at least one proc can start, if list is not empty
|
// check if at least one proc can start, if list is not empty
|
||||||
procListContainsItemsToRun(items)
|
|
||||||
if len(items) > 0 && !procListContainsItemsToRun(items) {
|
if len(items) > 0 && !procListContainsItemsToRun(items) {
|
||||||
return nil, fmt.Errorf("build has no startpoint")
|
return nil, fmt.Errorf("build has no startpoint")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user