diff --git a/README.md b/README.md index a7364715..d7fd7a8b 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,19 @@ css: - npm run buildcss ``` +Each task can only be run once. If it is included from another dependend task causing +a cyclomatic dependency, execution will be stopped. + +```yml +task1: + deps: [task2] + +task2: + deps: [task1] +``` + +Will stop at the moment the dependencies of `task2` are executed. + ### Prevent task from running when not necessary If a task generates something, you can inform Task the source and generated diff --git a/task.go b/task.go index 33e8585c..4d00890e 100644 --- a/task.go +++ b/task.go @@ -27,6 +27,8 @@ var ( // Tasks constains the tasks parsed from Taskfile Tasks = make(map[string]*Task) + + runTasks = make(map[string]bool) ) func init() { @@ -88,6 +90,11 @@ func Run() { // RunTask runs a task by its name func RunTask(name string) error { + if _, found := runTasks[name]; found { + return &taskRunError{taskName: name, err: fmt.Errorf("Cyclic dependency detected")} + } + runTasks[name] = true + t, ok := Tasks[name] if !ok { return &taskNotFoundError{name}