diff --git a/CHANGELOG.md b/CHANGELOG.md index 901c06a2..8795b7a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## Unreleased + +- Add `run:` setting to control if tasks should run multiple times or not. + Available options are `always` (the default), `when_changed` (if a variable + modified the task) and `once` (run only once no matter what). + This is a long time requested feature. Enjoy! + ([#53](https://github.com/go-task/task/issues/53), [#359](https://github.com/go-task/task/pull/359)). + ## v3.6.0 - 2021-07-10 - Allow using both `sources:` and `status:` in the same task diff --git a/docs/usage.md b/docs/usage.md index 78465424..f3a704a2 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -455,12 +455,13 @@ tasks: ### Limiting when tasks run -If a task executed by multiple `cmds` or multiple `deps` you can limit -how many times it is executed using `run`. `run` can also be set at the root +If a task executed by multiple `cmds` or multiple `deps` you can control +when it is executed using `run`. `run` can also be set at the root of the Taskfile to change the behavior of all the tasks unless explicitly -overridden +overridden. + +Supported values for `run`: -Supported values for `run` * `always` (default) always attempt to invoke the task regardless of the number of previous executions * `once` only invoke this task once regardless of the number of references @@ -468,7 +469,8 @@ Supported values for `run` passed into the task ```yaml -version: '3.7' +version: '3' + tasks: default: cmds: diff --git a/task.go b/task.go index daf552c2..38e7bf87 100644 --- a/task.go +++ b/task.go @@ -151,6 +151,9 @@ func (e *Executor) Setup() error { if v == 2.0 { v = 2.6 } + if v == 3.0 { + v = 3.7 + } if v > 3.7 { return fmt.Errorf(`task: Taskfile versions greater than v3.7 not implemented in the version of Task`) @@ -480,14 +483,19 @@ func (e *Executor) startExecution(ctx context.Context, t *taskfile.Task, execute e.executionHashesMutex.Lock() otherExecutionCtx, ok := e.executionHashes[h] - e.executionHashesMutex.Unlock() + if ok { + e.executionHashesMutex.Unlock() + e.Logger.VerboseErrf(logger.Magenta, "task: skipping execution of task: %s", h) <-otherExecutionCtx.Done() return nil } ctx, cancel := context.WithCancel(ctx) defer cancel() + e.executionHashes[h] = ctx + e.executionHashesMutex.Unlock() + return execute(ctx) }