Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
fix: convert meta's map[interface{}]interface{} to map[string]interfa…
Browse files Browse the repository at this point in the history
…ce{}
  • Loading branch information
suzuki-shunsuke committed Oct 15, 2020
1 parent d1febd2 commit 67d2291
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.6.1
github.com/suzuki-shunsuke/go-ci-env v0.2.1
github.com/suzuki-shunsuke/go-convmap v0.1.0
github.com/suzuki-shunsuke/go-dataeq v1.0.1
github.com/suzuki-shunsuke/go-error-with-exit-code v1.0.0
github.com/suzuki-shunsuke/go-findconfig v0.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/suzuki-shunsuke/go-ci-env v0.2.1 h1:BXyeehL7uHtQ8cM+xwLzfzZ8fEhrvcIXJtYe0MEqN0o=
github.com/suzuki-shunsuke/go-ci-env v0.2.1/go.mod h1:kO9UgcQIAH4Pu4ESkUJHPuQEtesxHPKkpQqeJHJzzdk=
github.com/suzuki-shunsuke/go-convmap v0.1.0 h1:0qzSC9IAzYdylNJvgzFpxbD/KeWpuVM608d/S0VjYsU=
github.com/suzuki-shunsuke/go-convmap v0.1.0/go.mod h1:S0yDqBPFU0lmlHhoMKNSSHDRt87tUyI+KY/fBuXNn14=
github.com/suzuki-shunsuke/go-dataeq v1.0.1 h1:ruo7fZ2tT1g5wSWxNTXbDzbdKZRyycnUiAQrhkrOWxw=
github.com/suzuki-shunsuke/go-dataeq v1.0.1/go.mod h1:y9Jf/g370ehd4VBPajzO2Ir8kj+Y4OR+yRu+T5CiK88=
github.com/suzuki-shunsuke/go-error-with-exit-code v1.0.0 h1:oVXrrYNGBq4POyITQNWKzwsYz7B2nUcqtDbeX4BfeEc=
Expand Down
21 changes: 20 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package config

import (
"fmt"
"os"

"github.com/suzuki-shunsuke/buildflow/pkg/expr"
"github.com/suzuki-shunsuke/go-ci-env/cienv"
"github.com/suzuki-shunsuke/go-convmap/convmap"
)

type Phase struct {
Expand Down Expand Up @@ -52,12 +54,29 @@ type Env struct {
CI bool
}

func convertMeta(meta map[string]interface{}) error {
for k, a := range meta {
b, err := convmap.Convert(a)
if err != nil {
return fmt.Errorf("parse meta: %w", err)
}
meta[k] = b
}
return nil
}

func Set(cfg Config) (Config, error) {
cfg = setDefault(setEnv(cfg))
if err := convertMeta(cfg.Meta); err != nil {
return cfg, fmt.Errorf(".meta is invalid: %w", err)
}
for i, phase := range cfg.Phases {
if err := convertMeta(phase.Meta); err != nil {
return cfg, fmt.Errorf("phase is invalid: %s: %w", phase.Name, err)
}
for j, task := range phase.Tasks {
if err := task.Set(); err != nil {
return cfg, err
return cfg, fmt.Errorf("task is invalid: %w", err)
}
phase.Tasks[j] = task
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (task *Task) Set() error {
}
}

if err := convertMeta(task.Meta); err != nil {
return err
}

return nil
}

Expand Down

0 comments on commit 67d2291

Please sign in to comment.