diff --git a/executor_test.go b/executor_test.go index ddf735c98b..ca10f9f24b 100644 --- a/executor_test.go +++ b/executor_test.go @@ -987,3 +987,12 @@ func TestIncludeChecksum(t *testing.T) { WithFixtureTemplating(), ) } + +func TestColonSeparatedSources(t *testing.T) { + t.Parallel() + NewExecutorTest(t, + WithExecutorOptions( + task.WithDir("testdata/colon_sources"), + ), + ) +} diff --git a/internal/templater/templater.go b/internal/templater/templater.go index 896cba23c1..6f226b6f72 100644 --- a/internal/templater/templater.go +++ b/internal/templater/templater.go @@ -105,11 +105,26 @@ func ReplaceGlobs(globs []*ast.Glob, cache *Cache) []*ast.Glob { return nil } - new := make([]*ast.Glob, len(globs)) - for i, g := range globs { - new[i] = &ast.Glob{ - Glob: Replace(g.Glob, cache), - Negate: g.Negate, + var new []*ast.Glob + for _, g := range globs { + replacedGlob := Replace(g.Glob, cache) + + if strings.Contains(replacedGlob, ":") { + paths := strings.Split(replacedGlob, ":") + for _, path := range paths { + path = strings.TrimSpace(path) + if path != "" { + new = append(new, &ast.Glob{ + Glob: path, + Negate: g.Negate, + }) + } + } + } else { + new = append(new, &ast.Glob{ + Glob: replacedGlob, + Negate: g.Negate, + }) } } return new diff --git a/testdata/colon_sources/Taskfile.yml b/testdata/colon_sources/Taskfile.yml new file mode 100644 index 0000000000..f0ba7bf66e --- /dev/null +++ b/testdata/colon_sources/Taskfile.yml @@ -0,0 +1,14 @@ +version: '3' + +vars: + MULTI_SOURCES: "*.txt:subdir/*.md" + +tasks: + default: + desc: Test colon-separated sources + sources: + - "{{.MULTI_SOURCES}}" + generates: + - output.txt + cmds: + - echo "Processing colon-separated sources" > output.txt \ No newline at end of file diff --git a/testdata/colon_sources/output.txt b/testdata/colon_sources/output.txt new file mode 100644 index 0000000000..51acdad04f --- /dev/null +++ b/testdata/colon_sources/output.txt @@ -0,0 +1 @@ +Processing colon-separated sources diff --git a/testdata/colon_sources/subdir/readme.md b/testdata/colon_sources/subdir/readme.md new file mode 100644 index 0000000000..8ae056963b --- /dev/null +++ b/testdata/colon_sources/subdir/readme.md @@ -0,0 +1 @@ +# Test diff --git a/testdata/colon_sources/test.txt b/testdata/colon_sources/test.txt new file mode 100644 index 0000000000..d670460b4b --- /dev/null +++ b/testdata/colon_sources/test.txt @@ -0,0 +1 @@ +test content diff --git a/testdata/colon_sources/testdata/TestColonSeparatedSources.golden b/testdata/colon_sources/testdata/TestColonSeparatedSources.golden new file mode 100644 index 0000000000..b34902ede9 --- /dev/null +++ b/testdata/colon_sources/testdata/TestColonSeparatedSources.golden @@ -0,0 +1 @@ +task: Task "default" is up to date diff --git a/website/src/docs/reference/schema.md b/website/src/docs/reference/schema.md index a6d81c3515..ecf25af7a1 100644 --- a/website/src/docs/reference/schema.md +++ b/website/src/docs/reference/schema.md @@ -537,7 +537,7 @@ tasks: #### `sources` - **Type**: `[]string` or `[]Glob` -- **Description**: Source files to monitor for changes +- **Description**: Source files to monitor for changes. Multiple glob patterns can be specified in a single string separated by colons. ```yaml tasks: @@ -545,6 +545,8 @@ tasks: sources: - '**/*.go' - go.mod + # Multiple patterns in one line (colon-separated) + - '*.js:*.ts:assets/**/*' # With exclusions - exclude: '**/*_test.go' cmds: diff --git a/website/src/public/schema.json b/website/src/public/schema.json index 8605d98b44..9b9d590845 100644 --- a/website/src/public/schema.json +++ b/website/src/public/schema.json @@ -96,7 +96,7 @@ } }, "sources": { - "description": "A list of sources to check before running this task. Relevant for `checksum` and `timestamp` methods. Can be file paths or star globs.", + "description": "A list of sources to check before running this task. Relevant for `checksum` and `timestamp` methods. Can be file paths or star globs. Multiple glob patterns can be specified in a single string separated by colons.", "type": "array", "items": { "$ref": "#/definitions/glob"