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
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).
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).