Supporting multiple yamls in procBuilder

This commit is contained in:
Laszlo Fogas 2019-06-01 10:41:51 +02:00
parent 8199fe4a21
commit c9f2346c2c
4 changed files with 113 additions and 124 deletions

View file

@ -323,7 +323,7 @@ func PostApproval(c *gin.Context) {
Secs: secs,
Regs: regs,
Link: httputil.GetURL(c.Request),
Yaml: conf.Data,
Yamls: []string{conf.Data},
Envs: envs,
}
buildItems, err := b.Build()
@ -512,7 +512,7 @@ func PostBuild(c *gin.Context) {
Secs: secs,
Regs: regs,
Link: httputil.GetURL(c.Request),
Yaml: conf.Data,
Yamls: []string{conf.Data},
Envs: buildParams,
}
buildItems, err := b.Build()

View file

@ -235,7 +235,7 @@ func PostHook(c *gin.Context) {
Regs: regs,
Envs: envs,
Link: httputil.GetURL(c.Request),
Yaml: conf.Data,
Yamls: []string{conf.Data},
}
buildItems, err := b.Build()
if err != nil {

View file

@ -32,11 +32,12 @@ bbb`,
Secs: []*model.Secret{},
Regs: []*model.Registry{},
Link: "",
Yaml: `pipeline:
Yamls: []string{`pipeline:
xxx:
image: scratch
yyy: ${DRONE_COMMIT_MESSAGE}
`,
},
}
if _, err := b.Build(); err != nil {

View file

@ -39,7 +39,7 @@ type procBuilder struct {
Secs []*model.Secret
Regs []*model.Registry
Link string
Yaml string
Yamls []string
Envs map[string]string
}
@ -51,8 +51,10 @@ type buildItem struct {
}
func (b *procBuilder) Build() ([]*buildItem, error) {
var items []*buildItem
axes, err := matrix.ParseString(b.Yaml)
for _, y := range b.Yamls {
axes, err := matrix.ParseString(y)
if err != nil {
return nil, err
}
@ -60,7 +62,6 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
axes = append(axes, matrix.Axis{})
}
var items []*buildItem
for i, axis := range axes {
proc := &model.Proc{
BuildID: b.Curr.ID,
@ -91,7 +92,6 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
})
}
y := b.Yaml
s, err := envsubst.Eval(y, func(name string) string {
env := environ[name]
if strings.Contains(env, "\n") {
@ -161,19 +161,6 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
compiler.WithMetadata(metadata),
).Compile(parsed)
// for _, sec := range b.Secs {
// if !sec.MatchEvent(b.Curr.Event) {
// continue
// }
// if b.Curr.Verified || sec.SkipVerify {
// ir.Secrets = append(ir.Secrets, &backend.Secret{
// Mask: sec.Conceal,
// Name: sec.Name,
// Value: sec.Value,
// })
// }
// }
item := &buildItem{
Proc: proc,
Config: ir,
@ -185,6 +172,7 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
}
items = append(items, item)
}
}
return items, nil
}