diff --git a/taskfile/ast/graph.go b/taskfile/ast/graph.go index ca2d1c5379..31d189e0aa 100644 --- a/taskfile/ast/graph.go +++ b/taskfile/ast/graph.go @@ -3,6 +3,7 @@ package ast import ( "fmt" "os" + "sync" "github.com/dominikbraun/graph" "github.com/dominikbraun/graph/draw" @@ -10,6 +11,7 @@ import ( ) type TaskfileGraph struct { + sync.Mutex graph.Graph[string, *TaskfileVertex] } @@ -25,6 +27,7 @@ func taskfileHash(vertex *TaskfileVertex) string { func NewTaskfileGraph() *TaskfileGraph { return &TaskfileGraph{ + sync.Mutex{}, graph.New(taskfileHash, graph.Directed(), graph.PreventCycles(), diff --git a/taskfile/reader.go b/taskfile/reader.go index 429c97da59..e67bb11f49 100644 --- a/taskfile/reader.go +++ b/taskfile/reader.go @@ -140,6 +140,8 @@ func (r *Reader) include(node Node) error { } // Create an edge between the Taskfiles + r.graph.Lock() + defer r.graph.Unlock() edge, err := r.graph.Edge(node.Location(), includeNode.Location()) if err == graph.ErrEdgeNotFound { // If the edge doesn't exist, create it