diff --git a/task_test.go b/task_test.go index debbf7b8..3286eb46 100644 --- a/task_test.go +++ b/task_test.go @@ -95,6 +95,15 @@ func TestEmptyTask(t *testing.T) { require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "default"})) } +func TestEmptyTaskfile(t *testing.T) { + e := &task.Executor{ + Dir: "testdata/empty_taskfile", + Stdout: io.Discard, + Stderr: io.Discard, + } + require.Error(t, e.Setup(), "e.Setup()") +} + func TestEnv(t *testing.T) { tt := fileContentTest{ Dir: "testdata/env", diff --git a/taskfile/reader.go b/taskfile/reader.go index dcfb7fdf..70b22993 100644 --- a/taskfile/reader.go +++ b/taskfile/reader.go @@ -263,23 +263,28 @@ func (r *Reader) readNode(node Node) (*ast.Taskfile, error) { } } - var t ast.Taskfile - if err := yaml.Unmarshal(b, &t); err != nil { + var tf ast.Taskfile + if err := yaml.Unmarshal(b, &tf); err != nil { return nil, &errors.TaskfileInvalidError{URI: filepathext.TryAbsToRel(node.Location()), Err: err} } + // Check that the Taskfile is set and has a schema version + if tf.Version == nil { + return nil, &errors.TaskfileVersionCheckError{URI: node.Location()} + } + // Set the taskfile/task's locations - t.Location = node.Location() - for _, task := range t.Tasks.Values() { + tf.Location = node.Location() + for _, task := range tf.Tasks.Values() { // If the task is not defined, create a new one if task == nil { task = &ast.Task{} } // Set the location of the taskfile for each task if task.Location.Taskfile == "" { - task.Location.Taskfile = t.Location + task.Location.Taskfile = tf.Location } } - return &t, nil + return &tf, nil } diff --git a/testdata/empty_taskfile/Taskfile.yml b/testdata/empty_taskfile/Taskfile.yml new file mode 100644 index 00000000..e69de29b