If there are no steps, it shouldn't yield a proc

This commit is contained in:
Laszlo Fogas 2019-07-19 09:18:40 +02:00
parent 2edc5fcfb7
commit c303a4d463
2 changed files with 42 additions and 1 deletions

View file

@ -80,7 +80,6 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
Environ: axis,
Name: sanitizePath(y.Name),
}
b.Curr.Procs = append(b.Curr.Procs, proc)
metadata := metadataFromStruct(b.Repo, b.Curr, b.Last, proc, b.Link)
environ := b.environmentVariables(metadata, axis)
@ -113,6 +112,10 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
ir := b.toInternalRepresentation(parsed, environ, metadata, proc.ID)
if len(ir.Stages) == 0 {
continue
}
item := &buildItem{
Proc: proc,
Config: ir,
@ -124,6 +127,8 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
if item.Labels == nil {
item.Labels = map[string]string{}
}
b.Curr.Procs = append(b.Curr.Procs, proc)
items = append(items, item)
pidSequence++
}

View file

@ -205,6 +205,42 @@ pipeline:
}
}
func TestZeroSteps(t *testing.T) {
build := &model.Build{Branch: "dev"}
b := procBuilder{
Repo: &model.Repo{},
Curr: build,
Last: &model.Build{},
Netrc: &model.Netrc{},
Secs: []*model.Secret{},
Regs: []*model.Registry{},
Link: "",
Yamls: []*remote.FileMeta{
&remote.FileMeta{Data: []byte(`
skip_clone: true
pipeline:
build:
when:
branch: notdev
image: scratch
yyy: ${DRONE_COMMIT_MESSAGE}
`)},
},
}
buildItems, err := b.Build()
if err != nil {
t.Fatal(err)
}
if len(buildItems) != 0 {
t.Fatal("Should not generate a build item if there are no steps")
}
if len(build.Procs) != 0 {
t.Fatal("Should not generate a build item if there are no steps")
}
}
func TestTree(t *testing.T) {
build := &model.Build{}