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
22 changes: 22 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,28 @@ func TestIncludesWithExclude(t *testing.T) {
require.Error(t, err)
buff.Reset()

err = e.Run(t.Context(), &task.Call{Task: "included:tools:lint"})
require.Error(t, err)
buff.Reset()

err = e.Run(t.Context(), &task.Call{Task: "included:tools:test"})
require.Error(t, err)
buff.Reset()

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

err = e.Run(t.Context(), &task.Call{Task: "included:deploy:*"})
require.Error(t, err)
buff.Reset()

err = e.Run(t.Context(), &task.Call{Task: "included:deploy:one"})
require.NoError(t, err)
assert.Equal(t, "deploy-one\n", buff.String())
buff.Reset()

err = e.Run(t.Context(), &task.Call{Task: "bar"})
require.Error(t, err)
buff.Reset()
Expand Down
7 changes: 5 additions & 2 deletions taskfile/ast/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ func (t1 *Tasks) Merge(t2 *Tasks, include *Include, includedTaskfileVars *Vars)
task.Internal = task.Internal || (include != nil && include.Internal)
taskName := name

// if the task is in the exclude list, don't add it to the merged taskfile
if slices.Contains(include.Excludes, name) {
// If the task or one of its namespaces is in the exclude list, don't add
// it to the merged taskfile.
if slices.ContainsFunc(include.Excludes, func(exclude string) bool {
return name == exclude || strings.HasPrefix(name, exclude+":")
}) {
continue
}

Expand Down
4 changes: 3 additions & 1 deletion testdata/includes_with_excludes/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ includes:
included:
taskfile: ./included/Taskfile.yml
excludes:
- foo
- foo
- tools
- deploy:*
included_flatten:
taskfile: ./included/Taskfile.yml
flatten: true
Expand Down
5 changes: 5 additions & 0 deletions testdata/includes_with_excludes/included/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ version: '3'
tasks:
foo: echo foo
bar: echo bar
tools:lint: echo lint
tools:test: echo test
toolshed: echo toolshed
deploy:*: echo wildcard
deploy:one: echo deploy-one
8 changes: 6 additions & 2 deletions website/src/docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ You can do this by using the
### Exclude tasks from being included

You can exclude tasks from being included by using the `excludes` option. This
option takes the list of tasks to be excluded from this include.
option takes a list of task names or namespaces to be excluded from this
include. Excluding a namespace also excludes all tasks below it. Entries are
matched literally and are not treated as glob patterns.

::: code-group

Expand All @@ -423,7 +425,7 @@ version: '3'
includes:
included:
taskfile: ./Included.yml
excludes: [foo]
excludes: [foo, tools]
```

```yaml [Included.yml]
Expand All @@ -432,6 +434,8 @@ version: '3'
tasks:
foo: echo "Foo"
bar: echo "Bar"
tools:lint: echo "Lint"
tools:test: echo "Test"
```

:::
Expand Down
4 changes: 2 additions & 2 deletions website/src/docs/reference/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ includes:
### `excludes`

- **Type**: `[]string`
- **Description**: Tasks to exclude from inclusion
- **Description**: Literal task names or namespaces to exclude from inclusion

```yaml
includes:
shared:
taskfile: ./shared.yml
excludes: [internal-setup, debug-only]
excludes: [internal-setup, debug]
```

### `vars`
Expand Down