diff --git a/internal/compiler/v2/compiler_v2.go b/internal/compiler/v2/compiler_v2.go index 04c4deff..1251ba32 100644 --- a/internal/compiler/v2/compiler_v2.go +++ b/internal/compiler/v2/compiler_v2.go @@ -16,10 +16,13 @@ import ( var _ compiler.Compiler = &CompilerV2{} type CompilerV2 struct { - Dir string + Dir string + Taskvars taskfile.Vars TaskfileVars taskfile.Vars + Expansions int + Logger *logger.Logger dynamicCache map[string]string @@ -34,14 +37,11 @@ type CompilerV2 struct { // 5. Environment variables func (c *CompilerV2) GetVariables(t *taskfile.Task, call taskfile.Call) (taskfile.Vars, error) { vr := varResolver{c: c, vars: compiler.GetEnviron()} - vr.merge(c.Taskvars) - vr.merge(c.Taskvars) - vr.merge(c.TaskfileVars) - vr.merge(c.TaskfileVars) - vr.merge(call.Vars) - vr.merge(call.Vars) - vr.merge(t.Vars) - vr.merge(t.Vars) + for _, vars := range []taskfile.Vars{c.Taskvars, c.TaskfileVars, call.Vars, t.Vars} { + for i := 0; i < c.Expansions; i++ { + vr.merge(vars) + } + } return vr.vars, vr.err } diff --git a/internal/taskfile/taskfile.go b/internal/taskfile/taskfile.go index 8368feb7..b874c610 100644 --- a/internal/taskfile/taskfile.go +++ b/internal/taskfile/taskfile.go @@ -2,9 +2,10 @@ package taskfile // Taskfile represents a Taskfile.yml type Taskfile struct { - Version string - Vars Vars - Tasks Tasks + Version string + Expansions int + Vars Vars + Tasks Tasks } // UnmarshalYAML implements yaml.Unmarshaler interface @@ -15,15 +16,20 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error { } var taskfile struct { - Version string - Vars Vars - Tasks Tasks + Version string + Expansions int + Vars Vars + Tasks Tasks } if err := unmarshal(&taskfile); err != nil { return err } tf.Version = taskfile.Version + tf.Expansions = taskfile.Expansions tf.Vars = taskfile.Vars tf.Tasks = taskfile.Tasks + if tf.Expansions <= 0 { + tf.Expansions = 2 + } return nil } diff --git a/task.go b/task.go index 038766e0..9fc00c78 100644 --- a/task.go +++ b/task.go @@ -112,6 +112,7 @@ func (e *Executor) setup() error { Dir: e.Dir, Taskvars: e.taskvars, TaskfileVars: e.Taskfile.Vars, + Expansions: e.Taskfile.Expansions, Logger: e.Logger, }