Running with --watch or watch: true does not actually run the task again when a change is detected if run: when_changed is set. Use the following Taskfile and run with task -w -vvv test to reproduce.
version: '3'
interval: 500ms
# Comment this out to see expected correct behavior
run: when_changed
tasks:
test:
sources:
- content.txt
cmds:
- echo "Hello, world!"
Editing content.json shows
% task -w -vvv test
task: Started watching for tasks: test
task: Watching for changes every 500ms
task: "test" started
task: watching new file: /Users/joshwilson/code/content.txt
task: Task "test" is up to date
task: received watch event: FILE "content.txt" WRITE [/Users/joshwilson/content.txt]
task: skipping execution of task: test:871025353146782510
I usually set run: when_changed at the global scope to avoid running diamond dependencies multiple times in a general manner. I was surprised by this interaction with the --watch option.
A workaround is to override the global run setting with run: always in the watched task definition. I would expect that a watched task would behave as if run: always was implicitly set. In the meantime I will revise my Taskfiles to default to run: always and explicitly set run: when_changed on the diamond dependencies.
- Task version: 3.31.0
- Operating system: macOS 13.6.1 (22G313) (Ventura)
- Experiments enabled: None
Running with
--watchorwatch: truedoes not actually run the task again when a change is detected ifrun: when_changedis set. Use the following Taskfile and run withtask -w -vvv testto reproduce.Editing
content.jsonshowsI usually set
run: when_changedat the global scope to avoid running diamond dependencies multiple times in a general manner. I was surprised by this interaction with the--watchoption.A workaround is to override the global
runsetting withrun: alwaysin the watched task definition. I would expect that a watched task would behave as ifrun: alwayswas implicitly set. In the meantime I will revise my Taskfiles to default torun: alwaysand explicitly setrun: when_changedon the diamond dependencies.