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 #57 from suzuki-shunsuke/feat/suppor-to-separate-i…
Browse files Browse the repository at this point in the history
…nput

feat: support to read task.input and task.output from a file
  • Loading branch information
suzuki-shunsuke authored Oct 12, 2020
2 parents c11e3c5 + ec329c9 commit 29a57ae
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
26 changes: 26 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 29a57ae

Please sign in to comment.