Task: Make up-to-date resolution work when only "generates" is given

Created on 18 Mar 2019  路  5Comments  路  Source: go-task/task

I'd like to create task that generates one file but doesn't have any sources. I'd expect that task runs only when generated file doesn't exist but it doesn't seem to be the case:

version: '2'

tasks:
  test:
    cmds:
      - echo ok
      - touch test.txt
    generates:
      - test.txt

The task above runs every time even after test.txt is created

feature

Most helpful comment

No, changes to Taskfile shoudn't matter. Status works OK but I'd expect generates has this behavior by default (it's the same way Makefiles work: if generated files exist, task shouldn't be run).

All 5 comments

Hi @sheerun,

That behavior is documented, and changing the status to check when only generates is given is a breaking change. Maybe for v3...

For now my recommendation is to use the status option to check if the file exists. That should be enough for your use case.

There's an example here: https://taskfile.dev/#/usage?id=prevent-unnecessary-work

Using generated file as source seems to work as well.

Maybe there should be issue with wishlist for v3? I think this behaviour is ought to change

IMHO we should have one feature request per issue. I just changed the title of this issue to better reflect the proposal.

If you have more ideas, feel free to open more issues.

Just a thought... Does the task depend on changes done to the Taskfile?

version: '2'

tasks:
  test:
    cmds:
    - echo ok
    - touch test.txt
    sources:
    - Taskfile.yml
    generates:
    - test.txt

Otherwise, status sounds like a good option :-)

No, changes to Taskfile shoudn't matter. Status works OK but I'd expect generates has this behavior by default (it's the same way Makefiles work: if generated files exist, task shouldn't be run).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marco-m picture marco-m  路  5Comments

BeyondEvil picture BeyondEvil  路  6Comments

fj picture fj  路  4Comments

testautomation picture testautomation  路  4Comments

InsaneRaph picture InsaneRaph  路  3Comments