Skip to content
Merged
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
19 changes: 19 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,25 @@ func TestIncludesIncorrect(t *testing.T) {
assert.Contains(t, err.Error(), "Failed to parse testdata/includes_incorrect/incomplete.yml:", err.Error())
}

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

const dir = "testdata/includes_missing_taskfile"

var buff bytes.Buffer
e := task.NewExecutor(
task.WithDir(dir),
task.WithStdout(&buff),
task.WithStderr(&buff),
task.WithSilent(true),
)

err := e.Setup()
require.Error(t, err)
assert.Contains(t, err.Error(), "include must specify taskfile or dir")
assert.NotContains(t, err.Error(), "include cycle detected")
}

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

Expand Down
4 changes: 4 additions & 0 deletions taskfile/ast/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ast

import (
"iter"
"strings"
"sync"

"github.com/elliotchance/orderedmap/v3"
Expand Down Expand Up @@ -171,6 +172,9 @@ func (include *Include) UnmarshalYAML(node *yaml.Node) error {
if err := node.Decode(&includedTaskfile); err != nil {
return errors.NewTaskfileDecodeError(err, node)
}
if strings.TrimSpace(includedTaskfile.Taskfile) == "" && strings.TrimSpace(includedTaskfile.Dir) == "" {
return errors.NewTaskfileDecodeError(nil, node).WithMessage("include must specify taskfile or dir")
}
include.Taskfile = includedTaskfile.Taskfile
include.Dir = includedTaskfile.Dir
include.Optional = includedTaskfile.Optional
Expand Down
5 changes: 5 additions & 0 deletions testdata/includes_missing_taskfile/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'

includes:
GOBIN:
sh: echo $(go env GOPATH)/bin
16 changes: 13 additions & 3 deletions website/src/public/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,13 @@
"properties": {
"taskfile": {
"description": "The path for the Taskfile or directory to be included. If a directory, Task will look for files named `Taskfile.yml` or `Taskfile.yaml` inside that directory. If a relative path, resolved relative to the directory containing the including Taskfile.",
"type": "string"
"type": "string",
"minLength": 1
},
"dir": {
"description": "The working directory of the included tasks when run.",
"type": "string"
"type": "string",
"minLength": 1
},
"optional": {
"description": "If `true`, no errors will be thrown if the specified file does not exist.",
Expand Down Expand Up @@ -741,7 +743,15 @@
"description": "The checksum of the file you expect to include. If the checksum does not match, the file will not be included.",
"type": "string"
}
}
},
"anyOf": [
{
"required": ["taskfile"]
},
{
"required": ["dir"]
}
]
}
]
}
Expand Down
Loading