Global preconditions
I'm new with Taskfile. I start to write my first Taskfile.yaml and I realize a serious problem : preconditions. It's a great option but from what I see we can't store a precondition so I have several duplications.
It would be nice if we can have something similar to:
# Global preconditions available for all tasks
preconditions:
my-first-condition:
- sh: "[ 1 = 0 ]"
msg: "One doesn't equal Zero, Halting"
my-second-condition:
- sh: "[ 1 = 0 ]"
msg: "One doesn't equal Zero, Halting"
tasks:
my-first-task:
# ...
preconditions:
- precondition: my-first-condition
- precondition: my-second-condition
So like when you reference a task to be executed in a task. Or if you have a better idea...
Hi @DuboisS,
This sounds like a good idea, but I have no plans to implement that soon...
I will check this one out to see if i can add it with the code in the repo now.
@andreynering Will you accept a PR for this or would that be planned later and you can't accept a PR even if there was one?
Is so then you can assign me :)
Hi @DanyHenriquez,
I'm not sure. This is not trivial to implement so it may need some thought first. Also, there are other priorities for now.
@andreynering @DuboisS
Based on my case, I have a project that use a lot of Taskfiles under Taskfile.d for command like task service:list ..., task project:list ..., task acount:list ..., etc and the problem is that we can't share the preconditions or even tasks between (namespaces).
So I suggest, if there will be PR for that to consider a more global preconditions like global:precondition-1, global:precondition-2 etc
Example:
version: '3'
tasks:
build:
deps:
- global:precondition-1 # << precondition 1
cmds:
- go build -v -i main.go
preconditions:
- task: global:precondition-2 # << precondition 2
@andreynering Hit me up and let me know where you need help
Cleaning up my queue. Unfollowing since i don't know the status or if help is needed. Let me know if this changes 😄
Looks like a duplicate of #294.
There is a way to reuse preconditions by the use of YAML anchors:
tasks:
task1:
cmds:
- "echo task1"
preconditions:
- &test-precondition
sh: "[ 1 = 0 ]"
msg: "One doesn't equal Zero, Halting"
task2:
cmds:
- "echo task2"
preconditions:
- *test-precondition
task3:
cmds:
- "echo task3"
preconditions:
- *test-precondition
The anchor have to be on the same YAML file. Adding global preconditions (e.g. #294) would only reduse duplications, if they are used on multiple imported taskfiles.
However we could reference YAML anchors in the documentation :+1:
Since we do not use strict YAML unmarshal, even this is possible:
preconditions:
<<: &test-precondition
sh: "[ 1 = 0 ]"
msg: "One doesn't equal Zero, Halting"
tasks:
task1:
cmds:
- "echo task1"
preconditions:
- *test-precondition
task2:
cmds:
- "echo task2"
preconditions:
- *test-precondition
task3:
cmds:
- "echo task3"
preconditions:
- *test-precondition
Duplicate of #294