diff --git a/compiler.go b/compiler.go index 311fd58423..c13d07365b 100644 --- a/compiler.go +++ b/compiler.go @@ -115,6 +115,13 @@ func (c *Compiler) getVariables(t *ast.Task, call *Call, evaluateShVars bool) (* } } if t != nil { + if call != nil { + for k, v := range call.Vars.All() { + if err := rangeFunc(k, v); err != nil { + return nil, err + } + } + } for k, v := range t.IncludeVars.All() { if err := rangeFunc(k, v); err != nil { return nil, err diff --git a/task_test.go b/task_test.go index 9d54af9740..7d56a5759f 100644 --- a/task_test.go +++ b/task_test.go @@ -2096,6 +2096,21 @@ func TestIncludeWithVarsInInclude(t *testing.T) { require.NoError(t, e.Setup()) } +func TestWildcardIncludeVarsCanUseMatch(t *testing.T) { + t.Parallel() + + const dir = "testdata/includes_wildcard_include_vars" + var buff bytes.Buffer + e := task.NewExecutor( + task.WithDir(dir), + task.WithStdout(&buff), + task.WithStderr(&buff), + ) + require.NoError(t, e.Setup()) + require.NoError(t, e.Run(t.Context(), &task.Call{Task: "default"})) + assert.Contains(t, buff.String(), "ENV=prod") +} + func TestIncludedVarsMultiLevel(t *testing.T) { t.Parallel() diff --git a/testdata/includes_wildcard_include_vars/Taskfile.stack.yml b/testdata/includes_wildcard_include_vars/Taskfile.stack.yml new file mode 100644 index 0000000000..7304b1dade --- /dev/null +++ b/testdata/includes_wildcard_include_vars/Taskfile.stack.yml @@ -0,0 +1,6 @@ +version: '3' + +tasks: + show: + cmds: + - echo "ENV={{.ENV}}" diff --git a/testdata/includes_wildcard_include_vars/Taskfile.yml b/testdata/includes_wildcard_include_vars/Taskfile.yml new file mode 100644 index 0000000000..352e42e682 --- /dev/null +++ b/testdata/includes_wildcard_include_vars/Taskfile.yml @@ -0,0 +1,12 @@ +version: '3' + +includes: + 'stack:*': + taskfile: ./Taskfile.stack.yml + vars: + ENV: '{{index .MATCH 0}}' + +tasks: + default: + cmds: + - task stack:prod:show