Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ func (c *Compiler) getVariables(t *ast.Task, call *Call, evaluateShVars bool) (*
}
}
if t != nil {
if call != nil {
if match, ok := call.Vars.Get("MATCH"); ok {
if err := rangeFunc("MATCH", match); err != nil {
return nil, err
}
}
}
for k, v := range t.IncludeVars.All() {
if err := rangeFunc(k, v); err != nil {
return nil, err
Expand Down
17 changes: 17 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,23 @@ func TestIncludesInterpolation(t *testing.T) { // nolint:paralleltest // cannot
}
}

func TestIncludeWildcardVarsExposeMatch(t *testing.T) {
t.Parallel()

var buff bytes.Buffer
e := task.NewExecutor(
task.WithDir("testdata/includes_wildcard_vars"),
task.WithSilent(true),
task.WithStdout(&buff),
task.WithStderr(&buff),
)
require.NoError(t, e.Setup())

err := e.Run(t.Context(), &task.Call{Task: "stack:prod:show"})
require.NoError(t, err)
assert.Equal(t, "prod\n", buff.String())
}

func TestIncludesWithExclude(t *testing.T) {
t.Parallel()

Expand Down
6 changes: 6 additions & 0 deletions testdata/includes_wildcard_vars/Taskfile.stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3'

tasks:
show:
cmds:
- echo '{{.ENV}}'
7 changes: 7 additions & 0 deletions testdata/includes_wildcard_vars/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'

includes:
'stack:*':
taskfile: ./Taskfile.stack.yml
vars:
ENV: '{{index .MATCH 0}}'