v3: Allow interpolation on "includes"

The idea is to allow manual inclusion of a OS-dependant Taskfile, since it's
not automatically included anymore.
This commit is contained in:
Andrey Nering
2020-05-17 16:03:03 -03:00
parent 191c34c9c4
commit 9f0f18c5c4
6 changed files with 33 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ import (
"runtime"
"github.com/go-task/task/v2/internal/taskfile"
"github.com/go-task/task/v2/internal/templater"
"gopkg.in/yaml.v3"
)
@@ -28,7 +29,24 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
return nil, err
}
v, err := t.ParsedVersion()
if err != nil {
return nil, err
}
for namespace, includedTask := range t.Includes {
if v >= 3.0 {
tr := templater.Templater{Vars: &taskfile.Vars{}, RemoveNoValue: true}
includedTask = taskfile.IncludedTaskfile{
Taskfile: tr.Replace(includedTask.Taskfile),
Dir: tr.Replace(includedTask.Dir),
AdvancedImport: includedTask.AdvancedImport,
}
if err := tr.Err(); err != nil {
return nil, err
}
}
if filepath.IsAbs(includedTask.Taskfile) {
path = includedTask.Taskfile
} else {
@@ -63,10 +81,6 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
}
}
v, err := t.ParsedVersion()
if err != nil {
return nil, err
}
if v < 3.0 {
path = filepath.Join(dir, fmt.Sprintf("Taskfile_%s.yml", runtime.GOOS))
if _, err = os.Stat(path); err == nil {