From 67d22913cadc7f66482d5a5711dc481eec061c25 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Fri, 16 Oct 2020 07:47:15 +0900 Subject: [PATCH 1/3] fix: convert meta's map[interface{}]interface{} to map[string]interface{} --- go.mod | 1 + go.sum | 2 ++ pkg/config/config.go | 21 ++++++++++++++++++++- pkg/config/task.go | 4 ++++ 4 files changed, 27 insertions(+), 1 deletion(-) 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..d9c341b 100644 --- a/pkg/config/task.go +++ b/pkg/config/task.go @@ -51,6 +51,10 @@ func (task *Task) Set() error { } } + if err := convertMeta(task.Meta); err != nil { + return err + } + return nil } From 1a22d69c9ac05f5818d61b82d73c71beaa19082f Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Fri, 16 Oct 2020 08:02:58 +0900 Subject: [PATCH 2/3] fix: convert task.items map[interface{}]interface{} to map[string]interface{} --- pkg/config/task.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/config/task.go b/pkg/config/task.go index d9c341b..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,12 @@ 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 { From eb22f82ed7c08d6378b65050a37f289a12b9959d Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Fri, 16 Oct 2020 08:08:22 +0900 Subject: [PATCH 3/3] docs: update README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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