(ctx context.Context, node Node)
| 290 | } |
| 291 | |
| 292 | func (r *Reader) include(ctx context.Context, node Node) error { |
| 293 | // Create a new vertex for the Taskfile |
| 294 | vertex := &ast.TaskfileVertex{ |
| 295 | URI: node.Location(), |
| 296 | Taskfile: nil, |
| 297 | } |
| 298 | |
| 299 | // Add the included Taskfile to the DAG |
| 300 | // If the vertex already exists, we return early since its Taskfile has |
| 301 | // already been read and its children explored |
| 302 | if err := r.graph.AddVertex(vertex); err == graph.ErrVertexAlreadyExists { |
| 303 | return nil |
| 304 | } else if err != nil { |
| 305 | return err |
| 306 | } |
| 307 | |
| 308 | // Read and parse the Taskfile from the file and add it to the vertex |
| 309 | var err error |
| 310 | vertex.Taskfile, err = r.readNode(ctx, node) |
| 311 | if err != nil { |
| 312 | return err |
| 313 | } |
| 314 | |
| 315 | // Create an error group to wait for all included Taskfiles to be read |
| 316 | var g errgroup.Group |
| 317 | |
| 318 | // Loop over each included taskfile |
| 319 | for _, include := range vertex.Taskfile.Includes.All() { |
| 320 | vars := env.GetEnviron() |
| 321 | vars.Merge(vertex.Taskfile.Vars, nil) |
| 322 | // Start a goroutine to process each included Taskfile |
| 323 | g.Go(func() error { |
| 324 | cache := &templater.Cache{Vars: vars} |
| 325 | include = &ast.Include{ |
| 326 | Namespace: include.Namespace, |
| 327 | Taskfile: templater.Replace(include.Taskfile, cache), |
| 328 | Dir: templater.Replace(include.Dir, cache), |
| 329 | Optional: include.Optional, |
| 330 | Internal: include.Internal, |
| 331 | Flatten: include.Flatten, |
| 332 | Aliases: include.Aliases, |
| 333 | AdvancedImport: include.AdvancedImport, |
| 334 | Excludes: include.Excludes, |
| 335 | Vars: include.Vars, |
| 336 | Checksum: include.Checksum, |
| 337 | } |
| 338 | if err := cache.Err(); err != nil { |
| 339 | return err |
| 340 | } |
| 341 | |
| 342 | entrypoint, err := node.ResolveEntrypoint(include.Taskfile) |
| 343 | if err != nil { |
| 344 | return err |
| 345 | } |
| 346 | |
| 347 | include.Dir, err = node.ResolveDir(include.Dir) |
| 348 | if err != nil { |
| 349 | return err |
no test coverage detected