11package read
22
33import (
4+ "errors"
45 "fmt"
56 "os"
67 "path/filepath"
@@ -11,6 +12,9 @@ import (
1112 "gopkg.in/yaml.v2"
1213)
1314
15+ // ErrIncludedTaskfilesCantHaveIncludes is returned when a included Taskfile contains includes
16+ var ErrIncludedTaskfilesCantHaveIncludes = errors .New ("task: Included Taskfiles can't have includes. Please, move the include to the main Taskfile" )
17+
1418// Taskfile reads a Taskfile for a given directory
1519func Taskfile (dir string ) (* taskfile.Taskfile , error ) {
1620 path := filepath .Join (dir , "Taskfile.yml" )
@@ -22,6 +26,27 @@ func Taskfile(dir string) (*taskfile.Taskfile, error) {
2226 return nil , err
2327 }
2428
29+ for namespace , path := range t .Includes {
30+ path = filepath .Join (dir , path )
31+ info , err := os .Stat (path )
32+ if err != nil {
33+ return nil , err
34+ }
35+ if info .IsDir () {
36+ path = filepath .Join (path , "Taskfile.yml" )
37+ }
38+ includedTaskfile , err := readTaskfile (path )
39+ if err != nil {
40+ return nil , err
41+ }
42+ if len (includedTaskfile .Includes ) > 0 {
43+ return nil , ErrIncludedTaskfilesCantHaveIncludes
44+ }
45+ if err = taskfile .Merge (t , includedTaskfile , namespace ); err != nil {
46+ return nil , err
47+ }
48+ }
49+
2550 path = filepath .Join (dir , fmt .Sprintf ("Taskfile_%s.yml" , runtime .GOOS ))
2651 if _ , err = os .Stat (path ); err == nil {
2752 osTaskfile , err := readTaskfile (path )
0 commit comments