diff --git a/README.md b/README.md index 54a463d..9d2e01e 100644 --- a/README.md +++ b/README.md @@ -343,6 +343,7 @@ If the confgiuration file path isn't specified, the file named `.buildflow.yml` * task.import * task.input_file * task.output_file +* task.when_file * command.command_file * command.env[].value_file * write_file.template_file diff --git a/pkg/config/bool.go b/pkg/config/bool.go index 6cc9c48..db4c2d5 100644 --- a/pkg/config/bool.go +++ b/pkg/config/bool.go @@ -25,6 +25,12 @@ func (b *Bool) SetBool(f bool) { b.Fixed = true } +func (b *Bool) SetBoolProgram(f expr.BoolProgram) { + b.Prog = f + b.Fixed = false + b.Initialized = true +} + func (b *Bool) SetDefaultBool(f bool) { if !b.Initialized { b.SetBool(f) diff --git a/pkg/config/task.go b/pkg/config/task.go index 071fe2e..a83a749 100644 --- a/pkg/config/task.go +++ b/pkg/config/task.go @@ -12,6 +12,7 @@ type Task struct { Name Template Type string `yaml:"-"` When Bool + WhenFile string `yaml:"when_file"` Dependency Dependency Command Command ReadFile ReadFile `yaml:"read_file"` diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 646d85c..37d4a72 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -408,6 +408,25 @@ func (ctrl Controller) readScript(p, wd string, scr *config.Script) error { return nil } +func (ctrl Controller) readBoolScript(p, wd string, scr *config.Bool) 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.NewBool(result.Text); err != nil { + return err + } else { + scr.SetBoolProgram(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 { @@ -446,6 +465,9 @@ func (ctrl Controller) ReadExternalFiles(ctx context.Context, wd string) error { if err := ctrl.readScript(task.OutputFile, wd, &task.Output); err != nil { return err } + if err := ctrl.readBoolScript(task.WhenFile, wd, &task.When); err != nil { + return err + } phase.Tasks[j] = task } ctrl.Config.Phases[i] = phase