Skip to content

--watch detects change but skips task when "run: when_changed" is set #1388

Open
@joshwilson-dbx

Description

@joshwilson-dbx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: watcherChanges related to the Taskfile watcher.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions