Skip to content

fix: support .MATCH in wildcard include vars#2929

Closed
vmaerten wants to merge 1 commit into
mainfrom
fix/match-wildcard-include-vars
Closed

fix: support .MATCH in wildcard include vars#2929
vmaerten wants to merge 1 commit into
mainfrom
fix/match-wildcard-include-vars

Conversation

@vmaerten

Copy link
Copy Markdown
Member

Summary

Fixes #2732.

.MATCH was not usable in the vars of an include declared with a wildcard
namespace, e.g.:

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

Running task stack:prod:deploy failed with
index of untyped nil.

The wildcard matching itself already worked: the * in the include key is
concatenated literally into the merged task name (stack:*:deploy), and
WildcardMatch captures it at runtime, so GetTask sets MATCH=["prod"] in
call.Vars. The only problem was ordering in Compiler.getVariables: include
vars were templated before call.Vars (which carries MATCH) was merged in,
so MATCH was still nil when the include vars were rendered.

This change exposes MATCH in the accumulator right before include vars are
evaluated. It is purely additive — the previous behaviour errored, so no
existing Taskfile can regress. call.Vars as a whole is intentionally not
moved earlier, to preserve the precedence of vars passed explicitly to
sub-tasks.

Note: only the include's vars can use .MATCH. The taskfile and dir
fields are resolved at load/merge time, before any task is called, so no
wildcard has been matched yet — this is documented.

Test plan

  • New TestIncludesWildcardVars (nominal match, second match, no-match error)
    with fixture testdata/includes_wildcard_vars/.
  • go test . → all 499 tests pass, no regression on
    TestWildcard / TestIncluded* / TestInclude*.
  • Manual: task --dir testdata/includes_wildcard_vars stack:prod:deploy
    prints Deploying to prod.
  • Docs added under Vars of included Taskfiles in guide.md.

@vmaerten vmaerten closed this Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wildcards don't work with vars specified in task includes

1 participant