diff --git a/internal/taskfile/read/taskfile.go b/internal/taskfile/read/taskfile.go index a96e4a9e..9c7c971a 100644 --- a/internal/taskfile/read/taskfile.go +++ b/internal/taskfile/read/taskfile.go @@ -1,6 +1,7 @@ package read import ( + "errors" "fmt" "os" "path/filepath" @@ -11,6 +12,9 @@ import ( "gopkg.in/yaml.v2" ) +// ErrIncludedTaskfilesCantHaveIncludes is returned when a included Taskfile contains includes +var ErrIncludedTaskfilesCantHaveIncludes = errors.New("task: Included Taskfiles can't have includes. Please, move the include to the main Taskfile") + // Taskfile reads a Taskfile for a given directory func Taskfile(dir string) (*taskfile.Taskfile, error) { path := filepath.Join(dir, "Taskfile.yml") @@ -35,6 +39,9 @@ func Taskfile(dir string) (*taskfile.Taskfile, error) { if err != nil { return nil, err } + if len(includedTaskfile.Includes) > 0 { + return nil, ErrIncludedTaskfilesCantHaveIncludes + } if err = taskfile.Merge(t, includedTaskfile, namespace); err != nil { return nil, err } diff --git a/task_test.go b/task_test.go index fef7302c..9b0bbb1a 100644 --- a/task_test.go +++ b/task_test.go @@ -477,8 +477,9 @@ func TestIncludes(t *testing.T) { Target: "default", TrimSpace: true, Files: map[string]string{ - "main.txt": "main", - "included.txt": "included", + "main.txt": "main", + "included_directory.txt": "included_directory", + "included_taskfile.txt": "included_taskfile", }, } tt.Run(t) diff --git a/testdata/includes/Taskfile.yml b/testdata/includes/Taskfile.yml index d4b44e51..6b7f29ef 100644 --- a/testdata/includes/Taskfile.yml +++ b/testdata/includes/Taskfile.yml @@ -2,12 +2,14 @@ version: '2' includes: included: ./included + included_taskfile: ./Taskfile2.yml tasks: default: cmds: - task: gen - task: included:gen + - task: included_taskfile:gen gen: cmds: diff --git a/testdata/includes/Taskfile2.yml b/testdata/includes/Taskfile2.yml new file mode 100644 index 00000000..dbb4a34c --- /dev/null +++ b/testdata/includes/Taskfile2.yml @@ -0,0 +1,6 @@ +version: '2' + +tasks: + gen: + cmds: + - echo included_taskfile > included_taskfile.txt diff --git a/testdata/includes/included/Taskfile.yml b/testdata/includes/included/Taskfile.yml index f0d19639..e8fe2ad2 100644 --- a/testdata/includes/included/Taskfile.yml +++ b/testdata/includes/included/Taskfile.yml @@ -3,4 +3,4 @@ version: '2' tasks: gen: cmds: - - echo included > included.txt + - echo included_directory > included_directory.txt