diff --git a/README.md b/README.md index 4743923..47eb099 100644 --- a/README.md +++ b/README.md @@ -337,6 +337,16 @@ If the `phase.condtion.exit` is true, the build is finished and subsequent phase The configuration file path can be specified with the `--config (-c)` option. If the confgiuration file path isn't specified, the file named `.buildflow.yml` or `.buildflow.yaml` would be searched from the current directory to the root directory. +## Separate Configuration file + +* phase.import +* task.import +* task.input_file +* task.output_file +* command.command_file +* command.env[].value_file +* write_file.template_file + ## Configuration Reference ```yaml diff --git a/pkg/config/task.go b/pkg/config/task.go index 113b8dc..071fe2e 100644 --- a/pkg/config/task.go +++ b/pkg/config/task.go @@ -24,6 +24,8 @@ type Task struct { Meta map[string]interface{} Output Script Input Script + InputFile string `yaml:"input_file"` + OutputFile string `yaml:"output_file"` Import string } diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index b1678a9..646d85c 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -14,6 +14,7 @@ import ( "github.com/suzuki-shunsuke/buildflow/pkg/constant" "github.com/suzuki-shunsuke/buildflow/pkg/domain" "github.com/suzuki-shunsuke/buildflow/pkg/execute" + "github.com/suzuki-shunsuke/buildflow/pkg/expr" gh "github.com/suzuki-shunsuke/buildflow/pkg/github" "github.com/suzuki-shunsuke/buildflow/pkg/template" "github.com/suzuki-shunsuke/go-dataeq/dataeq" @@ -388,6 +389,25 @@ func (ctrl Controller) readTemplateFile(p, wd string, tpl *config.Template) erro return nil } +func (ctrl Controller) readScript(p, wd string, scr *config.Script) error { + if p == "" { + return nil + } + if !filepath.IsAbs(p) { + p = filepath.Join(wd, p) + } + result, err := ctrl.FileReader.Read(p) + if err != nil { + return err + } + if prog, err := expr.New(result.Text); err != nil { + return err + } else { + scr.Prog = prog + } + return nil +} + func (ctrl Controller) ReadExternalFiles(ctx context.Context, wd string) error { //nolint:gocognit for i, phase := range ctrl.Config.Phases { for j, task := range phase.Tasks { @@ -420,6 +440,12 @@ func (ctrl Controller) ReadExternalFiles(ctx context.Context, wd string) error { return err } } + if err := ctrl.readScript(task.InputFile, wd, &task.Input); err != nil { + return err + } + if err := ctrl.readScript(task.OutputFile, wd, &task.Output); err != nil { + return err + } phase.Tasks[j] = task } ctrl.Config.Phases[i] = phase