feat: support custom variable references in include/exclude patterns#167
feat: support custom variable references in include/exclude patterns#167
Conversation
Co-authored-by: alirezanet <7004080+alirezanet@users.noreply.github.com>
alirezanet
left a comment
There was a problem hiding this comment.
instead of using filteringRuleVariable isn't it possible to use the custom variables in the include and exclude glob patterns like what we do for ${args} so people can adjust it properly? I don't want to create two separate way of handling one similar issue
Co-authored-by: alirezanet <7004080+alirezanet@users.noreply.github.com>
Done in commit 169bce9. The {
"variables": [
{ "name": "cs-to-be-pushed", "command": "git", "args": ["diff", "origin/main..HEAD", "--name-only"] }
],
"tasks": [
{
"name": "dotnet-test",
"group": "pre-push",
"command": "dotnet",
"args": ["test"],
"include": ["${cs-to-be-pushed}"]
}
]
}When the variable produces no output, the task is skipped. If |
Tasks like
dotnet testornpm run testdon't accept file paths as args, so there was no way to conditionally skip them based on which files were changed — without dropping into an OS-specific shell script.Description
Custom variables from the
variablessection can now be referenced directly insideincludeandexcludepatterns using the same${variable-name}syntax already used inargs. When a variable reference inincludeproduces no output, the task is automatically skipped — no separate property needed.Example
{ "variables": [ { "name": "cs-to-be-pushed", "command": "git", "args": ["diff", "origin/main..HEAD", "--name-only"] } ], "tasks": [ { "name": "dotnet-test", "group": "pre-push", "command": "dotnet", "args": ["test"], "include": ["${cs-to-be-pushed}"] } ] }If
cs-to-be-pushedreturns no files, the task is skipped. Works cross-platform — no shell hackery required.Mixed patterns (e.g.
["**/*.cs", "${my-var}"]) behave correctly: the task is only skipped when all include entries are custom-variable references that returned nothing; a plain glob alongside an empty variable still allows the task to run.Changes
ArgumentParser— new asyncGetPatternMatcherAsynconIArgumentParser; resolves${variable-name}references ininclude/excludepatterns by executing the named variable's command and using its output as patterns. Returnsnullwhen allincludeentries are custom-variable references that produced no output (skip signal). The staticGetPatternMatcheris kept for backward compatibility.ExecutableTaskFactory—CheckIfWeShouldSkipTheTaskchecksGetPatternMatcherAsync == nullfor the Variable rule; also uses it for the Staged rule so that variable references in include/exclude are resolved there too.schema.json—include/excludedescriptions updated to document${variable-name}support.GetPatternMatcherAsync; 4 integration tests covering matching, no-match, missing-variable, and mixed-pattern scenarios.Type of change
Checklist
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.