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

Commit

Permalink
Merge pull request #62 from suzuki-shunsuke/feat/support-when-file
Browse files Browse the repository at this point in the history
feat: support task.when_file
  • Loading branch information
suzuki-shunsuke authored Oct 12, 2020
2 parents 30a6c6e + cf32041 commit f7fbc25
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pkg/config/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/config/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
22 changes: 22 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f7fbc25

Please sign in to comment.