diff --git a/README.md b/README.md index d9f581c..ac20185 100644 --- a/README.md +++ b/README.md @@ -364,6 +364,21 @@ ex. We can test external Tengo scripts with [suzuki-shunsuke/tengo-tester](https://github.com/suzuki-shunsuke/tengo-tester). +## Restriction: map key should be string + +* meta +* phase.meta +* task.meta +* task.items + +NG + +```yaml +--- +meta: + true: foo # invalid key: key should be string +``` + ## Configuration Reference ```yaml diff --git a/go.mod b/go.mod index 0c12e22..6ba2315 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index a14bb7d..f8df1ac 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/config/config.go b/pkg/config/config.go index 51ac720..7ee3e68 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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 { @@ -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 } diff --git a/pkg/config/task.go b/pkg/config/task.go index a83a749..4f548f6 100644 --- a/pkg/config/task.go +++ b/pkg/config/task.go @@ -6,6 +6,7 @@ import ( "github.com/suzuki-shunsuke/buildflow/pkg/constant" "github.com/suzuki-shunsuke/buildflow/pkg/execute" "github.com/suzuki-shunsuke/buildflow/pkg/expr" + "github.com/suzuki-shunsuke/go-convmap/convmap" ) type Task struct { @@ -49,6 +50,16 @@ func (task *Task) Set() error { task.CompiledItems = Items{ Program: prog, } + } else if task.Items != nil { + a, err := convmap.Convert(task.Items) + if err != nil { + return err + } + task.Items = a + } + + if err := convertMeta(task.Meta); err != nil { + return err } return nil